def test_course_ids_with_certs_for_user(self): # Create one user with certs and one without student_no_certs = UserFactory() student_with_certs = UserFactory() student_with_certs.profile.allow_certificate = True student_with_certs.profile.save() # Set up a couple of courses course_1 = CourseFactory.create() course_2 = CourseFactory.create() # Generate certificates GeneratedCertificateFactory.create( user=student_with_certs, course_id=course_1.id, status=CertificateStatuses.downloadable, mode='honor') GeneratedCertificateFactory.create( user=student_with_certs, course_id=course_2.id, status=CertificateStatuses.downloadable, mode='honor') # User with no certs should return an empty set. self.assertSetEqual( GeneratedCertificate.course_ids_with_certs_for_user( student_no_certs), set()) # User with certs should return a set with the two course_ids self.assertSetEqual( GeneratedCertificate.course_ids_with_certs_for_user( student_with_certs), {course_1.id, course_2.id})
def test_refundable_when_certificate_exists(self, cutoff_date): """ Assert that enrollment is not refundable once a certificat has been generated.""" cutoff_date.return_value = datetime.now(pytz.UTC) + timedelta(days=1) self.assertTrue(self.enrollment.refundable()) GeneratedCertificateFactory.create( user=self.user, course_id=self.course.id, status=CertificateStatuses.downloadable, mode='verified' ) self.assertFalse(self.enrollment.refundable()) self.assertFalse( self.enrollment.refundable( user_already_has_certs_for=GeneratedCertificate.course_ids_with_certs_for_user(self.user) ) ) # Assert that can_refund overrides this and allows refund self.enrollment.can_refund = True self.assertTrue(self.enrollment.refundable()) self.assertTrue( self.enrollment.refundable( user_already_has_certs_for=GeneratedCertificate.course_ids_with_certs_for_user(self.user) ) )
def test_course_ids_with_certs_for_user(self): # Create one user with certs and one without student_no_certs = UserFactory() student_with_certs = UserFactory() student_with_certs.profile.allow_certificate = True student_with_certs.profile.save() # Set up a couple of courses course_1 = CourseFactory.create() course_2 = CourseFactory.create() # Generate certificates GeneratedCertificateFactory.create( user=student_with_certs, course_id=course_1.id, status=CertificateStatuses.downloadable, mode='honor' ) GeneratedCertificateFactory.create( user=student_with_certs, course_id=course_2.id, status=CertificateStatuses.downloadable, mode='honor' ) # User with no certs should return an empty set. self.assertSetEqual( GeneratedCertificate.course_ids_with_certs_for_user(student_no_certs), set() ) # User with certs should return a set with the two course_ids self.assertSetEqual( GeneratedCertificate.course_ids_with_certs_for_user(student_with_certs), {course_1.id, course_2.id} )