1111from django .test import TestCase
1212from django .utils import timezone as django_timezone
1313
14- from joanie .core import factories
14+ from joanie .core import enums , factories
1515from joanie .core .factories import CourseRunFactory
1616from joanie .core .models import CourseRun , CourseState , Enrollment
1717
@@ -452,6 +452,7 @@ def test_model_course_run_get_serialized(self):
452452 "enrollment_end" : "2022-09-09T09:00:00+00:00" ,
453453 "languages" : course_run .languages ,
454454 "catalog_visibility" : "course_and_search" ,
455+ "certificate_offer" : None ,
455456 },
456457 )
457458 course_run .is_listed = False
@@ -467,6 +468,7 @@ def test_model_course_run_get_serialized(self):
467468 "enrollment_end" : "2022-09-09T09:00:00+00:00" ,
468469 "languages" : course_run .languages ,
469470 "catalog_visibility" : "hidden" ,
471+ "certificate_offer" : None ,
470472 },
471473 )
472474
@@ -493,6 +495,7 @@ def test_model_course_run_get_serialized_hidden(self):
493495 "enrollment_end" : "2022-09-09T09:00:00+00:00" ,
494496 "languages" : course_run .languages ,
495497 "catalog_visibility" : "hidden" ,
498+ "certificate_offer" : None ,
496499 },
497500 )
498501
@@ -623,3 +626,51 @@ def test_models_course_run_user_with_no_enrollment_can_enroll(self):
623626
624627 self .assertTrue (course_run .can_enroll (user ))
625628 self .assertEqual (Enrollment .objects .count (), 0 )
629+
630+ def test_models_course_run_get_certificate_offer_none (self ):
631+ """
632+ Test the get_certificate_offer method of the CourseRun model.
633+ If no certificate product is related to the course, the course run should have
634+ a no offer.
635+ """
636+ course_run = factories .CourseRunFactory ()
637+ self .assertEqual (course_run .get_certificate_offer (), None )
638+
639+ def test_models_course_run_get_certificate_offer_none_with_credential_product (self ):
640+ """
641+ Test the get_certificate_offer method of the CourseRun model.
642+ If no certificate product is related to the course, the course run should have
643+ a no offer.
644+ """
645+ course_run = factories .CourseRunFactory ()
646+ factories .ProductFactory (
647+ courses = [course_run .course ],
648+ type = enums .PRODUCT_TYPE_CREDENTIAL ,
649+ )
650+ self .assertEqual (course_run .get_certificate_offer (), None )
651+
652+ def test_models_course_run_get_certificate_offer_free (self ):
653+ """
654+ Test the get_certificate_offer method of the CourseRun model.
655+ If a free certificate product is linked to the course, the course run should have
656+ a free offer.
657+ """
658+ course_run = factories .CourseRunFactory ()
659+ factories .ProductFactory (
660+ courses = [course_run .course ], type = enums .PRODUCT_TYPE_CERTIFICATE , price = 0
661+ )
662+ self .assertEqual (course_run .get_certificate_offer (), enums .COURSE_OFFER_FREE )
663+
664+ def test_models_course_run_get_certificate_offer_paid (self ):
665+ """
666+ Test the get_certificate_offer method of the CourseRun model.
667+ If a not free certificate product is linked to the course, the course run should have
668+ a paid offer.
669+ """
670+ course_run = factories .CourseRunFactory ()
671+ factories .ProductFactory (
672+ courses = [course_run .course ],
673+ type = enums .PRODUCT_TYPE_CERTIFICATE ,
674+ price = 42.00 ,
675+ )
676+ self .assertEqual (course_run .get_certificate_offer (), enums .COURSE_OFFER_PAID )
0 commit comments