Skip to content

Commit

Permalink
feat!: upgrading api to DRF.
Browse files Browse the repository at this point in the history
  • Loading branch information
awais786 committed Nov 27, 2024
1 parent 9274852 commit 7505ec7
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 143 deletions.
34 changes: 31 additions & 3 deletions lms/djangoapps/instructor/tests/test_certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,7 @@ def test_certificate_exception_missing_username_and_email_error(self):
assert not res_json['success']

# Assert Error Message
assert res_json['message'] ==\
'Student username/email field is required and can not be empty.' \
' Kindly fill in username/email and then press "Add to Exception List" button.'
assert res_json['message'] == {'user': ['This field may not be blank.']}

def test_certificate_exception_duplicate_user_error(self):
"""
Expand Down Expand Up @@ -604,6 +602,34 @@ def test_certificate_exception_removed_successfully(self):
# Verify that certificate exception does not exist
assert not certs_api.is_on_allowlist(self.user2, self.course.id)

def test_certificate_exception_removed_successfully_form_url(self):
"""
In case of deletion front-end is sending content-type x-www-form-urlencoded.
Just to handle that some logic added in api and this test is for that part.
Test certificates exception removal api endpoint returns success status
when called with valid course key and certificate exception id
"""
GeneratedCertificateFactory.create(
user=self.user2,
course_id=self.course.id,
status=CertificateStatuses.downloadable,
grade='1.0'
)
# Verify that certificate exception exists
assert certs_api.is_on_allowlist(self.user2, self.course.id)

response = self.client.post(
self.url,
data=json.dumps(self.certificate_exception_in_db),
content_type='application/x-www-form-urlencoded',
REQUEST_METHOD='DELETE'
)
# Assert successful request processing
assert response.status_code == 204

# Verify that certificate exception does not exist
assert not certs_api.is_on_allowlist(self.user2, self.course.id)

def test_remove_certificate_exception_invalid_request_error(self):
"""
Test certificates exception removal api endpoint returns error
Expand Down Expand Up @@ -1104,6 +1130,7 @@ def test_invalid_user_name_error(self):
# Assert 400 status code in response
assert response.status_code == 400
res_json = json.loads(response.content.decode('utf-8'))

# Assert Error Message
assert res_json['message'] == f'{invalid_user} does not exist in the LMS. Please check your spelling and retry.'

Expand All @@ -1122,6 +1149,7 @@ def test_no_generated_certificate_error(self):
# Assert 400 status code in response
assert response.status_code == 400
res_json = json.loads(response.content.decode('utf-8'))

# Assert Error Message
assert res_json['message'] == f'The student {self.enrolled_user_2.username} does not have certificate for the course {self.course.number}. Kindly verify student username/email and the selected course are correct and try again.' # pylint: disable=line-too-long

Expand Down
Loading

0 comments on commit 7505ec7

Please sign in to comment.