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_linked_in_add_to_profile_btn_not_appearing_without_config(self): # Without linked-in config don't show Add Certificate to LinkedIn button self.client.login(username="******", password="******") CourseModeFactory.create( course_id=self.course.id, mode_slug='verified', mode_display_name='verified', expiration_datetime=datetime.now(pytz.UTC) - timedelta(days=1) ) CourseEnrollment.enroll(self.user, self.course.id, mode='honor') self.course.start = datetime.now(pytz.UTC) - timedelta(days=2) self.course.end = datetime.now(pytz.UTC) - timedelta(days=1) self.course.display_name = u"Omega" self.course = self.update_course(self.course, self.user.id) download_url = 'www.edx.org' GeneratedCertificateFactory.create( user=self.user, course_id=self.course.id, status=CertificateStatuses.downloadable, mode='honor', grade='67', download_url=download_url ) response = self.client.get(reverse('dashboard')) self.assertEquals(response.status_code, 200) self.assertNotIn('Add Certificate to LinkedIn', response.content) response_url = 'http://www.linkedin.com/profile/add?_ed=' self.assertNotContains(response, escape(response_url))
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 setUp(self): super(CertificateServiceTests, self).setUp() self.service = CertificateService() self.course = CourseFactory() self.user = UserFactory() self.user_id = self.user.id self.course_id = self.course.id GeneratedCertificateFactory.create( status=CertificateStatuses.downloadable, user=self.user, course_id=self.course.id, grade=1.0 )
def setUp(self): super(EligibleCertificateManagerTest, self).setUp() self.user = UserFactory() self.eligible_cert = GeneratedCertificateFactory.create( status=CertificateStatuses.downloadable, user=self.user, course_id=self.courses[0].id ) self.ineligible_cert = GeneratedCertificateFactory.create( status=CertificateStatuses.audit_passing, user=self.user, course_id=self.courses[1].id )
def test_linked_in_add_to_profile_btn_with_certificate(self): # If user has a certificate with valid linked-in config then Add Certificate to LinkedIn button # should be visible. and it has URL value with valid parameters. self.client.login(username="******", password="******") LinkedInAddToProfileConfiguration.objects.create( company_identifier='0_mC_o2MizqdtZEmkVXjH4eYwMj4DnkCWrZP_D9', enabled=True ) CourseModeFactory.create( course_id=self.course.id, mode_slug='verified', mode_display_name='verified', expiration_datetime=datetime.now(pytz.UTC) - timedelta(days=1) ) self.course.certificate_available_date = datetime.now(pytz.UTC) - timedelta(days=1) CourseEnrollment.enroll(self.user, self.course.id, mode='honor') self.course.start = datetime.now(pytz.UTC) - timedelta(days=2) self.course.end = datetime.now(pytz.UTC) - timedelta(days=1) self.course.display_name = u"Omega" self.course = self.update_course(self.course, self.user.id) download_url = 'www.edx.org' GeneratedCertificateFactory.create( user=self.user, course_id=self.course.id, status=CertificateStatuses.downloadable, mode='honor', grade='67', download_url=download_url ) response = self.client.get(reverse('dashboard')) self.assertEquals(response.status_code, 200) self.assertIn('Add Certificate to LinkedIn', response.content) expected_url = ( u'http://www.linkedin.com/profile/add' u'?_ed=0_mC_o2MizqdtZEmkVXjH4eYwMj4DnkCWrZP_D9&' u'pfCertificationName={platform}+Honor+Code+Certificate+for+Omega&' u'pfCertificationUrl=www.edx.org&' u'source=o' ).format(platform=quote(settings.PLATFORM_NAME.encode('utf-8'))) self.assertContains(response, escape(expected_url))
def test_cert_status_with_generating(self): GeneratedCertificateFactory.create( user=self.student, course_id=self.course.id, status=CertificateStatuses.generating, mode='verified' ) self.assertEqual( certs_api.certificate_downloadable_status(self.student, self.course.id), { 'is_downloadable': False, 'is_generating': True, 'is_unverified': False, 'download_url': None, 'uuid': None, } )
def _generate_cert(self, status): """ Dry method to generate certificate. """ return GeneratedCertificateFactory.create( user=self.student, course_id=self.course.id, status=status, mode='verified' )
def setUp(self): freezer = freeze_time(self.now) freezer.start() self.addCleanup(freezer.stop) super(CertificatesDetailRestApiTest, self).setUp() GeneratedCertificateFactory.create( user=self.student, course_id=self.course.id, status=CertificateStatuses.downloadable, mode='verified', download_url='www.google.com', grade="0.88" ) self.namespaced_url = 'certificates_api:v0:certificates:detail'
def test_generate_user_certificates_with_unverified_cert_status(self): """ Generate user certificate when the certificate is unverified will trigger an update to the certificate if the user has since verified. """ # generate certificate with unverified status. GeneratedCertificateFactory.create( user=self.student, course_id=self.course.id, status=CertificateStatuses.unverified, mode='verified' ) with mock_passing_grade(): with self._mock_queue(): status = certs_api.generate_user_certificates(self.student, self.course.id) self.assertEqual(status, 'generating')
def setUp(self): super(CertificateInvalidationTest, self).setUp() self.course = CourseFactory() self.user = UserFactory() self.course_id = self.course.id self.certificate = GeneratedCertificateFactory.create( status=CertificateStatuses.downloadable, user=self.user, course_id=self.course_id)
def setUp(self): super(EligibleCertificateManagerTest, self).setUp() self.user = UserFactory() self.course1 = CourseOverviewFactory() self.course2 = CourseOverviewFactory( id=CourseKey.from_string('{}a'.format(self.course1.id)) ) self.eligible_cert = GeneratedCertificateFactory.create( status=CertificateStatuses.downloadable, user=self.user, course_id=self.course1.id ) self.ineligible_cert = GeneratedCertificateFactory.create( status=CertificateStatuses.audit_passing, user=self.user, course_id=self.course2.id )
def verify_pdf_certificate(self): """ Verifies the correct URL is returned in the response for PDF certificates. """ self.login_and_enroll() certificate_url = "http://test_certificate_url" GeneratedCertificateFactory.create( user=self.user, course_id=self.course.id, status=CertificateStatuses.downloadable, mode='verified', download_url=certificate_url, ) response = self.api_response() certificate_data = response.data[0]['certificate'] self.assertEqual(certificate_data['url'], certificate_url)
def test_invalidate_certificate_allowlist(self): """ Verify that CertificateService does not invalidate the certificate if it is allowlisted """ u = UserFactory.create() c = CourseFactory() course_key = c.id # pylint: disable=no-member GeneratedCertificateFactory.create( status=CertificateStatuses.downloadable, user=u, course_id=course_key, grade=1.0) CertificateAllowlistFactory(user=u, course_id=course_key) success = self.service.invalidate_certificate(u.id, course_key) assert not success cert = GeneratedCertificate.objects.get(user=u.id, course_id=course_key) assert cert.status == CertificateStatuses.downloadable
def setUp(self): super(CertificateInvalidationTest, self).setUp() self.course = CourseFactory() self.user = UserFactory() self.course_id = self.course.id self.certificate = GeneratedCertificateFactory.create( status=CertificateStatuses.downloadable, user=self.user, course_id=self.course_id )
def test_generate_user_certificates_with_unverified_cert_status(self): """ Generate user certificate when the certificate is unverified will trigger an update to the certificate if the user has since verified. """ self._setup_course_certificate() # generate certificate with unverified status. GeneratedCertificateFactory.create( user=self.student, course_id=self.course.id, status=CertificateStatuses.unverified, mode='verified' ) with mock_passing_grade(): with self._mock_queue(): status = certs_api.generate_user_certificates(self.student, self.course.id) self.assertEqual(status, 'generating')
def test_remove_allowlist_entry_with_certificate(self): """ Test for removing an allowlist entry. Verify that we also invalidate the certificate for the student. """ CertificateAllowlistFactory.create(course_id=self.course_run_key, user=self.user) GeneratedCertificateFactory.create( user=self.user, course_id=self.course_run_key, status=CertificateStatuses.downloadable, mode='verified' ) assert is_on_allowlist(self.user, self.course_run_key) result = remove_allowlist_entry(self.user, self.course_run_key) assert result certificate = GeneratedCertificate.objects.get(user=self.user, course_id=self.course_run_key) assert certificate.status == CertificateStatuses.unavailable assert not is_on_allowlist(self.user, self.course_run_key)
def setUp(self): super().setUp() self.course = CourseFactory() self.course_overview = CourseOverviewFactory.create(id=self.course.id) self.user = UserFactory() self.course_id = self.course.id # pylint: disable=no-member self.certificate = GeneratedCertificateFactory.create( status=CertificateStatuses.downloadable, user=self.user, course_id=self.course_id)
def verify_pdf_certificate(self): """ Verifies the correct URL is returned in the response for PDF certificates. """ self.login_and_enroll() certificate_url = "http://test_certificate_url" GeneratedCertificateFactory.create( user=self.user, course_id=self.course.id, status=CertificateStatuses.downloadable, mode='verified', download_url=certificate_url, ) response = self.api_response() certificate_data = response.data[0]['certificate'] self.assertEquals(certificate_data['url'], certificate_url)
def test_linked_in_add_to_profile_btn_with_certificate(self): # If user has a certificate with valid linked-in config then Add Certificate to LinkedIn button # should be visible. and it has URL value with valid parameters. self.client.login(username="******", password="******") linkedin_config = LinkedInAddToProfileConfiguration.objects.create(company_identifier='1337', enabled=True) CourseModeFactory.create( course_id=self.course.id, mode_slug='verified', mode_display_name='verified', expiration_datetime=datetime.now(pytz.UTC) - timedelta(days=1) ) CourseEnrollment.enroll(self.user, self.course.id, mode='honor') self.course.certificate_available_date = datetime.now(pytz.UTC) - timedelta(days=1) self.course.start = datetime.now(pytz.UTC) - timedelta(days=2) self.course.end = datetime.now(pytz.UTC) - timedelta(days=1) self.course.display_name = 'Omega' self.course = self.update_course(self.course, self.user.id) cert = GeneratedCertificateFactory.create( user=self.user, course_id=self.course.id, status=CertificateStatuses.downloadable, mode='honor', grade='67', download_url='https://www.edx.org' ) response = self.client.get(reverse('dashboard')) assert response.status_code == 200 self.assertContains(response, 'Add Certificate to LinkedIn') # We can switch to this and the commented out assertContains once edx-platform reaches Python 3.8 # expected_url = ( # 'https://www.linkedin.com/profile/add?startTask=CERTIFICATION_NAME&' # 'name={platform}+Honor+Code+Certificate+for+Omega&certUrl={cert_url}&' # 'organizationId={company_identifier}' # ).format( # platform=quote(settings.PLATFORM_NAME.encode('utf-8')), # cert_url=quote(cert.download_url, safe=''), # company_identifier=linkedin_config.company_identifier, # ) # self.assertContains(response, escape(expected_url)) # These can be removed (in favor of the above) once we are on Python 3.8. Fails in 3.5 because of dict ordering self.assertContains(response, escape('https://www.linkedin.com/profile/add?startTask=CERTIFICATION_NAME')) self.assertContains(response, escape('&name={platform}+Honor+Code+Certificate+for+Omega'.format( platform=quote(settings.PLATFORM_NAME.encode('utf-8')) ))) self.assertContains(response, escape('&certUrl={cert_url}'.format(cert_url=quote(cert.download_url, safe='')))) self.assertContains(response, escape('&organizationId={company_identifier}'.format( company_identifier=linkedin_config.company_identifier )))
def test_course_milestone_collected(self): student = UserFactory() course = CourseFactory.create(org='edx', number='998', display_name='Test Course') pre_requisite_course = CourseFactory.create(org='edx', number='999', display_name='Pre requisite Course') # set pre-requisite course set_prerequisite_courses(course.id, [unicode(pre_requisite_course.id)]) # get milestones collected by user before completing the pre-requisite course completed_milestones = milestones_achieved_by_user(student, unicode(pre_requisite_course.id)) self.assertEqual(len(completed_milestones), 0) GeneratedCertificateFactory.create( user=student, course_id=pre_requisite_course.id, status=CertificateStatuses.generating, mode='verified' ) # get milestones collected by user after user has completed the pre-requisite course completed_milestones = milestones_achieved_by_user(student, unicode(pre_requisite_course.id)) self.assertEqual(len(completed_milestones), 1) self.assertEqual(completed_milestones[0]['namespace'], unicode(pre_requisite_course.id))
def test_remove_allowlist_entry_with_certificate(self): """ Test for removing an allowlist entry. Verify that we also invalidate the certificate for the student. """ CertificateWhitelistFactory.create(course_id=self.course_run_key, user=self.user) GeneratedCertificateFactory.create( user=self.user, course_id=self.course_run_key, status=CertificateStatuses.downloadable, mode='verified' ) result = remove_allowlist_entry(self.user, self.course_run_key) assert result certificate = GeneratedCertificate.objects.get(user=self.user, course_id=self.course_run_key) assert certificate.status == CertificateStatuses.unavailable with pytest.raises(ObjectDoesNotExist) as error: CertificateWhitelist.objects.get(user=self.user, course_id=self.course_run_key) assert str(error.value) == "CertificateWhitelist matching query does not exist."
def setUp(self): freezer = freeze_time(self.now) freezer.start() self.addCleanup(freezer.stop) super(CertificatesRestApiTest, self).setUp() self.student = UserFactory.create(password=USER_PASSWORD) self.student_no_cert = UserFactory.create(password=USER_PASSWORD) self.staff_user = UserFactory.create(password=USER_PASSWORD, is_staff=True) GeneratedCertificateFactory.create( user=self.student, course_id=self.course.id, status=CertificateStatuses.downloadable, mode='verified', download_url='www.google.com', grade="0.88") self.namespaced_url = 'certificates_api:v0:certificates:detail'
def setUp(self): super().setUp() self.student = UserFactory() self.student_no_cert = UserFactory() self.course = CourseFactory.create( org='edx', number='verified', display_name='Verified Course', end=datetime.now(pytz.UTC), self_paced=False, certificate_available_date=datetime.now(pytz.UTC) - timedelta(days=2)) GeneratedCertificateFactory.create( user=self.student, course_id=self.course.id, status=CertificateStatuses.downloadable, mode='verified') self.request_factory = RequestFactory()
def setUpClass(cls): cls.freezer = freeze_time(cls.now) cls.freezer.start() super(CertificateGetTests, cls).setUpClass() cls.student = UserFactory() cls.student_no_cert = UserFactory() cls.uuid = uuid.uuid4().hex cls.web_cert_course = CourseFactory.create( org='edx', number='verified_1', display_name='Verified Course 1', cert_html_view_enabled=True ) cls.pdf_cert_course = CourseFactory.create( org='edx', number='verified_2', display_name='Verified Course 2', cert_html_view_enabled=False ) # certificate for the first course GeneratedCertificateFactory.create( user=cls.student, course_id=cls.web_cert_course.id, status=CertificateStatuses.downloadable, mode='verified', download_url='www.google.com', grade="0.88", verify_uuid=cls.uuid, ) # certificate for the second course GeneratedCertificateFactory.create( user=cls.student, course_id=cls.pdf_cert_course.id, status=CertificateStatuses.downloadable, mode='honor', download_url='www.gmail.com', grade="0.99", verify_uuid=cls.uuid, )
def test_unverified(self): """ Test the unverified method """ cert = GeneratedCertificateFactory.create( status=CertificateStatuses.downloadable, user=self.user, course_id=self.course_key) cert.mark_unverified() cert = GeneratedCertificate.objects.get(user=self.user, course_id=self.course_key) assert cert.status == CertificateStatuses.unverified
def test_invalidate(self): """ Test the invalidate method """ cert = GeneratedCertificateFactory.create( status=CertificateStatuses.downloadable, user=self.user, course_id=self.course_key) cert.invalidate() cert = GeneratedCertificate.objects.get(user=self.user, course_id=self.course_key) assert cert.status == CertificateStatuses.unavailable
def test_certificate_info_for_user_when_grade_changes(self, allow_certificate, whitelisted, grade, output): """ Verify that certificate_info_for_user works as expect in scenario when grading of problems changes after certificates already generated. In such scenario `Certificate delivered` should not depend on student's eligibility to get certificates since in above scenario eligibility can change over period of time. """ student = UserFactory() student.profile.allow_certificate = allow_certificate student.profile.save() certificate1 = GeneratedCertificateFactory.create( user=student, course_id=self.instructor_paced_course.id, status=CertificateStatuses.downloadable, mode='honor' ) certificate2 = GeneratedCertificateFactory.create( user=student, course_id=self.self_paced_course.id, status=CertificateStatuses.downloadable, mode='honor' ) # for instructor paced course certificate_info = certificate_info_for_user( student, self.instructor_paced_course.id, grade, whitelisted, certificate1 ) self.assertEqual(certificate_info, output) # for self paced course certificate_info = certificate_info_for_user( student, self.self_paced_course.id, grade, whitelisted, certificate2 ) self.assertEqual(certificate_info, output)
def setUp(self): freezer = freeze_time(self.now) freezer.start() self.addCleanup(freezer.stop) super(CertificatesRestApiTest, self).setUp() self.student = UserFactory.create(password=USER_PASSWORD) self.student_no_cert = UserFactory.create(password=USER_PASSWORD) self.staff_user = UserFactory.create(password=USER_PASSWORD, is_staff=True) GeneratedCertificateFactory.create( user=self.student, course_id=self.course.id, status=CertificateStatuses.downloadable, mode='verified', download_url='www.google.com', grade="0.88" ) self.namespaced_url = 'certificates_api:v0:certificates:detail' # create a configuration for django-oauth-toolkit (DOT) dot_app_user = UserFactory.create(password=USER_PASSWORD) dot_app = dot_models.Application.objects.create( name='test app', user=dot_app_user, client_type='confidential', authorization_grant_type='authorization-code', redirect_uris='http://localhost:8079/complete/edxorg/' ) self.dot_access_token = dot_models.AccessToken.objects.create( user=self.student, application=dot_app, expires=datetime.utcnow() + timedelta(weeks=1), scope='read write', token='16MGyP3OaQYHmpT1lK7Q6MMNAZsjwF' )
def test_badge_callback(self, handler): student = UserFactory() course = CourseFactory.create(org='edx', number='998', display_name='Test Course', issue_badges=True) CourseCompleteImageConfigurationFactory() CourseEnrollmentFactory(user=student, course_id=course.location.course_key, mode='honor') cert = GeneratedCertificateFactory.create( user=student, course_id=course.id, status=CertificateStatuses.generating, mode='verified' ) cert.status = CertificateStatuses.downloadable cert.save() self.assertTrue(handler.return_value.award.called)
def test_send_certificate_changed_event(self): """ Test whether the certificate changed event is sent at the end of the certificate update process. Expected result: - CERTIFICATE_CHANGED is sent and received by the mocked receiver. - The arguments that the receiver gets are the arguments sent by the event except the metadata generated on the fly. """ event_receiver = Mock(side_effect=self._event_receiver_side_effect) CERTIFICATE_CHANGED.connect(event_receiver) certificate = GeneratedCertificateFactory.create( status=CertificateStatuses.downloadable, user=self.user, course_id=self.course.id, mode=GeneratedCertificate.MODES.honor, name="Certificate", grade="100", download_url="https://certificate.pdf") certificate.grade = "50" certificate.save() self.assertTrue(self.receiver_called) self.assertDictContainsSubset( { "signal": CERTIFICATE_CHANGED, "sender": None, "certificate": CertificateData( user=UserData( pii=UserPersonalData( username=certificate.user.username, email=certificate.user.email, name=certificate.user.profile.name, ), id=certificate.user.id, is_active=certificate.user.is_active, ), course=CourseData(course_key=certificate.course_id, ), mode=certificate.mode, grade=certificate.grade, current_status=certificate.status, download_url=certificate.download_url, name=certificate.name, ), }, event_receiver.call_args.kwargs)
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) assert self.enrollment.refundable() GeneratedCertificateFactory.create( user=self.user, course_id=self.course.id, status=CertificateStatuses.downloadable, mode='verified') assert not self.enrollment.refundable() assert not 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 assert self.enrollment.refundable() assert self.enrollment.refundable( user_already_has_certs_for=GeneratedCertificate. course_ids_with_certs_for_user(self.user))
def test_notpassing(self): """ Test the notpassing method """ cert = GeneratedCertificateFactory.create( status=CertificateStatuses.downloadable, user=self.user, course_id=self.course_key) grade = '.3' cert.mark_notpassing(grade) cert = GeneratedCertificate.objects.get(user=self.user, course_id=self.course_key) assert cert.status == CertificateStatuses.notpassing assert cert.grade == grade
def test_get_allowlist_cert(self): allowlist_item = CertificateAllowlistFactory.create( course_id=self.course_run_key, user=self.user) cert = GeneratedCertificateFactory.create( status=CertificateStatuses.downloadable, user=self.user, course_id=self.course_run_key) ret = CertificateAllowlist.get_certificate_allowlist( course_id=self.course_run_key, student=self.user) assert len(ret) == 1 item = ret[0] assert item['id'] == allowlist_item.id assert item['certificate_generated'] == cert.created_date.strftime( "%B %d, %Y")
def test_can_be_added_to_allowlist_certificate_invalidated(self): """ Test to verify that a learner will be rejected from the allowlist if they currently appear on the certificate invalidation list. """ certificate = GeneratedCertificateFactory.create( user=self.user, course_id=self.course_run_key, status=CertificateStatuses.unavailable, mode='verified') CertificateInvalidationFactory.create( generated_certificate=certificate, invalidated_by=self.global_staff, active=True) assert not can_be_added_to_allowlist(self.user, self.course_run_key)
def setUp(self): freezer = freeze_time(self.now) freezer.start() self.addCleanup(freezer.stop) super(CertificatesDetailRestApiTest, self).setUp() self.cert = GeneratedCertificateFactory.create( user=self.student, course_id=self.course.id, status=CertificateStatuses.downloadable, mode='verified', download_url='www.google.com', grade="0.88") self.namespaced_url = 'certificates_api:v0:certificates:detail'
def test_create_certificate_invalidation_entry(self): """ Test to verify that we can use the functionality defined in the Certificates api.py to create certificate invalidation entries. This is functionality the Instructor Dashboard django app relies on. """ certificate = GeneratedCertificateFactory.create( user=self.user, course_id=self.course_run_key, status=CertificateStatuses.unavailable, mode='verified' ) result = create_certificate_invalidation_entry(certificate, self.global_staff, "Test!") assert result.generated_certificate == certificate assert result.active is True assert result.notes == "Test!"
def setUp(self): freezer = freeze_time(self.now) freezer.start() self.addCleanup(freezer.stop) super(CertificatesListRestApiTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.cert = GeneratedCertificateFactory.create( user=self.student, course_id=self.course.id, status=CertificateStatuses.downloadable, mode='verified', download_url='www.google.com', grade="0.88", ) self.student.is_staff = True self.student.save() self.namespaced_url = 'certificates_api:v0:certificates:list'
def setUp(self): super(AwardCourseCertificatesTestCase, self).setUp() self.course = CourseOverviewFactory.create( self_paced=True # Any option to allow the certificate to be viewable for the course ) self.student = UserFactory.create(username='******') # Instantiate the Certificate first so that the config doesn't execute issuance self.certificate = GeneratedCertificateFactory.create( user=self.student, mode='verified', course_id=self.course.id, status='downloadable' ) self.create_credentials_config() self.site = SiteFactory() ClientFactory.create(name='credentials') UserFactory.create(username=settings.CREDENTIALS_SERVICE_USERNAME)
def verify_downloadable_pdf_cert(self): """ Verifies certificate_downloadable_status returns the correct response for PDF certificates. """ cert = GeneratedCertificateFactory.create( user=self.student, course_id=self.course.id, status=CertificateStatuses.downloadable, mode='verified', download_url='www.google.com', ) assert certificate_downloadable_status(self.student, self.course.id) ==\ {'is_downloadable': True, 'is_generating': False, 'is_unverified': False, 'download_url': 'www.google.com', 'is_pdf_certificate': True, 'uuid': cert.verify_uuid}
def test_certificate_info_for_user_when_grade_changes(self, allow_certificate, whitelisted, grade, output): """ Verify that certificate_info_for_user works as expect in scenario when grading of problems changes after certificates already generated. In such scenario `Certificate delivered` should not depend on student's eligibility to get certificates since in above scenario eligibility can change over period of time. """ student = UserFactory() course = CourseFactory.create(org='edx', number='verified', display_name='Verified Course') student.profile.allow_certificate = allow_certificate student.profile.save() certificate = GeneratedCertificateFactory.create( user=student, course_id=course.id, status=CertificateStatuses.downloadable, mode='honor' ) certificate_info = certificate_info_for_user(student, grade, whitelisted, certificate) self.assertEqual(certificate_info, output)
def test_get_certificate_invalidation_entry(self): """ Test to verify that we can retrieve a certificate invalidation entry for a learner. """ certificate = GeneratedCertificateFactory.create( user=self.user, course_id=self.course_run_key, status=CertificateStatuses.unavailable, mode='verified') invalidation = CertificateInvalidationFactory.create( generated_certificate=certificate, invalidated_by=self.global_staff, active=True) retrieved_invalidation = get_certificate_invalidation_entry( certificate) assert retrieved_invalidation.id == invalidation.id assert retrieved_invalidation.generated_certificate == certificate assert retrieved_invalidation.active == invalidation.active
def setUp(self): super(AwardCourseCertificatesTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.available_date = datetime.now(pytz.UTC) + timedelta(days=1) self.course = CourseOverviewFactory.create( self_paced= True, # Any option to allow the certificate to be viewable for the course certificate_available_date=self.available_date, ) self.student = UserFactory.create(username='******') # Instantiate the Certificate first so that the config doesn't execute issuance self.certificate = GeneratedCertificateFactory.create( user=self.student, mode='verified', course_id=self.course.id, status='downloadable') self.create_credentials_config() self.site = SiteFactory() ApplicationFactory.create(name='credentials') UserFactory.create(username=settings.CREDENTIALS_SERVICE_USERNAME)
def verify_downloadable_pdf_cert(self): """ Verifies certificate_downloadable_status returns the correct response for PDF certificates. """ cert = GeneratedCertificateFactory.create( user=self.student, course_id=self.course.id, status=CertificateStatuses.downloadable, mode='verified', download_url='www.google.com', ) self.assertEqual( certs_api.certificate_downloadable_status(self.student, self.course.id), { 'is_downloadable': True, 'is_generating': False, 'is_unverified': False, 'download_url': 'www.google.com', 'uuid': cert.verify_uuid } )
def test_query_counts(self): # Test student with no certificates student_no_cert = UserFactory.create(password=self.user_password) with self.assertNumQueries(22): resp = self.get_response( AuthType.jwt, requesting_user=student_no_cert, requested_user=student_no_cert, ) self.assertEqual(resp.status_code, status.HTTP_200_OK) self.assertEqual(len(resp.data), 0) # Test student with 1 certificate with self.assertNumQueries(17): resp = self.get_response( AuthType.jwt, requesting_user=self.student, requested_user=self.student, ) self.assertEqual(resp.status_code, status.HTTP_200_OK) self.assertEqual(len(resp.data), 1) # Test student with 2 certificates student_2_certs = UserFactory.create(password=self.user_password) course = CourseFactory.create( org='edx', number='test', display_name='Test Course', self_paced=True, ) CourseOverviewFactory.create( id=course.id, display_org_with_default='edx', display_name='Test Course', cert_html_view_enabled=True, self_paced=True, ) GeneratedCertificateFactory.create( user=student_2_certs, course_id=self.course.id, status=CertificateStatuses.downloadable, mode='verified', download_url='www.google.com', grade="0.88", ) GeneratedCertificateFactory.create( user=student_2_certs, course_id=course.id, status=CertificateStatuses.downloadable, mode='verified', download_url='www.google.com', grade="0.88", ) with self.assertNumQueries(17): resp = self.get_response( AuthType.jwt, requesting_user=student_2_certs, requested_user=student_2_certs, ) self.assertEqual(resp.status_code, status.HTTP_200_OK) self.assertEqual(len(resp.data), 2)