Skip to content

Commit

Permalink
test: updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eemaanamir committed Nov 4, 2024
1 parent 9a5d44f commit ba4bdbb
Showing 1 changed file with 24 additions and 11 deletions.
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]

0 comments on commit ba4bdbb

Please sign in to comment.