Skip to content

Commit 815bb05

Browse files
committed
fix: fix unit test failures
1 parent 041c789 commit 815bb05

2 files changed

Lines changed: 21 additions & 10 deletions

File tree

submissions/tests/test_admin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def test_get_readonly_fields_new_object(self):
233233
readonly_fields = self.admin.get_readonly_fields(request, None)
234234

235235
# Should only include default readonly fields
236-
expected_readonly = ['submission', 'pullkey', 'status_time', 'created_at']
236+
expected_readonly = ['submission', 'pullkey', 'queue_key', 'status_time', 'created_at']
237237
self.assertEqual(readonly_fields, expected_readonly)
238238

239239
def test_has_change_permission(self):

submissions/tests/test_viewsets.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from submissions.permissions import IsXQueueUser
2222
from submissions.tests.factories import ExternalGraderDetailFactory, SubmissionFactory
2323
from submissions.views.xqueue import XQueueViewSet
24-
24+
from submissions.views.xqueue import MAX_SCORE_UPDATE_RETRIES
2525
User = get_user_model()
2626

2727

@@ -256,17 +256,21 @@ def test_put_result_set_score_failure(self):
256256
self.assertEqual(self.external_grader.num_failures, 1)
257257
self.assertEqual(self.external_grader.status, 'retry')
258258

259-
def test_put_result_set_score_fail_30_times(self):
259+
def test_put_result_set_score_fail_multiple_times(self):
260260
"""
261-
Test put_result handling when set_score by intentionally failing 30 times.
261+
Test put_result handling when set_score by intentionally failing multiple times.
262262
"""
263263
self.client.login(username='testuser', password='testpass')
264264
response = self.client.post(self.url_status)
265265
self.assertEqual(response.status_code, status.HTTP_200_OK)
266266

267-
for each in range(31):
267+
for each in range(MAX_SCORE_UPDATE_RETRIES+1):
268268
with patch('submissions.views.xqueue.set_score') as mock_set_score:
269269
mock_set_score.side_effect = Exception('Test error') # Make it actually fail
270+
# Ensure the external grader is in the right state for pulling
271+
# If it's failed, we need to reset it to pending first, then to pulled
272+
if self.external_grader.status == 'failed':
273+
self.external_grader.update_status('pending')
270274
self.external_grader.update_status('pulled')
271275
payload = {
272276
'xqueue_header': json.dumps({
@@ -309,9 +313,17 @@ def test_put_result_success(self, mock_log):
309313
mock_set_score.return_value = True
310314
response = self.client.post(self.url_put_result, payload, format='json')
311315

316+
submission_context = {
317+
'submission_id': self.submission.id,
318+
'course_id': self.submission.student_item.course_id,
319+
'user_id': self.submission.student_item.student_id,
320+
'item_id': self.submission.student_item.item_id,
321+
'queue_name': self.external_grader.queue_name,
322+
'queue_key': self.external_grader.queue_key,
323+
}
312324
mock_log.info.assert_any_call(
313-
"Successfully updated submission score for submission %s",
314-
self.submission.id
325+
"Successfully updated submission %(submission_id)s for user %(user_id)s",
326+
submission_context
315327
)
316328

317329
response_data = json.loads(response.content)
@@ -470,7 +482,6 @@ def test_get_submission_value_error(self, mock_get_files):
470482

471483
response = self.client.get(self.get_submission_url, {'queue_name': queue_name})
472484

473-
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
485+
self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
474486
self.assertEqual(response.data['return_code'], 1)
475-
self.assertIn("Error processing submission", response.data['content'])
476-
self.assertIn("File processing error", response.data['content'])
487+
self.assertIn("Unable to serialize submission payload", response.data['content'])

0 commit comments

Comments
 (0)