Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly set certificate status for audit certs when regenerating. #11427

Merged
merged 1 commit into from
Feb 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lms/djangoapps/certificates/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,11 @@ def add_cert(self, student, course_id, course=None, forced_grade=None, template_

# If this user's enrollment is not eligible to receive a
# certificate, mark it as such for reporting and
# analytics. Only do this if the certificate is new -- we
# don't want to mark existing audit certs as ineligible.
if created and not is_eligible_for_certificate:
# analytics. Only do this if the certificate is new, or
# already marked as ineligible -- we don't want to mark
# existing audit certs as ineligible.
if (created or cert.status in (CertificateStatuses.audit_passing, CertificateStatuses.audit_notpassing)) \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Prefer using parens instead of \ for multiline conditionals

and not is_eligible_for_certificate:
cert.status = CertificateStatuses.audit_passing if passing else CertificateStatuses.audit_notpassing
cert.save()
LOGGER.info(
Expand Down
15 changes: 11 additions & 4 deletions lms/djangoapps/certificates/tests/test_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,14 @@ def test_add_cert_statuses(self, status, should_generate):
else:
self.assertFalse(mock_send.called)

def test_regen_audit_certs_eligibility(self):
@ddt.data(
(CertificateStatuses.downloadable, 'Pass', CertificateStatuses.generating),
(CertificateStatuses.audit_passing, 'Pass', CertificateStatuses.audit_passing),
(CertificateStatuses.audit_notpassing, 'Pass', CertificateStatuses.audit_passing),
(CertificateStatuses.audit_notpassing, None, CertificateStatuses.audit_notpassing),
)
@ddt.unpack
def test_regen_audit_certs_eligibility(self, status, grade, expected_status):
"""
Test that existing audit certificates remain eligible even if cert
generation is re-run.
Expand All @@ -221,19 +228,19 @@ def test_regen_audit_certs_eligibility(self):
user=self.user_2,
course_id=self.course.id,
grade='1.0',
status=CertificateStatuses.downloadable,
status=status,
mode=GeneratedCertificate.MODES.audit,
)

# Run grading/cert generation again
with patch('courseware.grades.grade', Mock(return_value={'grade': 'Pass', 'percent': 0.75})):
with patch('courseware.grades.grade', Mock(return_value={'grade': grade, 'percent': 0.75})):
with patch.object(XQueueInterface, 'send_to_queue') as mock_send:
mock_send.return_value = (0, None)
self.xqueue.add_cert(self.user_2, self.course.id)

self.assertEqual(
GeneratedCertificate.objects.get(user=self.user_2, course_id=self.course.id).status, # pylint: disable=no-member
CertificateStatuses.generating
expected_status
)


Expand Down