| @@ 30-70 (lines=41) @@ | ||
| 27 | # setting task |
|
| 28 | self.my_task = ImportCRBAnimTask() |
|
| 29 | ||
| 30 | @patch('crbanim.tasks.send_message_to_websocket') |
|
| 31 | @patch('asyncio.get_event_loop') |
|
| 32 | def test_on_failure(self, asyncio_mock, send_message_to_websocket_mock): |
|
| 33 | """Testing on failure methods""" |
|
| 34 | tmp = asyncio_mock.return_value |
|
| 35 | tmp.run_until_complete = Mock() |
|
| 36 | ||
| 37 | exc = Exception("Test") |
|
| 38 | task_id = "test_task_id" |
|
| 39 | args = [self.submission_id] |
|
| 40 | kwargs = {} |
|
| 41 | einfo = ExceptionInfo |
|
| 42 | ||
| 43 | # call on_failure method |
|
| 44 | self.my_task.on_failure(exc, task_id, args, kwargs, einfo) |
|
| 45 | ||
| 46 | # check submission status and message |
|
| 47 | submission = Submission.objects.get(pk=self.submission_id) |
|
| 48 | ||
| 49 | # check submission.state changed |
|
| 50 | self.assertEqual(submission.status, ERROR) |
|
| 51 | self.assertEqual( |
|
| 52 | submission.message, |
|
| 53 | "Error in CRBAnim loading: Test") |
|
| 54 | ||
| 55 | # test email sent |
|
| 56 | self.assertEqual(len(mail.outbox), 1) |
|
| 57 | ||
| 58 | # read email |
|
| 59 | email = mail.outbox[0] |
|
| 60 | ||
| 61 | self.assertEqual( |
|
| 62 | "Error in CRBAnim loading: %s" % self.submission_id, |
|
| 63 | email.subject) |
|
| 64 | ||
| 65 | self.assertEqual(asyncio_mock.call_count, 1) |
|
| 66 | self.assertEqual(tmp.run_until_complete.call_count, 1) |
|
| 67 | self.assertEqual(send_message_to_websocket_mock.call_count, 1) |
|
| 68 | send_message_to_websocket_mock.assert_called_with( |
|
| 69 | {'message': 'Error', |
|
| 70 | 'notification_message': 'Error in CRBAnim loading: Test'}, 1) |
|
| 71 | ||
| 72 | @patch("crbanim.tasks.upload_crbanim", return_value=True) |
|
| 73 | def test_import_from_crbanim(self, my_upload): |
|
| @@ 83-124 (lines=42) @@ | ||
| 80 | ||
| 81 | class ValidateSubmissionTest(ValidateSubmissionMixin, TestCase): |
|
| 82 | ||
| 83 | @patch('validation.tasks.send_message_to_websocket') |
|
| 84 | @patch('asyncio.get_event_loop') |
|
| 85 | def test_on_failure(self, asyncio_mock, send_message_to_websocket_mock): |
|
| 86 | """Testing on failure methods""" |
|
| 87 | ||
| 88 | tmp = asyncio_mock.return_value |
|
| 89 | tmp.run_until_complete = Mock() |
|
| 90 | ||
| 91 | exc = Exception("Test") |
|
| 92 | task_id = "test_task_id" |
|
| 93 | args = [self.submission_id] |
|
| 94 | kwargs = {} |
|
| 95 | einfo = ExceptionInfo |
|
| 96 | ||
| 97 | # call on_failure method |
|
| 98 | self.my_task.on_failure(exc, task_id, args, kwargs, einfo) |
|
| 99 | ||
| 100 | # check submission status and message |
|
| 101 | submission = Submission.objects.get(pk=self.submission_id) |
|
| 102 | ||
| 103 | # check submission.state changed |
|
| 104 | self.assertEqual(submission.status, ERROR) |
|
| 105 | self.assertEqual( |
|
| 106 | submission.message, |
|
| 107 | "Error in IMAGE Validation: Test") |
|
| 108 | ||
| 109 | # test email sent |
|
| 110 | self.assertEqual(len(mail.outbox), 1) |
|
| 111 | ||
| 112 | # read email |
|
| 113 | email = mail.outbox[0] |
|
| 114 | ||
| 115 | self.assertEqual( |
|
| 116 | "Error in IMAGE Validation: %s" % self.submission_id, |
|
| 117 | email.subject) |
|
| 118 | ||
| 119 | self.assertEqual(asyncio_mock.call_count, 1) |
|
| 120 | self.assertEqual(tmp.run_until_complete.call_count, 1) |
|
| 121 | self.assertEqual(send_message_to_websocket_mock.call_count, 1) |
|
| 122 | send_message_to_websocket_mock.assert_called_with( |
|
| 123 | {'message': 'Error', |
|
| 124 | 'notification_message': 'Error in IMAGE Validation: Test'}, 1) |
|
| 125 | ||
| 126 | @patch('crbanim.helpers.send_message_to_websocket') |
|
| 127 | @patch('asyncio.get_event_loop') |
|
| @@ 364-403 (lines=40) @@ | ||
| 361 | for sample in my_samples: |
|
| 362 | self.assertTrue(sample.patch.called) |
|
| 363 | ||
| 364 | @patch('biosample.tasks.send_message_to_websocket') |
|
| 365 | @patch('asyncio.get_event_loop') |
|
| 366 | def test_on_failure(self, asyncio_mock, send_message_to_websocket_mock): |
|
| 367 | """Testing on failure methods""" |
|
| 368 | tmp = asyncio_mock.return_value |
|
| 369 | tmp.run_until_complete = Mock() |
|
| 370 | ||
| 371 | exc = Exception("Test") |
|
| 372 | task_id = "test_task_id" |
|
| 373 | args = [self.submission_id] |
|
| 374 | kwargs = {} |
|
| 375 | einfo = ExceptionInfo |
|
| 376 | ||
| 377 | # call on_failure method |
|
| 378 | self.my_task.on_failure(exc, task_id, args, kwargs, einfo) |
|
| 379 | ||
| 380 | # check submission status and message |
|
| 381 | submission = Submission.objects.get(pk=self.submission_id) |
|
| 382 | ||
| 383 | # check submission.state changed |
|
| 384 | self.assertEqual(submission.status, ERROR) |
|
| 385 | self.assertEqual( |
|
| 386 | submission.message, |
|
| 387 | "Error in biosample submission: Test") |
|
| 388 | ||
| 389 | # test email sent |
|
| 390 | self.assertEqual(len(mail.outbox), 1) |
|
| 391 | ||
| 392 | # read email |
|
| 393 | email = mail.outbox[0] |
|
| 394 | ||
| 395 | self.assertEqual( |
|
| 396 | "Error in biosample submission %s" % self.submission_id, |
|
| 397 | email.subject) |
|
| 398 | self.assertEqual(asyncio_mock.call_count, 1) |
|
| 399 | self.assertEqual(tmp.run_until_complete.call_count, 1) |
|
| 400 | self.assertEqual(send_message_to_websocket_mock.call_count, 1) |
|
| 401 | send_message_to_websocket_mock.assert_called_with( |
|
| 402 | {'message': 'Error', |
|
| 403 | 'notification_message': 'Error in biosample submission: Test'}, 1) |
|
| 404 | ||
| 405 | @patch('biosample.tasks.send_message_to_websocket') |
|
| 406 | @patch('asyncio.get_event_loop') |
|