Skip to content

Commit d9ad5dd

Browse files
authored
test: adding a new test for missing certificate available date (#2525)
we have a weird error condition happening sometimes when the certificate available date is missing. On the one hand, this test does not reveal the cause of the error condition, but on the other hand, is an important test to have.
1 parent ad1e31b commit d9ad5dd

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

credentials/apps/api/v2/tests/test_serializers.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ def test_course_credential(self):
335335

336336
class CourseCertificateSerializerTests(SiteMixin, TestCase):
337337
def test_create_course_certificate(self):
338+
"""We can create a course certificate configuration"""
338339
course_run = CourseRunFactory()
339340
course_certificate = CourseCertificateFactory(site=self.site, course_run=course_run)
340341
Request = namedtuple("Request", ["site"])
@@ -351,7 +352,7 @@ def test_create_course_certificate(self):
351352
self.assertEqual(actual, expected)
352353

353354
def test_missing_course_run(self):
354-
# We should be able to create an entry without a course run
355+
"""We can create a course certificate configuration without a course run"""
355356
course_certificate = CourseCertificateFactory(site=self.site, course_run=None)
356357
Request = namedtuple("Request", ["site"])
357358
actual = CourseCertificateSerializer(course_certificate, context={"request": Request(site=self.site)}).data
@@ -367,8 +368,7 @@ def test_missing_course_run(self):
367368
self.assertEqual(actual, expected)
368369

369370
def test_create_without_course_run_raises_warning(self):
370-
# even though you can create an entry without a course run,
371-
# we want to make sure we are logging a warning when it is missing
371+
"""Creating a course certificate configuration without a course run raises a warning"""
372372
with self.assertLogs(level=WARNING):
373373
Request = namedtuple("Request", ["site"])
374374
CourseCertificateSerializer(context={"request": Request(site=self.site)}).create(
@@ -379,3 +379,24 @@ def test_create_without_course_run_raises_warning(self):
379379
"certificate_available_date": None,
380380
}
381381
)
382+
383+
def test_missing_certificate_available_date(self):
384+
"""We can create a course certificate configuration without a certificate available date"""
385+
course_run = CourseRunFactory()
386+
course_certificate = CourseCertificateFactory(
387+
site=self.site,
388+
course_run=course_run,
389+
certificate_available_date=None,
390+
)
391+
Request = namedtuple("Request", ["site"])
392+
actual = CourseCertificateSerializer(course_certificate, context={"request": Request(site=self.site)}).data
393+
expected = {
394+
"id": course_certificate.id,
395+
"site": self.site.id,
396+
"course_run": course_certificate.course_run.key,
397+
"course_id": course_certificate.course_id,
398+
"certificate_type": course_certificate.certificate_type,
399+
"certificate_available_date": None,
400+
"is_active": course_certificate.is_active,
401+
}
402+
self.assertEqual(actual, expected)

0 commit comments

Comments
 (0)