diff --git a/openedx/core/djangoapps/programs/tasks.py b/openedx/core/djangoapps/programs/tasks.py index 316e15c4a41dbc2b9a5fad3c9faf719ffba8399b..869d73f3dc8f9249d8b7917fb52665c64426ecc5 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 832c5478196f4c07e0ccd562660dfd4322c8c143..5a6f9869ce81936fa9d0dec9cfe7fcc183f5f727 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,