Skip to content

Commit

Permalink
fix: 500 error on invalid user
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharis278 committed Aug 9, 2024
1 parent 827cfff commit fe14669
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
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

0 comments on commit fe14669

Please sign in to comment.