From 2760eeba6e89da62a366a32fe024956fd1176ac8 Mon Sep 17 00:00:00 2001 From: rabiaiftikhar Date: Fri, 25 May 2018 22:57:35 +0500 Subject: [PATCH] EDUCATOR-2927 certificate eligible column will appear with value N for audit-passing learners in grade report --- lms/djangoapps/certificates/models.py | 8 +++++- lms/djangoapps/certificates/tests/tests.py | 23 +++++++++++++++- .../tests/test_tasks_helper.py | 27 ++++++++++++++----- 3 files changed, 49 insertions(+), 9 deletions(-) diff --git a/lms/djangoapps/certificates/models.py b/lms/djangoapps/certificates/models.py index 09c53c69fb..0ac76b0d20 100644 --- a/lms/djangoapps/certificates/models.py +++ b/lms/djangoapps/certificates/models.py @@ -65,6 +65,7 @@ from opaque_keys.edx.django.models import CourseKeyField from badges.events.course_complete import course_badge_check from badges.events.course_meta import completion_check, course_group_check +from course_modes.models import CourseMode from lms.djangoapps.instructor_task.models import InstructorTask from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.signals.signals import COURSE_CERT_AWARDED @@ -568,13 +569,18 @@ def certificate_info_for_user(user, course_id, grade, user_is_whitelisted, user_ """ Returns the certificate info for a user for grade report. """ + from student.models import CourseEnrollment + certificate_is_delivered = 'N' certificate_type = 'N/A' status = certificate_status(user_certificate) certificate_generated = status['status'] == CertificateStatuses.downloadable can_have_certificate = CourseOverview.get_from_id(course_id).may_certify() + enrollment_mode, __ = CourseEnrollment.enrollment_mode_for_user(user, course_id) + mode_is_verified = enrollment_mode in CourseMode.VERIFIED_MODES + user_is_verified = grade is not None and mode_is_verified - eligible_for_certificate = 'Y' if (user_is_whitelisted or grade is not None or certificate_generated) \ + eligible_for_certificate = 'Y' if (user_is_whitelisted or user_is_verified or certificate_generated) \ and user.profile.allow_certificate else 'N' if certificate_generated and can_have_certificate: diff --git a/lms/djangoapps/certificates/tests/tests.py b/lms/djangoapps/certificates/tests/tests.py index 6698153f99..ca2bbf4f36 100644 --- a/lms/djangoapps/certificates/tests/tests.py +++ b/lms/djangoapps/certificates/tests/tests.py @@ -17,6 +17,7 @@ from lms.djangoapps.certificates.models import ( certificate_status_for_student ) from lms.djangoapps.certificates.tests.factories import GeneratedCertificateFactory +from student.models import CourseEnrollment from student.tests.factories import CourseEnrollmentFactory, UserFactory from util.milestones_helpers import milestones_achieved_by_user, set_prerequisite_courses from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase @@ -58,7 +59,7 @@ class CertificatesModelTest(ModuleStoreTestCase, MilestonesTestCaseMixin): @data( {'allow_certificate': False, 'whitelisted': False, 'grade': None, 'output': ['N', 'N', 'N/A']}, {'allow_certificate': True, 'whitelisted': True, 'grade': None, 'output': ['Y', 'N', 'N/A']}, - {'allow_certificate': True, 'whitelisted': False, 'grade': 0.9, 'output': ['Y', 'N', 'N/A']}, + {'allow_certificate': True, 'whitelisted': False, 'grade': 0.9, 'output': ['N', 'N', 'N/A']}, {'allow_certificate': False, 'whitelisted': True, 'grade': 0.8, 'output': ['N', 'N', 'N/A']}, {'allow_certificate': False, 'whitelisted': None, 'grade': 0.8, 'output': ['N', 'N', 'N/A']} ) @@ -133,6 +134,26 @@ class CertificatesModelTest(ModuleStoreTestCase, MilestonesTestCaseMixin): ) self.assertEqual(certificate_info, output) + @unpack + @data( + {'allow_certificate': True, 'whitelisted': False, 'grade': 0.8, 'mode': 'audit', 'output': ['N', 'N', 'N/A']}, + {'allow_certificate': True, 'whitelisted': True, 'grade': 0.8, 'mode': 'audit', 'output': ['Y', 'N', 'N/A']}, + {'allow_certificate': True, 'whitelisted': False, 'grade': 0.8, 'mode': 'verified', 'output': ['Y', 'N', 'N/A']} + ) + def test_certificate_info_for_user_with_course_modes(self, allow_certificate, whitelisted, grade, mode, output): + """ + Verify that certificate_info_for_user works with course modes. + """ + user = UserFactory.create() + user.profile.allow_certificate = allow_certificate + user.profile.save() + _ = CourseEnrollment.enroll(user, self.instructor_paced_course.id, mode) + certificate_info = certificate_info_for_user( + user, self.instructor_paced_course.id, grade, + whitelisted, user_certificate=None + ) + self.assertEqual(certificate_info, output) + def test_course_ids_with_certs_for_user(self): # Create one user with certs and one without student_no_certs = UserFactory() diff --git a/lms/djangoapps/instructor_task/tests/test_tasks_helper.py b/lms/djangoapps/instructor_task/tests/test_tasks_helper.py index be2a0feb47..5efde29c06 100644 --- a/lms/djangoapps/instructor_task/tests/test_tasks_helper.py +++ b/lms/djangoapps/instructor_task/tests/test_tasks_helper.py @@ -339,29 +339,42 @@ class TestInstructorGradeReport(InstructorGradeReportTestCase): "N" in the report. Also confirms that a persisted passing grade will result in a Certificate Eligibility - of "Y." + of "Y" incase of verified learners and "N" incase of audit laerners. """ course = CourseFactory.create() - user = CourseEnrollment.enroll(UserFactory.create(), course.id) - self._verify_cell_data_for_user(user.username, course.id, 'Certificate Eligible', 'N', num_rows=1) + audit_user = CourseEnrollment.enroll(UserFactory.create(), course.id) + self._verify_cell_data_for_user(audit_user.username, course.id, 'Certificate Eligible', 'N', num_rows=1) grading_policy_hash = GradesTransformer.grading_policy_hash(course) PersistentCourseGrade.update_or_create( - user_id=user.user_id, + user_id=audit_user.user_id, course_id=course.id, passed=False, percent_grade=0.0, grading_policy_hash=grading_policy_hash, ) - self._verify_cell_data_for_user(user.username, course.id, 'Certificate Eligible', 'N', num_rows=1) + self._verify_cell_data_for_user(audit_user.username, course.id, 'Certificate Eligible', 'N', num_rows=1) PersistentCourseGrade.update_or_create( - user_id=user.user_id, + user_id=audit_user.user_id, course_id=course.id, passed=True, percent_grade=0.8, letter_grade="pass", grading_policy_hash=grading_policy_hash, ) - self._verify_cell_data_for_user(user.username, course.id, 'Certificate Eligible', 'Y', num_rows=1) + # verifies that audit passing learner is not eligible for certificate + self._verify_cell_data_for_user(audit_user.username, course.id, 'Certificate Eligible', 'N', num_rows=1) + + verified_user = CourseEnrollment.enroll(UserFactory.create(), course.id, 'verified') + PersistentCourseGrade.update_or_create( + user_id=verified_user.user_id, + course_id=course.id, + passed=True, + percent_grade=0.8, + letter_grade="pass", + grading_policy_hash=grading_policy_hash, + ) + # verifies that verified passing learner is eligible for certificate + self._verify_cell_data_for_user(verified_user.username, course.id, 'Certificate Eligible', 'Y', num_rows=2) @ddt.data( (ModuleStoreEnum.Type.mongo, 4),