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

fix: 500 error on invalid user #304

Merged
merged 1 commit into from
Aug 9, 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
12 changes: 11 additions & 1 deletion edx_exams/apps/api/v1/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1961,7 +1961,7 @@ def test_post_invalid_field_value(self):
response = self.request_api('post', self.user, self.exam.course_id, data=request_data)
self.assertEqual(response.status_code, 400)

def test_post_invalid_missing_user(self):
def test_post_missing_user(self):
"""
Test that 400 response is returned if serializer is invalid due to missing required field
"""
Expand All @@ -1971,6 +1971,16 @@ def test_post_invalid_missing_user(self):
response = self.request_api('post', self.user, self.exam.course_id, data=request_data)
self.assertEqual(response.status_code, 400)

def test_post_invalid_user(self):
"""
Test that 400 response is returned if a username/email does not exist
"""
request_data = [
{'exam_id': self.exam.id, 'username': 'junk', 'extra_time_mins': 45},
]
response = self.request_api('post', self.user, self.exam.course_id, data=request_data)
self.assertEqual(response.status_code, 400)

def test_post_unauthorized_course(self):
"""
Test that an error is returned when atttempting to create an allowance for
Expand Down
5 changes: 5 additions & 0 deletions edx_exams/apps/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,11 @@ def post(self, request, course_id):
status=status.HTTP_400_BAD_REQUEST,
data={'detail': 'Exam does not exist'}
)
except User.DoesNotExist:
return Response(
status=status.HTTP_400_BAD_REQUEST,
data={'detail': 'Learner with username/email not found'}
)

StudentAllowance.bulk_create_or_update(allowance_objects)

Expand Down
Loading