|
21 | 21 | from submissions.permissions import IsXQueueUser |
22 | 22 | from submissions.tests.factories import ExternalGraderDetailFactory, SubmissionFactory |
23 | 23 | from submissions.views.xqueue import XQueueViewSet |
24 | | - |
| 24 | +from submissions.views.xqueue import MAX_SCORE_UPDATE_RETRIES |
25 | 25 | User = get_user_model() |
26 | 26 |
|
27 | 27 |
|
@@ -256,17 +256,21 @@ def test_put_result_set_score_failure(self): |
256 | 256 | self.assertEqual(self.external_grader.num_failures, 1) |
257 | 257 | self.assertEqual(self.external_grader.status, 'retry') |
258 | 258 |
|
259 | | - def test_put_result_set_score_fail_30_times(self): |
| 259 | + def test_put_result_set_score_fail_multiple_times(self): |
260 | 260 | """ |
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. |
262 | 262 | """ |
263 | 263 | self.client.login(username='testuser', password='testpass') |
264 | 264 | response = self.client.post(self.url_status) |
265 | 265 | self.assertEqual(response.status_code, status.HTTP_200_OK) |
266 | 266 |
|
267 | | - for each in range(31): |
| 267 | + for each in range(MAX_SCORE_UPDATE_RETRIES+1): |
268 | 268 | with patch('submissions.views.xqueue.set_score') as mock_set_score: |
269 | 269 | 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') |
270 | 274 | self.external_grader.update_status('pulled') |
271 | 275 | payload = { |
272 | 276 | 'xqueue_header': json.dumps({ |
@@ -309,9 +313,17 @@ def test_put_result_success(self, mock_log): |
309 | 313 | mock_set_score.return_value = True |
310 | 314 | response = self.client.post(self.url_put_result, payload, format='json') |
311 | 315 |
|
| 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 | + } |
312 | 324 | 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 |
315 | 327 | ) |
316 | 328 |
|
317 | 329 | response_data = json.loads(response.content) |
@@ -470,7 +482,6 @@ def test_get_submission_value_error(self, mock_get_files): |
470 | 482 |
|
471 | 483 | response = self.client.get(self.get_submission_url, {'queue_name': queue_name}) |
472 | 484 |
|
473 | | - self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) |
| 485 | + self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR) |
474 | 486 | 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