feat: converting existing api to drf base api. (#35039)

Adding generic permission class. Added standard authentication classes.
This commit is contained in:
Awais Qureshi
2024-07-30 13:18:49 +05:00
committed by GitHub
parent 085a2f5815
commit 39dd3c002b
4 changed files with 111 additions and 26 deletions

View File

@@ -2945,7 +2945,37 @@ class TestInstructorAPILevelsDataDump(SharedModuleStoreTestCase, LoginEnrollment
response = self.client.post(url, data)
assert response.status_code == 200
res_json = json.loads(response.content.decode('utf-8'))
assert 'progress_url' in res_json
expected_data = {
'course_id': str(self.course.id),
'progress_url': f'/courses/{self.course.id}/progress/{self.students[0].id}/'
}
for key, value in expected_data.items():
self.assertIn(key, res_json)
self.assertEqual(res_json[key], value)
def test_get_student_progress_url_response_headers(self):
"""
Test that the progress_url endpoint returns the correct headers.
"""
url = reverse('get_student_progress_url', kwargs={'course_id': str(self.course.id)})
data = {'unique_student_identifier': self.students[0].email}
response = self.client.post(url, data)
assert response.status_code == 200
expected_headers = {
'Allow': 'POST, OPTIONS', # drf view brings this key.
'Cache-Control': 'no-cache, no-store, must-revalidate',
'Content-Language': 'en',
'Content-Length': str(len(response.content.decode('utf-8'))),
'Content-Type': 'application/json',
'Vary': 'Cookie, Accept-Language, origin',
'X-Frame-Options': 'DENY'
}
for key, value in expected_headers.items():
self.assertIn(key, response.headers)
self.assertEqual(response.headers[key], value)
def test_get_student_progress_url_from_uname(self):
""" Test that progress_url is in the successful response. """
@@ -2955,6 +2985,14 @@ class TestInstructorAPILevelsDataDump(SharedModuleStoreTestCase, LoginEnrollment
assert response.status_code == 200
res_json = json.loads(response.content.decode('utf-8'))
assert 'progress_url' in res_json
expected_data = {
'course_id': str(self.course.id),
'progress_url': f'/courses/{self.course.id}/progress/{self.students[0].id}/'
}
for key, value in expected_data.items():
self.assertIn(key, res_json)
self.assertEqual(res_json[key], value)
def test_get_student_progress_url_noparams(self):
""" Test that the endpoint 404's without the required query params. """
@@ -2968,6 +3006,17 @@ class TestInstructorAPILevelsDataDump(SharedModuleStoreTestCase, LoginEnrollment
response = self.client.post(url)
assert response.status_code == 400
def test_get_student_progress_url_without_permissions(self):
""" Test that progress_url returns 403 without credentials. """
# removed both roles from courses for instructor
CourseDataResearcherRole(self.course.id).remove_users(self.instructor)
CourseInstructorRole(self.course.id).remove_users(self.instructor)
url = reverse('get_student_progress_url', kwargs={'course_id': str(self.course.id)})
data = {'unique_student_identifier': self.students[0].email}
response = self.client.post(url, data)
assert response.status_code == 403
class TestInstructorAPIRegradeTask(SharedModuleStoreTestCase, LoginEnrollmentTestCase):
"""