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

feat: add verify_uuid to response of CertificatesListView #35760

Merged
merged 2 commits into from
Nov 18, 2024
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
1 change: 1 addition & 0 deletions lms/djangoapps/certificates/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def _format_certificate_for_user(username, cert):
if cert.status == CertificateStatuses.downloadable
else None
),
"uuid": cert.verify_uuid,
}

return None
Expand Down
35 changes: 24 additions & 11 deletions lms/djangoapps/certificates/apis/v0/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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):
"""
Expand All @@ -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)
Expand All @@ -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):
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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]
1 change: 1 addition & 0 deletions lms/djangoapps/certificates/apis/v0/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Loading