From a28f54bf4aa688cdc6c8155d5090023c1dd81117 Mon Sep 17 00:00:00 2001 From: "Albert (AJ) St. Aubin" <astaubin@edx.org> Date: Tue, 7 Sep 2021 12:27:27 -0400 Subject: [PATCH] feat: Added lms_user_id and email to data sent to Credentials for Program certs [MICROBA-1466] --- openedx/core/djangoapps/programs/tasks.py | 12 +++++++----- openedx/core/djangoapps/programs/tests/test_tasks.py | 9 ++++++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/openedx/core/djangoapps/programs/tasks.py b/openedx/core/djangoapps/programs/tasks.py index 316e15c4a41..869d73f3dc8 100644 --- a/openedx/core/djangoapps/programs/tasks.py +++ b/openedx/core/djangoapps/programs/tasks.py @@ -91,15 +91,15 @@ def get_certified_programs(student): return certified_programs -def award_program_certificate(client, username, program_uuid, visible_date): +def award_program_certificate(client, user, program_uuid, visible_date): """ Issue a new certificate of completion to the given student for the given program. Args: client: credentials API client (EdxRestApiClient) - username: - The username of the student + user: + The student's user data program_uuid: uuid of the completed program visible_date: @@ -110,7 +110,9 @@ def award_program_certificate(client, username, program_uuid, visible_date): """ client.credentials.post({ - 'username': username, + 'username': user.username, + 'lms_user_id': user.id, + 'email': user.email, 'credential': { 'type': PROGRAM_CERTIFICATE, 'program_uuid': program_uuid @@ -231,7 +233,7 @@ def award_program_certificates(self, username): # lint-amnesty, pylint: disable visible_date = completed_programs[program_uuid] try: LOGGER.info(f"Visible date for user {username} : program {program_uuid} is {visible_date}") - award_program_certificate(credentials_client, username, program_uuid, visible_date) + award_program_certificate(credentials_client, student, program_uuid, visible_date) LOGGER.info(f"Awarded certificate for program {program_uuid} to user {username}") except exceptions.HttpNotFoundError: LOGGER.exception( diff --git a/openedx/core/djangoapps/programs/tests/test_tasks.py b/openedx/core/djangoapps/programs/tests/test_tasks.py index 832c5478196..5a6f9869ce8 100644 --- a/openedx/core/djangoapps/programs/tests/test_tasks.py +++ b/openedx/core/djangoapps/programs/tests/test_tasks.py @@ -87,7 +87,8 @@ class AwardProgramCertificateTestCase(TestCase): """ Ensure the correct API call gets made """ - test_username = 'test-username' + student = UserFactory(username='test-username', email='test-email@email.com') + test_client = EdxRestApiClient('http://test-server', jwt='test-token') httpretty.register_uri( @@ -95,10 +96,12 @@ class AwardProgramCertificateTestCase(TestCase): 'http://test-server/credentials/', ) - tasks.award_program_certificate(test_client, test_username, 123, datetime(2010, 5, 30)) + tasks.award_program_certificate(test_client, student, 123, datetime(2010, 5, 30)) expected_body = { - 'username': test_username, + 'username': student.username, + 'lms_user_id': student.id, + 'email': student.email, 'credential': { 'program_uuid': 123, 'type': tasks.PROGRAM_CERTIFICATE, -- GitLab