From e9cdc133a6e726dac6e9fd69d5986f46d3975e7f Mon Sep 17 00:00:00 2001 From: Clinton Blackburn Date: Fri, 26 May 2017 17:18:04 -0400 Subject: [PATCH] Updated programs detail page to always call Credentials API The programs detail page now always makes a call to the Credentials API to check for program credentials, regardless of whether the user has earned a course certificate. The course certificate constraint adds an additional burden to testing in exchange for slightly decreased load on the API. The cost outweighs the benefit given the limited traffic to this page. LEARNER-1103 --- .../djangoapps/programs/tests/test_utils.py | 14 ++++++++++---- openedx/core/djangoapps/programs/utils.py | 19 +++++++------------ 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/openedx/core/djangoapps/programs/tests/test_utils.py b/openedx/core/djangoapps/programs/tests/test_utils.py index f40513fbc0..5b244ee0cc 100644 --- a/openedx/core/djangoapps/programs/tests/test_utils.py +++ b/openedx/core/djangoapps/programs/tests/test_utils.py @@ -752,12 +752,18 @@ class TestGetCertificates(TestCase): def test_course_run_certificates_missing(self, mock_get_credentials): """ - Verify an empty list is returned when course run certificates are missing, - and that no attempt is made to retrieve program certificates. + Verify program certificates are retrieved even if the learner has not earned any course certificates. """ + expected = [{ + 'type': 'program', + 'title': self.program['title'], + 'url': self.program_certificate_url, + }] + mock_get_credentials.return_value = [{'certificate_url': self.program_certificate_url}] + certificates = get_certificates(self.user, self.program) - self.assertEqual(certificates, []) - self.assertFalse(mock_get_credentials.called) + self.assertTrue(mock_get_credentials.called) + self.assertEqual(certificates, expected) def test_program_certificate_missing(self, mock_get_credentials): """ diff --git a/openedx/core/djangoapps/programs/utils.py b/openedx/core/djangoapps/programs/utils.py index db88090ffe..44aecaf177 100644 --- a/openedx/core/djangoapps/programs/utils.py +++ b/openedx/core/djangoapps/programs/utils.py @@ -464,18 +464,13 @@ def get_certificates(user, extended_program): # We only want one certificate per course to be returned. break - # A user can only have earned a program certificate if they've earned certificates - # in associated course runs. If they haven't earned any course run certificates, - # they can't have earned a program certificate, and we can save a network call - # to the credentials service. - if certificates: - program_credentials = get_credentials(user, program_uuid=extended_program['uuid']) - if program_credentials: - certificates.append({ - 'type': 'program', - 'title': extended_program['title'], - 'url': program_credentials[0]['certificate_url'], - }) + program_credentials = get_credentials(user, program_uuid=extended_program['uuid']) + if program_credentials: + certificates.append({ + 'type': 'program', + 'title': extended_program['title'], + 'url': program_credentials[0]['certificate_url'], + }) return certificates