def test_cert_grade_no_grades(self): """ Tests that the default cert info is returned when the learner has no persisted grade or grade in the certs table. """ user = Mock(username="******", id="1") survey_url = "http://a_survey.com" course = Mock( end_of_course_survey_url=survey_url, certificates_display_behavior='end', id=CourseLocator(org="x", course="y", run="z"), ) course_mode = 'honor' cert_status = {'status': 'generating', 'mode': 'honor'} with patch('lms.djangoapps.grades.new.course_grade_factory.CourseGradeFactory.read') as patch_persisted_grade: patch_persisted_grade.return_value = None self.assertEqual( _cert_info(user, course, cert_status, course_mode), { 'status': 'processing', 'show_disabled_download_button': False, 'show_download_url': False, 'show_survey_button': False, 'can_unenroll': True, } )
def test_cert_grade_no_grades(self): """ Tests that the default cert info is returned when the learner has no persisted grade or grade in the certs table. """ user = Mock(username="******", id="1") survey_url = "http://a_survey.com" course = Mock( end_of_course_survey_url=survey_url, certificates_display_behavior='end', id=CourseLocator(org="x", course="y", run="z"), ) course_mode = 'honor' cert_status = {'status': 'generating', 'mode': 'honor'} with patch('lms.djangoapps.grades.course_grade_factory.CourseGradeFactory.read') as patch_persisted_grade: patch_persisted_grade.return_value = None self.assertEqual( _cert_info(user, course, cert_status, course_mode), { 'status': 'processing', 'show_survey_button': False, 'can_unenroll': True, } )
def test_cert_grade(self, persisted_grade, cert_grade): """ Tests that the higher of the persisted grade and the grade from the certs table is used on the learner dashboard. """ expected_grade = max(persisted_grade, cert_grade) user = Mock(username="******", id="1") survey_url = "http://a_survey.com" course = Mock( end_of_course_survey_url=survey_url, certificates_display_behavior='end', id=CourseLocator(org="x", course="y", run="z"), ) course_mode = 'honor' if cert_grade is not None: cert_status = {'status': 'generating', 'grade': unicode(cert_grade), 'mode': 'honor'} else: cert_status = {'status': 'generating', 'mode': 'honor'} with patch('lms.djangoapps.grades.course_grade_factory.CourseGradeFactory.read') as patch_persisted_grade: patch_persisted_grade.return_value = Mock(percent=persisted_grade) self.assertEqual( _cert_info(user, course, cert_status, course_mode), { 'status': 'generating', 'show_survey_button': True, 'survey_url': survey_url, 'grade': unicode(expected_grade), 'mode': 'honor', 'linked_in_url': None, 'can_unenroll': False, } )
def test_linked_in_url_with_unicode_course_display_name(self): """Test with unicode display name values.""" user = Mock(username="******") survey_url = "http://a_survey.com" course = Mock(end_of_course_survey_url=survey_url, certificates_display_behavior='end', display_name=u'edx/abc/courseregisters®') download_url = 'http://s3.edx/cert' cert_status = { 'status': 'downloadable', 'grade': '67', 'download_url': download_url, 'mode': 'honor' } LinkedInAddToProfileConfiguration( company_identifier='0_mC_o2MizqdtZEmkVXjH4eYwMj4DnkCWrZP_D9', enabled=True).save() status_dict = _cert_info(user, course, cert_status, 'honor') expected_url = ( 'http://www.linkedin.com/profile/add' '?_ed=0_mC_o2MizqdtZEmkVXjH4eYwMj4DnkCWrZP_D9&' 'pfCertificationName=edX+Honor+Code+Certificate+for+edx%2Fabc%2Fcourseregisters%C2%AE&' 'pfCertificationUrl=http%3A%2F%2Fs3.edx%2Fcert&' 'source=o') self.assertEqual(expected_url, status_dict['linked_in_url'])
def test_linked_in_url_not_exists_without_config(self): user = Mock(username="******") survey_url = "http://a_survey.com" course = Mock(display_name="Demo Course", end_of_course_survey_url=survey_url, certificates_display_behavior='end') download_url = 'http://s3.edx/cert' cert_status = { 'status': 'downloadable', 'grade': '67', 'download_url': download_url, 'mode': 'verified' } self.assertEqual( _cert_info(user, course, cert_status, 'verified'), { 'status': 'ready', 'show_disabled_download_button': False, 'show_download_url': True, 'download_url': download_url, 'show_survey_button': True, 'survey_url': survey_url, 'grade': '67', 'mode': 'verified', 'linked_in_url': None }) # Enabling the configuration will cause the LinkedIn # "add to profile" button to appear. # We need to clear the cache again to make sure we # pick up the modified configuration. cache.clear() LinkedInAddToProfileConfiguration( company_identifier='0_mC_o2MizqdtZEmkVXjH4eYwMj4DnkCWrZP_D9', enabled=True).save() status_dict = _cert_info(user, course, cert_status, 'honor') expected_url = ( 'http://www.linkedin.com/profile/add' '?_ed=0_mC_o2MizqdtZEmkVXjH4eYwMj4DnkCWrZP_D9&' 'pfCertificationName=edX+Verified+Certificate+for+Demo+Course&' 'pfCertificationUrl=http%3A%2F%2Fs3.edx%2Fcert&' 'source=o') self.assertEqual(expected_url, status_dict['linked_in_url'])
def test_linked_in_url_certificate_types(self, cert_mode, cert_name): user = Mock(username="******") course = Mock(display_name='DemoX', end_of_course_survey_url='http://example.com', certificates_display_behavior='end') cert_status = { 'status': 'downloadable', 'grade': '67', 'download_url': 'http://edx.org', 'mode': cert_mode } LinkedInAddToProfileConfiguration(company_identifier="abcd123", enabled=True).save() status_dict = _cert_info(user, course, cert_status, cert_mode) self.assertIn(cert_name.replace(' ', '+'), status_dict['linked_in_url'])
def test_cert_grade(self, persisted_grade, cert_grade): """ Tests that the higher of the persisted grade and the grade from the certs table is used on the learner dashboard. """ expected_grade = max(persisted_grade, cert_grade) user = Mock(username="******", id="1") survey_url = "http://a_survey.com" course = Mock( end_of_course_survey_url=survey_url, certificates_display_behavior='end', id=CourseLocator(org="x", course="y", run="z"), ) course_mode = 'honor' if cert_grade is not None: cert_status = {'status': 'generating', 'grade': unicode(cert_grade), 'mode': 'honor'} else: cert_status = {'status': 'generating', 'mode': 'honor'} with patch('lms.djangoapps.grades.new.course_grade_factory.CourseGradeFactory.read') as patch_persisted_grade: patch_persisted_grade.return_value = Mock(percent=persisted_grade) self.assertEqual( _cert_info(user, course, cert_status, course_mode), { 'status': 'generating', 'show_disabled_download_button': True, 'show_download_url': False, 'show_survey_button': True, 'survey_url': survey_url, 'grade': unicode(expected_grade), 'mode': 'honor', 'linked_in_url': None, 'can_unenroll': False, } )
def test_cert_info(self): user = Mock(username="******", id="1") survey_url = "http://a_survey.com" course = Mock( end_of_course_survey_url=survey_url, certificates_display_behavior='end', id=CourseLocator(org="x", course="y", run="z"), ) course_mode = 'honor' self.assertEqual( _cert_info(user, course, None, course_mode), { 'status': 'processing', 'show_disabled_download_button': False, 'show_download_url': False, 'show_survey_button': False, 'can_unenroll': True, } ) cert_status = {'status': 'unavailable'} self.assertEqual( _cert_info(user, course, cert_status, course_mode), { 'status': 'processing', 'show_disabled_download_button': False, 'show_download_url': False, 'show_survey_button': False, 'mode': None, 'linked_in_url': None, 'can_unenroll': True, } ) cert_status = {'status': 'generating', 'grade': '0.67', 'mode': 'honor'} with patch('lms.djangoapps.grades.new.course_grade_factory.CourseGradeFactory.read') as patch_persisted_grade: patch_persisted_grade.return_value = Mock(percent=1.0) self.assertEqual( _cert_info(user, course, cert_status, course_mode), { 'status': 'generating', 'show_disabled_download_button': True, 'show_download_url': False, 'show_survey_button': True, 'survey_url': survey_url, 'grade': '1.0', 'mode': 'honor', 'linked_in_url': None, 'can_unenroll': False, } ) cert_status = {'status': 'generating', 'grade': '0.67', 'mode': 'honor'} self.assertEqual( _cert_info(user, course, cert_status, course_mode), { 'status': 'generating', 'show_disabled_download_button': True, 'show_download_url': False, 'show_survey_button': True, 'survey_url': survey_url, 'grade': '0.67', 'mode': 'honor', 'linked_in_url': None, 'can_unenroll': False, } ) download_url = 'http://s3.edx/cert' cert_status = { 'status': 'downloadable', 'grade': '0.67', 'download_url': download_url, 'mode': 'honor' } self.assertEqual( _cert_info(user, course, cert_status, course_mode), { 'status': 'ready', 'show_disabled_download_button': False, 'show_download_url': True, 'download_url': download_url, 'show_survey_button': True, 'survey_url': survey_url, 'grade': '0.67', 'mode': 'honor', 'linked_in_url': None, 'can_unenroll': False, } ) cert_status = { 'status': 'notpassing', 'grade': '0.67', 'download_url': download_url, 'mode': 'honor' } self.assertEqual( _cert_info(user, course, cert_status, course_mode), { 'status': 'notpassing', 'show_disabled_download_button': False, 'show_download_url': False, 'show_survey_button': True, 'survey_url': survey_url, 'grade': '0.67', 'mode': 'honor', 'linked_in_url': None, 'can_unenroll': True, } ) # Test a course that doesn't have a survey specified course2 = Mock(end_of_course_survey_url=None, id=CourseLocator(org="a", course="b", run="c")) cert_status = { 'status': 'notpassing', 'grade': '0.67', 'download_url': download_url, 'mode': 'honor' } self.assertEqual( _cert_info(user, course2, cert_status, course_mode), { 'status': 'notpassing', 'show_disabled_download_button': False, 'show_download_url': False, 'show_survey_button': False, 'grade': '0.67', 'mode': 'honor', 'linked_in_url': None, 'can_unenroll': True, } ) # test when the display is unavailable or notpassing, we get the correct results out course2.certificates_display_behavior = 'early_no_info' cert_status = {'status': 'unavailable'} self.assertEqual(_cert_info(user, course2, cert_status, course_mode), {}) cert_status = { 'status': 'notpassing', 'grade': '0.67', 'download_url': download_url, 'mode': 'honor' } self.assertEqual(_cert_info(user, course2, cert_status, course_mode), {})
def test_cert_info(self): user = Mock(username="******") survey_url = "http://a_survey.com" course = Mock(end_of_course_survey_url=survey_url) self.assertEqual(_cert_info(user, course, None), {'status': 'processing', 'show_disabled_download_button': False, 'show_download_url': False, 'show_survey_button': False, }) cert_status = {'status': 'unavailable'} self.assertEqual(_cert_info(user, course, cert_status), {'status': 'processing', 'show_disabled_download_button': False, 'show_download_url': False, 'show_survey_button': False, 'mode': None }) cert_status = {'status': 'generating', 'grade': '67', 'mode': 'honor'} self.assertEqual(_cert_info(user, course, cert_status), {'status': 'generating', 'show_disabled_download_button': True, 'show_download_url': False, 'show_survey_button': True, 'survey_url': survey_url, 'grade': '67', 'mode': 'honor' }) cert_status = {'status': 'regenerating', 'grade': '67', 'mode': 'verified'} self.assertEqual(_cert_info(user, course, cert_status), {'status': 'generating', 'show_disabled_download_button': True, 'show_download_url': False, 'show_survey_button': True, 'survey_url': survey_url, 'grade': '67', 'mode': 'verified' }) download_url = 'http://s3.edx/cert' cert_status = {'status': 'downloadable', 'grade': '67', 'download_url': download_url, 'mode': 'honor'} self.assertEqual(_cert_info(user, course, cert_status), {'status': 'ready', 'show_disabled_download_button': False, 'show_download_url': True, 'download_url': download_url, 'show_survey_button': True, 'survey_url': survey_url, 'grade': '67', 'mode': 'honor' }) cert_status = {'status': 'notpassing', 'grade': '67', 'download_url': download_url, 'mode': 'honor'} self.assertEqual(_cert_info(user, course, cert_status), {'status': 'notpassing', 'show_disabled_download_button': False, 'show_download_url': False, 'show_survey_button': True, 'survey_url': survey_url, 'grade': '67', 'mode': 'honor' }) # Test a course that doesn't have a survey specified course2 = Mock(end_of_course_survey_url=None) cert_status = {'status': 'notpassing', 'grade': '67', 'download_url': download_url, 'mode': 'honor'} self.assertEqual(_cert_info(user, course2, cert_status), {'status': 'notpassing', 'show_disabled_download_button': False, 'show_download_url': False, 'show_survey_button': False, 'grade': '67', 'mode': 'honor' })
def test_cert_info(self): user = Mock(username="******") survey_url = "http://a_survey.com" course = Mock(end_of_course_survey_url=survey_url, certificates_display_behavior='end') self.assertEqual(_cert_info(user, course, None), {'status': 'processing', 'show_disabled_download_button': False, 'show_download_url': False, 'show_survey_button': False, }) cert_status = {'status': 'unavailable'} self.assertEqual(_cert_info(user, course, cert_status), {'status': 'processing', 'show_disabled_download_button': False, 'show_download_url': False, 'show_survey_button': False, 'mode': None }) cert_status = {'status': 'generating', 'grade': '67', 'mode': 'honor'} self.assertEqual(_cert_info(user, course, cert_status), {'status': 'generating', 'show_disabled_download_button': True, 'show_download_url': False, 'show_survey_button': True, 'survey_url': survey_url, 'grade': '67', 'mode': 'honor' }) cert_status = {'status': 'regenerating', 'grade': '67', 'mode': 'verified'} self.assertEqual(_cert_info(user, course, cert_status), {'status': 'generating', 'show_disabled_download_button': True, 'show_download_url': False, 'show_survey_button': True, 'survey_url': survey_url, 'grade': '67', 'mode': 'verified' }) download_url = 'http://s3.edx/cert' cert_status = {'status': 'downloadable', 'grade': '67', 'download_url': download_url, 'mode': 'honor'} self.assertEqual(_cert_info(user, course, cert_status), {'status': 'ready', 'show_disabled_download_button': False, 'show_download_url': True, 'download_url': download_url, 'show_survey_button': True, 'survey_url': survey_url, 'grade': '67', 'mode': 'honor' }) cert_status = {'status': 'notpassing', 'grade': '67', 'download_url': download_url, 'mode': 'honor'} self.assertEqual(_cert_info(user, course, cert_status), {'status': 'notpassing', 'show_disabled_download_button': False, 'show_download_url': False, 'show_survey_button': True, 'survey_url': survey_url, 'grade': '67', 'mode': 'honor' }) # Test a course that doesn't have a survey specified course2 = Mock(end_of_course_survey_url=None) cert_status = {'status': 'notpassing', 'grade': '67', 'download_url': download_url, 'mode': 'honor'} self.assertEqual(_cert_info(user, course2, cert_status), {'status': 'notpassing', 'show_disabled_download_button': False, 'show_download_url': False, 'show_survey_button': False, 'grade': '67', 'mode': 'honor' }) # test when the display is unavailable or notpassing, we get the correct results out course2.certificates_display_behavior = 'early_no_info' cert_status = {'status': 'unavailable'} self.assertIsNone(_cert_info(user, course2, cert_status)) cert_status = {'status': 'notpassing', 'grade': '67', 'download_url': download_url, 'mode': 'honor'} self.assertIsNone(_cert_info(user, course2, cert_status))
def test_cert_info(self): user = Mock(username="******") survey_url = "http://a_survey.com" course = Mock(end_of_course_survey_url=survey_url, certificates_display_behavior='end') self.assertEqual( _cert_info(user, course, None), { 'status': 'processing', 'show_disabled_download_button': False, 'show_download_url': False, 'show_survey_button': False, }) cert_status = {'status': 'unavailable'} self.assertEqual( _cert_info(user, course, cert_status), { 'status': 'processing', 'show_disabled_download_button': False, 'show_download_url': False, 'show_survey_button': False, 'mode': None }) cert_status = {'status': 'generating', 'grade': '67', 'mode': 'honor'} self.assertEqual( _cert_info(user, course, cert_status), { 'status': 'generating', 'show_disabled_download_button': True, 'show_download_url': False, 'show_survey_button': True, 'survey_url': survey_url, 'grade': '67', 'mode': 'honor' }) cert_status = { 'status': 'regenerating', 'grade': '67', 'mode': 'verified' } self.assertEqual( _cert_info(user, course, cert_status), { 'status': 'generating', 'show_disabled_download_button': True, 'show_download_url': False, 'show_survey_button': True, 'survey_url': survey_url, 'grade': '67', 'mode': 'verified' }) download_url = 'http://s3.edx/cert' cert_status = { 'status': 'downloadable', 'grade': '67', 'download_url': download_url, 'mode': 'honor' } self.assertEqual( _cert_info(user, course, cert_status), { 'status': 'ready', 'show_disabled_download_button': False, 'show_download_url': True, 'download_url': download_url, 'show_survey_button': True, 'survey_url': survey_url, 'grade': '67', 'mode': 'honor' }) cert_status = { 'status': 'notpassing', 'grade': '67', 'download_url': download_url, 'mode': 'honor' } self.assertEqual( _cert_info(user, course, cert_status), { 'status': 'notpassing', 'show_disabled_download_button': False, 'show_download_url': False, 'show_survey_button': True, 'survey_url': survey_url, 'grade': '67', 'mode': 'honor' }) # Test a course that doesn't have a survey specified course2 = Mock(end_of_course_survey_url=None) cert_status = { 'status': 'notpassing', 'grade': '67', 'download_url': download_url, 'mode': 'honor' } self.assertEqual( _cert_info(user, course2, cert_status), { 'status': 'notpassing', 'show_disabled_download_button': False, 'show_download_url': False, 'show_survey_button': False, 'grade': '67', 'mode': 'honor' }) # test when the display is unavailable or notpassing, we get the correct results out course2.certificates_display_behavior = 'early_no_info' cert_status = {'status': 'unavailable'} self.assertIsNone(_cert_info(user, course2, cert_status)) cert_status = { 'status': 'notpassing', 'grade': '67', 'download_url': download_url, 'mode': 'honor' } self.assertIsNone(_cert_info(user, course2, cert_status))
def test_cert_info(self): user = Mock(username="******") survey_url = "http://a_survey.com" course = Mock(end_of_course_survey_url=survey_url, certificates_display_behavior="end") course_mode = "honor" self.assertEqual( _cert_info(user, course, None, course_mode), { "status": "processing", "show_disabled_download_button": False, "show_download_url": False, "show_survey_button": False, }, ) cert_status = {"status": "unavailable"} self.assertEqual( _cert_info(user, course, cert_status, course_mode), { "status": "processing", "show_disabled_download_button": False, "show_download_url": False, "show_survey_button": False, "mode": None, "linked_in_url": None, }, ) cert_status = {"status": "generating", "grade": "67", "mode": "honor"} self.assertEqual( _cert_info(user, course, cert_status, course_mode), { "status": "generating", "show_disabled_download_button": True, "show_download_url": False, "show_survey_button": True, "survey_url": survey_url, "grade": "67", "mode": "honor", "linked_in_url": None, }, ) cert_status = {"status": "regenerating", "grade": "67", "mode": "verified"} self.assertEqual( _cert_info(user, course, cert_status, course_mode), { "status": "generating", "show_disabled_download_button": True, "show_download_url": False, "show_survey_button": True, "survey_url": survey_url, "grade": "67", "mode": "verified", "linked_in_url": None, }, ) download_url = "http://s3.edx/cert" cert_status = {"status": "downloadable", "grade": "67", "download_url": download_url, "mode": "honor"} self.assertEqual( _cert_info(user, course, cert_status, course_mode), { "status": "ready", "show_disabled_download_button": False, "show_download_url": True, "download_url": download_url, "show_survey_button": True, "survey_url": survey_url, "grade": "67", "mode": "honor", "linked_in_url": None, }, ) cert_status = {"status": "notpassing", "grade": "67", "download_url": download_url, "mode": "honor"} self.assertEqual( _cert_info(user, course, cert_status, course_mode), { "status": "notpassing", "show_disabled_download_button": False, "show_download_url": False, "show_survey_button": True, "survey_url": survey_url, "grade": "67", "mode": "honor", "linked_in_url": None, }, ) # Test a course that doesn't have a survey specified course2 = Mock(end_of_course_survey_url=None) cert_status = {"status": "notpassing", "grade": "67", "download_url": download_url, "mode": "honor"} self.assertEqual( _cert_info(user, course2, cert_status, course_mode), { "status": "notpassing", "show_disabled_download_button": False, "show_download_url": False, "show_survey_button": False, "grade": "67", "mode": "honor", "linked_in_url": None, }, ) # test when the display is unavailable or notpassing, we get the correct results out course2.certificates_display_behavior = "early_no_info" cert_status = {"status": "unavailable"} self.assertIsNone(_cert_info(user, course2, cert_status, course_mode)) cert_status = {"status": "notpassing", "grade": "67", "download_url": download_url, "mode": "honor"} self.assertIsNone(_cert_info(user, course2, cert_status, course_mode))
def test_cert_info(self): user = Mock(username="******", id="1") survey_url = "http://a_survey.com" course = Mock( end_of_course_survey_url=survey_url, certificates_display_behavior='end', id=CourseLocator(org="x", course="y", run="z"), ) course_mode = 'honor' self.assertEqual( _cert_info(user, course, None, course_mode), { 'status': 'processing', 'show_disabled_download_button': False, 'show_download_url': False, 'show_survey_button': False, 'can_unenroll': True, }) cert_status = {'status': 'unavailable'} self.assertEqual( _cert_info(user, course, cert_status, course_mode), { 'status': 'processing', 'show_disabled_download_button': False, 'show_download_url': False, 'show_survey_button': False, 'mode': None, 'linked_in_url': None, 'can_unenroll': True, }) cert_status = {'status': 'generating', 'grade': '67', 'mode': 'honor'} with patch( 'lms.djangoapps.grades.new.course_grade.CourseGradeFactory.get_persisted' ) as patch_persisted_grade: patch_persisted_grade.return_value = Mock(percent=100) self.assertEqual( _cert_info(user, course, cert_status, course_mode), { 'status': 'generating', 'show_disabled_download_button': True, 'show_download_url': False, 'show_survey_button': True, 'survey_url': survey_url, 'grade': '100', 'mode': 'honor', 'linked_in_url': None, 'can_unenroll': False, }) cert_status = {'status': 'generating', 'grade': '67', 'mode': 'honor'} self.assertEqual( _cert_info(user, course, cert_status, course_mode), { 'status': 'generating', 'show_disabled_download_button': True, 'show_download_url': False, 'show_survey_button': True, 'survey_url': survey_url, 'grade': '67', 'mode': 'honor', 'linked_in_url': None, 'can_unenroll': False, }) download_url = 'http://s3.edx/cert' cert_status = { 'status': 'downloadable', 'grade': '67', 'download_url': download_url, 'mode': 'honor' } self.assertEqual( _cert_info(user, course, cert_status, course_mode), { 'status': 'ready', 'show_disabled_download_button': False, 'show_download_url': True, 'download_url': download_url, 'show_survey_button': True, 'survey_url': survey_url, 'grade': '67', 'mode': 'honor', 'linked_in_url': None, 'can_unenroll': False, }) cert_status = { 'status': 'notpassing', 'grade': '67', 'download_url': download_url, 'mode': 'honor' } self.assertEqual( _cert_info(user, course, cert_status, course_mode), { 'status': 'notpassing', 'show_disabled_download_button': False, 'show_download_url': False, 'show_survey_button': True, 'survey_url': survey_url, 'grade': '67', 'mode': 'honor', 'linked_in_url': None, 'can_unenroll': True, }) # Test a course that doesn't have a survey specified course2 = Mock(end_of_course_survey_url=None, id=CourseLocator(org="a", course="b", run="c")) cert_status = { 'status': 'notpassing', 'grade': '67', 'download_url': download_url, 'mode': 'honor' } self.assertEqual( _cert_info(user, course2, cert_status, course_mode), { 'status': 'notpassing', 'show_disabled_download_button': False, 'show_download_url': False, 'show_survey_button': False, 'grade': '67', 'mode': 'honor', 'linked_in_url': None, 'can_unenroll': True, }) # test when the display is unavailable or notpassing, we get the correct results out course2.certificates_display_behavior = 'early_no_info' cert_status = {'status': 'unavailable'} self.assertEqual(_cert_info(user, course2, cert_status, course_mode), {}) cert_status = { 'status': 'notpassing', 'grade': '67', 'download_url': download_url, 'mode': 'honor' } self.assertEqual(_cert_info(user, course2, cert_status, course_mode), {})
def test_cert_info(self): user = Mock(username="******") survey_url = "http://a_survey.com" course = Mock(end_of_course_survey_url=survey_url) self.assertEqual( _cert_info(user, course, None), { "status": "processing", "show_disabled_download_button": False, "show_download_url": False, "show_survey_button": False, }, ) cert_status = {"status": "unavailable"} self.assertEqual( _cert_info(user, course, cert_status), { "status": "processing", "show_disabled_download_button": False, "show_download_url": False, "show_survey_button": False, }, ) cert_status = {"status": "generating", "grade": "67"} self.assertEqual( _cert_info(user, course, cert_status), { "status": "generating", "show_disabled_download_button": True, "show_download_url": False, "show_survey_button": True, "survey_url": survey_url, "grade": "67", }, ) cert_status = {"status": "regenerating", "grade": "67"} self.assertEqual( _cert_info(user, course, cert_status), { "status": "generating", "show_disabled_download_button": True, "show_download_url": False, "show_survey_button": True, "survey_url": survey_url, "grade": "67", }, ) download_url = "http://s3.edx/cert" cert_status = {"status": "downloadable", "grade": "67", "download_url": download_url} self.assertEqual( _cert_info(user, course, cert_status), { "status": "ready", "show_disabled_download_button": False, "show_download_url": True, "download_url": download_url, "show_survey_button": True, "survey_url": survey_url, "grade": "67", }, ) cert_status = {"status": "notpassing", "grade": "67", "download_url": download_url} self.assertEqual( _cert_info(user, course, cert_status), { "status": "notpassing", "show_disabled_download_button": False, "show_download_url": False, "show_survey_button": True, "survey_url": survey_url, "grade": "67", }, ) # Test a course that doesn't have a survey specified course2 = Mock(end_of_course_survey_url=None) cert_status = {"status": "notpassing", "grade": "67", "download_url": download_url} self.assertEqual( _cert_info(user, course2, cert_status), { "status": "notpassing", "show_disabled_download_button": False, "show_download_url": False, "show_survey_button": False, "grade": "67", }, )
def test_cert_info(self): user = Mock(username="******", id="1") survey_url = "http://a_survey.com" course = Mock( end_of_course_survey_url=survey_url, certificates_display_behavior="end", id=CourseLocator(org="x", course="y", run="z"), ) course_mode = "honor" self.assertEqual( _cert_info(user, course, None, course_mode), { "status": "processing", "show_disabled_download_button": False, "show_download_url": False, "show_survey_button": False, "can_unenroll": True, }, ) cert_status = {"status": "unavailable"} self.assertEqual( _cert_info(user, course, cert_status, course_mode), { "status": "processing", "show_disabled_download_button": False, "show_download_url": False, "show_survey_button": False, "mode": None, "linked_in_url": None, "can_unenroll": True, }, ) cert_status = {"status": "generating", "grade": "67", "mode": "honor"} with patch("lms.djangoapps.grades.new.course_grade.CourseGradeFactory.get_persisted") as patch_persisted_grade: patch_persisted_grade.return_value = Mock(percent=100) self.assertEqual( _cert_info(user, course, cert_status, course_mode), { "status": "generating", "show_disabled_download_button": True, "show_download_url": False, "show_survey_button": True, "survey_url": survey_url, "grade": "100", "mode": "honor", "linked_in_url": None, "can_unenroll": False, }, ) cert_status = {"status": "generating", "grade": "67", "mode": "honor"} self.assertEqual( _cert_info(user, course, cert_status, course_mode), { "status": "generating", "show_disabled_download_button": True, "show_download_url": False, "show_survey_button": True, "survey_url": survey_url, "grade": "67", "mode": "honor", "linked_in_url": None, "can_unenroll": False, }, ) download_url = "http://s3.edx/cert" cert_status = {"status": "downloadable", "grade": "67", "download_url": download_url, "mode": "honor"} self.assertEqual( _cert_info(user, course, cert_status, course_mode), { "status": "ready", "show_disabled_download_button": False, "show_download_url": True, "download_url": download_url, "show_survey_button": True, "survey_url": survey_url, "grade": "67", "mode": "honor", "linked_in_url": None, "can_unenroll": False, }, ) cert_status = {"status": "notpassing", "grade": "67", "download_url": download_url, "mode": "honor"} self.assertEqual( _cert_info(user, course, cert_status, course_mode), { "status": "notpassing", "show_disabled_download_button": False, "show_download_url": False, "show_survey_button": True, "survey_url": survey_url, "grade": "67", "mode": "honor", "linked_in_url": None, "can_unenroll": True, }, ) # Test a course that doesn't have a survey specified course2 = Mock(end_of_course_survey_url=None, id=CourseLocator(org="a", course="b", run="c")) cert_status = {"status": "notpassing", "grade": "67", "download_url": download_url, "mode": "honor"} self.assertEqual( _cert_info(user, course2, cert_status, course_mode), { "status": "notpassing", "show_disabled_download_button": False, "show_download_url": False, "show_survey_button": False, "grade": "67", "mode": "honor", "linked_in_url": None, "can_unenroll": True, }, ) # test when the display is unavailable or notpassing, we get the correct results out course2.certificates_display_behavior = "early_no_info" cert_status = {"status": "unavailable"} self.assertEqual(_cert_info(user, course2, cert_status, course_mode), {}) cert_status = {"status": "notpassing", "grade": "67", "download_url": download_url, "mode": "honor"} self.assertEqual(_cert_info(user, course2, cert_status, course_mode), {})