• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

gcivil-nyu-org / INT2-Monday-Spring2024-Team-2 / 800

29 Apr 2024 09:02AM UTC coverage: 91.218% (+1.7%) from 89.518%
800

push

travis-pro

web-flow
Merge pull request #250 from gcivil-nyu-org/Community-v3

add tests

8 of 39 new or added lines in 1 file covered. (20.51%)

764 existing lines in 16 files now uncovered.

1984 of 2175 relevant lines covered (91.22%)

1.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/Dashboard/tests.py
1
from django.test import (
2✔
2
    TestCase,
3
    Client,
4
    RequestFactory,
5
    override_settings,
6
    TransactionTestCase,
7
)
8
from django.urls import reverse
2✔
9
from django.contrib.auth.models import User
2✔
10
from TutorRegister.models import (
2✔
11
    Expertise,
12
    Availability,
13
    ProfileT,
14
    TutoringSession,
15
    TutorReview,
16
)
17
from TutorNYU.form import ContactForm
2✔
18
import json
2✔
19
from .views import (
2✔
20
    StudentInformation,
21
    Requests,
22
    TutorFeedback,
23
    AdminDashboard,
24
    download_attachment,
25
    Survey,
26
)
27
from TutorNYU.views import contact
2✔
28
from TutorRegister.models import ProfileS
2✔
29
from .templatetags.custom_filters import remove_prefix
2✔
30
from .forms.student_info import StudentForm
2✔
31
from .forms.tutor_info import TutorForm
2✔
32
from .forms.survey_form import SurveyForm
2✔
33
from django.core import mail
2✔
34
from django.core.cache import cache
2✔
35
from django.core.files.uploadedfile import SimpleUploadedFile
2✔
36
import os
2✔
37
from PIL import Image
2✔
38
from io import BytesIO
2✔
39
from django.core.files.uploadedfile import SimpleUploadedFile
2✔
40
from django.core.files.storage import default_storage
2✔
41
from django.contrib.auth.decorators import login_required
2✔
42
from datetime import datetime, time
2✔
43
import mimetypes
2✔
44

45

46
# Create your tests here.
47
class StudentDashboardTestCase(TestCase):
2✔
48
    def setUp(self):
2✔
UNCOV
49
        self.client = Client()
1✔
50

51
    def test_student_dashboard_view_with_login(self):
2✔
UNCOV
52
        self.client.login(username="test@example.com", password="testpassword")
1✔
UNCOV
53
        url = reverse("Dashboard:dashboard")
1✔
UNCOV
54
        response = self.client.get(url)
1✔
UNCOV
55
        self.assertEqual(response.status_code, 200)
1✔
UNCOV
56
        self.assertTemplateUsed(response, "Dashboard/dashboard.html")
1✔
57

58
    def test_student_dashboard_view_without_login(self):
2✔
UNCOV
59
        url = reverse("Dashboard:dashboard")
1✔
UNCOV
60
        response = self.client.get(url)
1✔
UNCOV
61
        self.assertEqual(response.status_code, 302)
1✔
62
        # Check if redirect to login page
UNCOV
63
        self.assertTrue(response.url.startswith("/auth/login/"))
1✔
64

65

66
class TutorDashboardTestCase(TestCase):
2✔
67
    def setUp(self):
2✔
UNCOV
68
        self.client = Client()
1✔
69

70
    def test_tutor_dashboard_view_with_login(self):
2✔
UNCOV
71
        self.client.login(username="test@nyu.edu", password="testpassword")
1✔
UNCOV
72
        url = reverse("Dashboard:dashboard")
1✔
UNCOV
73
        response = self.client.get(url)
1✔
UNCOV
74
        self.assertEqual(response.status_code, 200)
1✔
UNCOV
75
        self.assertTemplateUsed(response, "Dashboard/dashboard.html")
1✔
76

77
    def test_tutor_dashboard_view_without_login(self):
2✔
UNCOV
78
        url = reverse("Dashboard:dashboard")
1✔
UNCOV
79
        response = self.client.get(url)
1✔
UNCOV
80
        self.assertEqual(response.status_code, 302)
1✔
81
        # Check if redirect to login page
UNCOV
82
        self.assertTrue(response.url.startswith("/auth/login/"))
1✔
83

84

85
class HomepageTestCase(TestCase):
2✔
86
    def test_home_view(self):
2✔
UNCOV
87
        url = reverse("home")
1✔
UNCOV
88
        response = self.client.get(url)
1✔
UNCOV
89
        self.assertEqual(response.status_code, 200)
1✔
UNCOV
90
        self.assertTemplateUsed(response, "home.html")
1✔
91

92

93
class ContactTestCase(TestCase):
2✔
94
    def setUp(self):
2✔
UNCOV
95
        self.factory = RequestFactory()
1✔
96

97
    @override_settings(EMAIL_BACKEND="django.core.mail.backends.locmem.EmailBackend")
2✔
98
    def test_contact_post(self):
2✔
UNCOV
99
        url = reverse("contact_us")
1✔
UNCOV
100
        form_data = {
1✔
101
            "full_name": "John Doe",
102
            "email": "john@example.com",
103
            "phone": "1234567890",
104
            "message": "Test message",
105
        }
UNCOV
106
        form = ContactForm(data=form_data)
1✔
UNCOV
107
        print("Valid:", form.is_valid())
1✔
UNCOV
108
        print("Errors:", form.errors)
1✔
UNCOV
109
        request = self.factory.post(url, data=form.data)
1✔
UNCOV
110
        response = contact(request)
1✔
UNCOV
111
        self.assertEqual(response.status_code, 200)
1✔
UNCOV
112
        self.assertEqual(len(mail.outbox), 1)
1✔
113

114

115
class TutorInformationTest(TestCase):
2✔
116
    @classmethod
2✔
117
    def setUpTestData(cls):
2✔
UNCOV
118
        cls.user = User.objects.get(pk=cache.get("tutor"))
1✔
UNCOV
119
        cls.url = reverse("Dashboard:tutor_profile")
1✔
120

121
    def setUp(self):
2✔
UNCOV
122
        self.client = Client()
1✔
UNCOV
123
        self.client.login(username="test@nyu.edu", password="testpassword")
1✔
124

125
    def test_get_request(self):
2✔
UNCOV
126
        response = self.client.get(self.url)
1✔
UNCOV
127
        self.assertEqual(response.status_code, 200)
1✔
UNCOV
128
        self.assertIn("tutor_form", response.context)
1✔
UNCOV
129
        self.assertIn("availability_form", response.context)
1✔
UNCOV
130
        self.assertIn("initial_availabilities_json", response.context)
1✔
UNCOV
131
        self.assertTemplateUsed(response, "Dashboard/tutor_info.html")
1✔
132

133
    def test_post_request(self):
2✔
UNCOV
134
        test_file_path = os.path.join(
1✔
135
            os.path.dirname(__file__), "test_files", "random.pdf"
136
        )
UNCOV
137
        with open(test_file_path, "rb") as f:
1✔
UNCOV
138
            transcript_file = SimpleUploadedFile(
1✔
139
                "random.pdf", f.read(), content_type="application/pdf"
140
            )
141

UNCOV
142
        post_data = {
1✔
143
            "fname": "Test",
144
            "lname": "User",
145
            "gender": "male",
146
            "zip": "00000",
147
            "grade": "grad",
148
            "major": "Computer Science",
149
            "preferred_mode": "remote",
150
            "salary_min": 20,
151
            "salary_max": 50,
152
            "intro": "This is a test introduction.",
153
            "expertise": ["math", "computer_sci"],
154
            "day_of_week": "monday",
155
            "start_time": "10:00",
156
            "end_time": "12:00",
157
            "availabilities": json.dumps(
158
                [
159
                    {
160
                        "day_of_week": "monday",
161
                        "start_time": "10:00",
162
                        "end_time": "12:00",
163
                    },
164
                    {
165
                        "day_of_week": "wednesday",
166
                        "start_time": "14:00",
167
                        "end_time": "16:00",
168
                    },
169
                ]
170
            ),
171
        }
172

173
        # Include the transcript file in the request.FILES dictionary
UNCOV
174
        response = self.client.post(
1✔
175
            self.url, {**post_data, "transcript": transcript_file}, follow=True
176
        )
177

UNCOV
178
        self.assertRedirects(
1✔
179
            response,
180
            reverse("Dashboard:dashboard"),
181
            status_code=302,
182
            target_status_code=200,
183
        )
184

UNCOV
185
        self.assertTrue(ProfileT.objects.filter(user=self.user).exists())
1✔
UNCOV
186
        self.assertEqual(
1✔
187
            Expertise.objects.filter(user=self.user).count(),
188
            len(post_data["expertise"]),
189
        )
UNCOV
190
        self.assertTrue(Availability.objects.filter(user=self.user).exists())
1✔
191

192

193
class StudentInformationTestCase(TestCase):
2✔
194
    def setUp(self):
2✔
UNCOV
195
        self.user = User.objects.get(pk=cache.get("student"))
1✔
UNCOV
196
        self.client = Client(username="test@example.com", password="testpassword")
1✔
UNCOV
197
        self.factory = RequestFactory()
1✔
198

199
    def test_student_information_view(self):
2✔
UNCOV
200
        url = reverse("Dashboard:student_profile")
1✔
UNCOV
201
        profile, created = ProfileS.objects.get_or_create(user=self.user)
1✔
202

UNCOV
203
        form_data = {
1✔
204
            "fname": "Test",
205
            "lname": "User",
206
            "gender": "female",
207
            "zip": "12345",
208
            "school": "Test School",
209
            "grade": "1",
210
            "preferred_mode": "remote",
211
            "intro": "Hello, this is a test.",
212
        }
213

UNCOV
214
        student_form = StudentForm(data=form_data, instance=profile)
1✔
UNCOV
215
        request = self.factory.post(url, data=student_form.data)
1✔
UNCOV
216
        request.user = self.user
1✔
UNCOV
217
        response = StudentInformation(request)
1✔
UNCOV
218
        self.assertEqual(response.status_code, 302)
1✔
UNCOV
219
        self.assertTrue(self.user.usertype.has_profile_complete)
1✔
220

221
    def tearDown(self):
2✔
UNCOV
222
        self.user.delete()
1✔
223

224

225
class CancelSessionTestCase(TestCase):
2✔
226
    def setUp(self):
2✔
UNCOV
227
        self.session = TutoringSession.objects.get(pk=cache.get("upcoming_session"))
1✔
228

229
    @override_settings(EMAIL_BACKEND="django.core.mail.backends.locmem.EmailBackend")
2✔
230
    def test_cancel_session(self):
2✔
UNCOV
231
        self.client.login(username="test@nyu.edu", password="testpassword")
1✔
UNCOV
232
        response = self.client.get(
1✔
233
            reverse("Dashboard:cancel_session", args=(self.session.pk,))
234
        )
UNCOV
235
        self.assertEqual(response.status_code, 302)
1✔
UNCOV
236
        self.session.refresh_from_db()
1✔
UNCOV
237
        self.assertEqual(self.session.status, "Cancelled")
1✔
UNCOV
238
        self.assertEqual(len(mail.outbox), 1)
1✔
239

240
    def tearDown(self) -> None:
2✔
UNCOV
241
        self.session.status = "Accepted"
1✔
UNCOV
242
        self.session.save()
1✔
UNCOV
243
        super().tearDown()
1✔
244

245

246
class RequestsTestCase(TestCase):
2✔
247
    def setUp(self):
2✔
UNCOV
248
        self.tutor = User.objects.get(pk=cache.get("tutor"))
1✔
249

250
    def test_tutor_request(self):
2✔
UNCOV
251
        request = RequestFactory().get(reverse("Dashboard:requests"))
1✔
UNCOV
252
        request.user = self.tutor
1✔
UNCOV
253
        response = Requests(request)
1✔
UNCOV
254
        self.assertEqual(response.status_code, 200)
1✔
255

256

257
class AcceptRequestTestCase(TestCase):
2✔
258
    def setUp(self):
2✔
UNCOV
259
        self.session = TutoringSession.objects.get(pk=cache.get("pending_request"))
1✔
UNCOV
260
        self.client = Client()
1✔
261

262
    def test_accept_request(self):
2✔
UNCOV
263
        self.client.login(username="test@nyu.edu", password="testpassword")
1✔
UNCOV
264
        response = self.client.get(
1✔
265
            reverse("Dashboard:accept_request", args=(self.session.pk,))
266
        )
UNCOV
267
        self.assertEqual(response.status_code, 302)
1✔
UNCOV
268
        self.session.refresh_from_db()
1✔
UNCOV
269
        self.assertEqual(self.session.status, "Accepted")
1✔
270

271
    def tearDown(self) -> None:
2✔
UNCOV
272
        self.session.status = "Pending"
1✔
UNCOV
273
        self.session.save()
1✔
UNCOV
274
        super().tearDown()
1✔
275

276

277
class DeclineRequestTestCase(TestCase):
2✔
278
    def setUp(self):
2✔
UNCOV
279
        self.session = TutoringSession.objects.get(pk=cache.get("pending_request"))
1✔
UNCOV
280
        self.client = Client()
1✔
281

282
    def test_decline_request(self):
2✔
UNCOV
283
        self.client.login(username="test@nyu.edu", password="testpassword")
1✔
UNCOV
284
        response = self.client.get(
1✔
285
            reverse("Dashboard:decline_request", args=(self.session.pk,))
286
        )
UNCOV
287
        self.assertEqual(response.status_code, 302)
1✔
UNCOV
288
        self.session.refresh_from_db()
1✔
UNCOV
289
        self.assertEqual(self.session.status, "Declined")
1✔
290

291
    def tearDown(self) -> None:
2✔
UNCOV
292
        self.session.status = "Pending"
1✔
UNCOV
293
        self.session.save()
1✔
UNCOV
294
        super().tearDown()
1✔
295

296

297
class LogoutTestCase(TestCase):
2✔
298
    def setUp(self):
2✔
UNCOV
299
        self.user = User.objects.get(pk=cache.get("student"))
1✔
UNCOV
300
        self.client = Client()
1✔
UNCOV
301
        self.client.login(username="test@example.com", password="testpassword")
1✔
302

303
    def test_logout_view(self):
2✔
UNCOV
304
        self.assertNotEqual(str(self.user), "AnonymousUser")
1✔
UNCOV
305
        response = self.client.get(reverse("Dashboard:logout"))
1✔
UNCOV
306
        self.assertEqual(response.status_code, 302)
1✔
UNCOV
307
        self.assertEqual(response.url, reverse("home"))
1✔
308

UNCOV
309
        user_after_logout = response.wsgi_request.user
1✔
UNCOV
310
        self.assertEqual(str(user_after_logout), "AnonymousUser")
1✔
311

312

313
class ProvideFeedbackTestCase(TestCase):
2✔
314
    def setUp(self):
2✔
UNCOV
315
        self.session = TutoringSession.objects.get(pk=cache.get("past_session"))
1✔
UNCOV
316
        self.client = Client()
1✔
UNCOV
317
        self.client.login(username="test@example.com", password="testpassword")
1✔
318

319
    def test_provide_feedback(self):
2✔
UNCOV
320
        response = self.client.post(
1✔
321
            reverse("Dashboard:feedback", args=[self.session.pk]),
322
            {"rating": 5.0, "review": "Great tutor!"},
323
        )
UNCOV
324
        self.assertEqual(response.status_code, 302)
1✔
UNCOV
325
        self.assertTrue(
1✔
326
            TutoringSession.objects.get(pk=self.session.pk).reviewed_by_student
327
        )
328

329

330
class SurveyTestCase(TestCase):
2✔
331
    def setUp(self):
2✔
UNCOV
332
        self.session = TutoringSession.objects.get(pk=cache.get("past_session"))
1✔
UNCOV
333
        self.client = Client()
1✔
UNCOV
334
        self.client.login(username="test@example.com", password="testpassword")
1✔
335

336
    def test_submit_survey(self):
2✔
UNCOV
337
        response = self.client.post(
1✔
338
            reverse("Dashboard:survey", args=[self.session.pk]),
339
            {"q1": "True", "q2": "True", "q3": "True"},
340
        )
UNCOV
341
        self.assertEqual(response.status_code, 302)
1✔
UNCOV
342
        self.assertTrue(
1✔
343
            TutoringSession.objects.get(pk=self.session.pk).survey_completed
344
        )
345

346

347
class TutorFeedbackTestCase(TestCase):
2✔
348
    def setUp(self):
2✔
UNCOV
349
        self.tutor = User.objects.get(pk=cache.get("tutor"))
1✔
UNCOV
350
        self.student = User.objects.get(pk=cache.get("student"))
1✔
UNCOV
351
        self.session = TutoringSession.objects.get(pk=cache.get("past_session"))
1✔
UNCOV
352
        self.review = TutorReview.objects.create(
1✔
353
            tutor_id=self.tutor,
354
            student_id=self.student,
355
            tutoring_session=self.session,
356
            rating=4.5,
357
            review="Good tutor",
358
        )
UNCOV
359
        self.factory = RequestFactory()
1✔
360

361
    def test_tutor_feedback(self):
2✔
UNCOV
362
        self.client.force_login(self.tutor)
1✔
UNCOV
363
        request = self.factory.get(reverse("Dashboard:tutor_feedback"))
1✔
UNCOV
364
        request.user = self.tutor
1✔
UNCOV
365
        response = TutorFeedback(request)
1✔
UNCOV
366
        self.assertEqual(response.status_code, 200)
1✔
367

368

369
class AdminDashboardTestCase(TestCase):
2✔
370
    def setUp(self):
2✔
UNCOV
371
        self.superuser = User.objects.create_superuser(
1✔
372
            username="admin", password="admin"
373
        )
UNCOV
374
        self.client = Client()
1✔
UNCOV
375
        self.tutor = User.objects.get(pk=cache.get("tutor"))
1✔
UNCOV
376
        Expertise.objects.create(subject="Math", user=self.tutor)
1✔
377

378
    def test_admin_dashboard(self):
2✔
UNCOV
379
        self.client.login(username="admin", password="admin")
1✔
UNCOV
380
        response = self.client.get(reverse("Dashboard:admin_dashboard"))
1✔
UNCOV
381
        self.assertEqual(response.status_code, 200)
1✔
382

383

384
class VideoCallTestCase(TestCase):
2✔
385
    def setUp(self):
2✔
UNCOV
386
        self.client = Client()
1✔
387

388
    def test_video_call_tutor(self):
2✔
UNCOV
389
        self.client.login(username="test@nyu.edu", password="testpassword")
1✔
UNCOV
390
        response = self.client.get(reverse("Dashboard:video_call"))
1✔
UNCOV
391
        self.assertEqual(response.status_code, 200)
1✔
392

393
    def test_video_call_student(self):
2✔
UNCOV
394
        self.client.login(username="test@example.com", password="testpassword")
1✔
UNCOV
395
        response = self.client.get(reverse("Dashboard:video_call"))
1✔
UNCOV
396
        self.assertEqual(response.status_code, 200)
1✔
397

398

399
class UpdateQualificationTestCase(TestCase):
2✔
400
    def setUp(self):
2✔
UNCOV
401
        self.superuser = User.objects.create_superuser(
1✔
402
            username="admin", password="admin"
403
        )
UNCOV
404
        self.client = Client()
1✔
UNCOV
405
        self.tutor = User.objects.get(pk=cache.get("tutor"))
1✔
UNCOV
406
        self.tutor_profile = ProfileT.objects.get(user=self.tutor)
1✔
407

408
    @override_settings(EMAIL_BACKEND="django.core.mail.backends.locmem.EmailBackend")
2✔
409
    def test_update_qualifiction_qualified(self):
2✔
UNCOV
410
        self.tutor_profile.qualified = True
1✔
UNCOV
411
        self.client.login(username="admin", password="admin")
1✔
UNCOV
412
        response = self.client.post(
1✔
413
            reverse("Dashboard:update_qualification"),
414
            {"tutor_id": self.tutor_profile.id, "qualification": "qualified"},
415
        )
UNCOV
416
        self.assertEqual(response.status_code, 302)
1✔
UNCOV
417
        self.assertEqual(len(mail.outbox), 1)
1✔
418

419
    @override_settings(EMAIL_BACKEND="django.core.mail.backends.locmem.EmailBackend")
2✔
420
    def test_update_qualifiction_unqualified(self):
2✔
UNCOV
421
        self.tutor_profile.qualified = False
1✔
UNCOV
422
        self.client.login(username="admin", password="admin")
1✔
UNCOV
423
        response = self.client.post(
1✔
424
            reverse("Dashboard:update_qualification"),
425
            {"tutor_id": self.tutor_profile.id, "qualification": "unqualified"},
426
        )
UNCOV
427
        self.assertEqual(response.status_code, 302)
1✔
UNCOV
428
        self.assertEqual(len(mail.outbox), 1)
1✔
429

430

431
class RemovePrefixTestCase(TestCase):
2✔
432
    def test_remove_prefix_starts_with_prefix(self):
2✔
UNCOV
433
        value = "foobar"
1✔
UNCOV
434
        prefix = "foo"
1✔
UNCOV
435
        expected_result = "bar"
1✔
UNCOV
436
        self.assertEqual(remove_prefix(value, prefix), expected_result)
1✔
437

438
    def test_remove_prefix_without_prefix(self):
2✔
UNCOV
439
        value = "foo"
1✔
UNCOV
440
        prefix = "baz"
1✔
UNCOV
441
        expected_result = "foo"
1✔
UNCOV
442
        self.assertEqual(remove_prefix(value, prefix), expected_result)
1✔
443

444

445
class DownloadAttachmentTestCase(TestCase):
2✔
446
    def setUp(self):
2✔
447
        # Set up a user and log in
UNCOV
448
        self.user = User.objects.create_user(username="testuser", password="12345")
1✔
UNCOV
449
        self.client = Client()
1✔
UNCOV
450
        self.client.login(username="testuser", password="12345")
1✔
451

452
        # Ensure to include all required fields for the TutoringSession
UNCOV
453
        self.attachment = SimpleUploadedFile(
1✔
454
            "attachment.txt",
455
            b"Dummy file content of the attachment.",
456
            content_type="text/plain",
457
        )
UNCOV
458
        self.session = TutoringSession.objects.create(
1✔
459
            attachment=self.attachment,
460
            date=datetime.now().date(),
461
            offering_rate=55,
462
            student_id_id=1,
463
            tutor_id_id=10,
464
            start_time=time(12, 0),
465
            end_time=time(14, 0),
466
            status="Pending",
467
        )
UNCOV
468
        self.session.save()
1✔
469

470
    def test_download_attachment(self):
2✔
471
        # Build the URL and make the request
UNCOV
472
        url = reverse(
1✔
473
            "Dashboard:download_attachment", kwargs={"session_id": self.session.pk}
474
        )
UNCOV
475
        response = self.client.get(url)
1✔
476

477
        # Check response status code
UNCOV
478
        self.assertEqual(response.status_code, 200)
1✔
479

480
        # Check the content-type header
UNCOV
481
        self.assertEqual(response["Content-Type"], "text/plain")
1✔
482

483
        # Check the content-disposition header for correct filename
UNCOV
484
        self.assertIn(
1✔
485
            f'attachment; filename="{self.attachment.name}"',
486
            response["Content-Disposition"],
487
        )
488

489
        # Gather the streamed content and assert its content
UNCOV
490
        content = b"".join(response.streaming_content)
1✔
UNCOV
491
        self.assertEqual(content, b"Dummy file content of the attachment.")
1✔
492

493
    def tearDown(self):
2✔
494
        # Clean up after each test
UNCOV
495
        self.user.delete()
1✔
UNCOV
496
        self.session.delete()
1✔
497

498

499
class DownloadTranscriptTestCase(TestCase):
2✔
500
    def setUp(self):
2✔
501
        # Set up a user and log in
UNCOV
502
        self.user = User.objects.create_user(username="testuser", password="12345")
1✔
UNCOV
503
        self.client = Client()
1✔
UNCOV
504
        self.client.login(username="testuser", password="12345")
1✔
505

506
        # Set up a ProfileT with a transcript
UNCOV
507
        self.transcript = SimpleUploadedFile(
1✔
508
            "transcript.pdf",
509
            b"PDF file content for testing",
510
            content_type="application/pdf",
511
        )
UNCOV
512
        self.tutor_profile = ProfileT.objects.create(
1✔
513
            user=self.user,
514
            transcript=self.transcript,
515
        )
516

517
    def test_download_transcript(self):
2✔
518
        # Build the URL and make the request
UNCOV
519
        url = reverse(
1✔
520
            "Dashboard:download_transcript", kwargs={"tutor_id": self.tutor_profile.pk}
521
        )
UNCOV
522
        response = self.client.get(url)
1✔
523

524
        # Check response status code
UNCOV
525
        self.assertEqual(response.status_code, 200)
1✔
526

527
        # Check the content-type header
UNCOV
528
        content_type, _ = mimetypes.guess_type(self.transcript.name)
1✔
UNCOV
529
        self.assertEqual(response["Content-Type"], content_type)
1✔
530

531
        # Check the content-disposition header for correct filename
UNCOV
532
        self.assertIn(
1✔
533
            f'attachment; filename="{self.transcript.name}"',
534
            response["Content-Disposition"],
535
        )
536

537
        # Gather the streamed content and assert its content
UNCOV
538
        content = b"".join(response.streaming_content)
1✔
UNCOV
539
        self.assertEqual(content, b"PDF file content for testing")
1✔
540

541
    def tearDown(self):
2✔
542
        # Clean up after each test
UNCOV
543
        self.user.delete()
1✔
UNCOV
544
        self.tutor_profile.delete()
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc