From b38758472a50010bb63a91e8f452336e2a983db9 Mon Sep 17 00:00:00 2001 From: eemaanamir Date: Sun, 3 Nov 2024 23:10:57 +0500 Subject: [PATCH 1/2] feat: add verify_uuid to response of CertificatesListView --- lms/djangoapps/certificates/api.py | 1 + lms/djangoapps/certificates/apis/v0/views.py | 1 + 2 files changed, 2 insertions(+) diff --git a/lms/djangoapps/certificates/api.py b/lms/djangoapps/certificates/api.py index bd7db8662e70..895822f58824 100644 --- a/lms/djangoapps/certificates/api.py +++ b/lms/djangoapps/certificates/api.py @@ -82,6 +82,7 @@ def _format_certificate_for_user(username, cert): if cert.status == CertificateStatuses.downloadable else None ), + "uuid": cert.verify_uuid, } return None diff --git a/lms/djangoapps/certificates/apis/v0/views.py b/lms/djangoapps/certificates/apis/v0/views.py index 121f37fe72d0..aa6512535b84 100644 --- a/lms/djangoapps/certificates/apis/v0/views.py +++ b/lms/djangoapps/certificates/apis/v0/views.py @@ -244,6 +244,7 @@ def get(self, request, username): 'is_passing': user_cert.get('is_passing'), 'download_url': user_cert.get('download_url'), 'grade': user_cert.get('grade'), + 'uuid': user_cert.get('uuid'), }) return Response(user_certs) From b691ce689d95303fdb59dbfff6150b49fb7fba32 Mon Sep 17 00:00:00 2001 From: eemaanamir Date: Sun, 3 Nov 2024 23:31:14 +0500 Subject: [PATCH 2/2] test: updated tests --- .../certificates/apis/v0/tests/test_views.py | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/lms/djangoapps/certificates/apis/v0/tests/test_views.py b/lms/djangoapps/certificates/apis/v0/tests/test_views.py index efff97f54d5a..c8ef620dd2db 100644 --- a/lms/djangoapps/certificates/apis/v0/tests/test_views.py +++ b/lms/djangoapps/certificates/apis/v0/tests/test_views.py @@ -173,17 +173,22 @@ def get_url(self, username): def assert_success_response_for_student(self, response, download_url='www.google.com'): """ This method is required by AuthAndScopesTestMixin. """ - assert response.data ==\ - [{'username': self.student.username, - 'course_id': str(self.course.id), - 'course_display_name': self.course.display_name, - 'course_organization': self.course.org, - 'certificate_type': CourseMode.VERIFIED, - 'created_date': self.now, - 'modified_date': self.now, - 'status': CertificateStatuses.downloadable, - 'is_passing': True, - 'download_url': download_url, 'grade': '0.88'}] + assert response.data == [ + { + 'username': self.student.username, + 'course_id': str(self.course.id), + 'course_display_name': self.course.display_name, + 'course_organization': self.course.org, + 'certificate_type': CourseMode.VERIFIED, + 'created_date': self.now, + 'modified_date': self.now, + 'status': CertificateStatuses.downloadable, + 'is_passing': True, + 'download_url': download_url, + 'grade': '0.88', + 'uuid': str(self.cert.verify_uuid) + } + ] @patch('edx_rest_framework_extensions.permissions.log') @ddt.data(*list(AuthType)) @@ -212,6 +217,7 @@ def test_another_user_with_certs_shared_public(self, auth_type): assert resp.status_code == status.HTTP_200_OK assert len(resp.data) == 1 + assert 'uuid' in resp.data[0] def test_owner_can_access_its_certs(self): """ @@ -227,6 +233,7 @@ def test_owner_can_access_its_certs(self): resp = self.get_response(AuthType.session, requesting_user=self.student) assert resp.status_code == status.HTTP_200_OK + assert 'uuid' in resp.data[0] # verifies that other than owner cert list api is not accessible resp = self.get_response(AuthType.session, requesting_user=self.other_student) @@ -246,12 +253,15 @@ def test_public_profile_certs_is_accessible(self): resp = self.get_response(AuthType.session, requesting_user=self.student) assert resp.status_code == status.HTTP_200_OK + assert 'uuid' in resp.data[0] resp = self.get_response(AuthType.session, requesting_user=self.other_student) assert resp.status_code == status.HTTP_200_OK + assert 'uuid' in resp.data[0] resp = self.get_response(AuthType.session, requesting_user=self.global_staff) assert resp.status_code == status.HTTP_200_OK + assert 'uuid' in resp.data[0] @ddt.data(*list(AuthType)) def test_another_user_with_certs_shared_custom(self, auth_type): @@ -276,6 +286,7 @@ def test_another_user_with_certs_shared_custom(self, auth_type): assert resp.status_code == status.HTTP_200_OK assert len(resp.data) == 1 + assert 'uuid' in resp.data[0] @patch('edx_rest_framework_extensions.permissions.log') @ddt.data(*JWT_AUTH_TYPES) @@ -290,6 +301,7 @@ def test_jwt_on_behalf_of_other_user(self, auth_type, mock_log): else: assert resp.status_code == status.HTTP_200_OK assert len(resp.data) == 1 + assert 'uuid' in resp.data[0] @patch('edx_rest_framework_extensions.permissions.log') @ddt.data(*JWT_AUTH_TYPES) @@ -422,3 +434,4 @@ def test_certificate_without_course(self, mock_get_course_run_details): assert response.status_code == status.HTTP_200_OK self.assertContains(response, cert_for_deleted_course.download_url) self.assertContains(response, expected_course_name) + assert 'uuid' in response.data[0]