|
@@ 1036-1078 (lines=43) @@
|
| 1033 |
|
'report it to InjectTool team') |
| 1034 |
|
}, 1) |
| 1035 |
|
|
| 1036 |
|
@patch('biosample.tasks.send_message_to_websocket') |
| 1037 |
|
@patch('asyncio.get_event_loop') |
| 1038 |
|
def test_error_in_draft_status(self, asyncio_mock, |
| 1039 |
|
send_message_to_websocket_mock): |
| 1040 |
|
tmp = asyncio_mock.return_value |
| 1041 |
|
tmp.run_until_complete = Mock() |
| 1042 |
|
# a still running submission |
| 1043 |
|
self.my_submission = Mock() |
| 1044 |
|
self.my_submission.name = "test-fetch" |
| 1045 |
|
self.my_submission.status = 'Draft' |
| 1046 |
|
|
| 1047 |
|
# assert task and mock methods called |
| 1048 |
|
self.common_tests(self.my_submission) |
| 1049 |
|
|
| 1050 |
|
# test email sent |
| 1051 |
|
self.assertEqual(len(mail.outbox), 1) |
| 1052 |
|
|
| 1053 |
|
# read email |
| 1054 |
|
email = mail.outbox[0] |
| 1055 |
|
|
| 1056 |
|
self.assertEqual( |
| 1057 |
|
"Error in biosample submission %s" % self.submission_obj_id, |
| 1058 |
|
email.subject) |
| 1059 |
|
|
| 1060 |
|
# check submission.state changed |
| 1061 |
|
self.submission_obj.refresh_from_db() |
| 1062 |
|
|
| 1063 |
|
self.assertEqual(self.submission_obj.status, ERROR) |
| 1064 |
|
self.assertIn( |
| 1065 |
|
"Biosample subission {} remained with the same status".format( |
| 1066 |
|
self.submission_obj), |
| 1067 |
|
self.submission_obj.message |
| 1068 |
|
) |
| 1069 |
|
|
| 1070 |
|
self.assertEqual(asyncio_mock.call_count, 1) |
| 1071 |
|
self.assertEqual(tmp.run_until_complete.call_count, 1) |
| 1072 |
|
self.assertEqual(send_message_to_websocket_mock.call_count, 1) |
| 1073 |
|
send_message_to_websocket_mock.assert_called_with( |
| 1074 |
|
{'message': 'Error', |
| 1075 |
|
'notification_message': ( |
| 1076 |
|
'Biosample subission Cryoweb ' |
| 1077 |
|
'(United Kingdom, test) remained with the ' |
| 1078 |
|
'same status for more than 5 days. Please ' |
| 1079 |
|
'report it to InjectTool team') |
| 1080 |
|
}, 1) |
| 1081 |
|
|
|
@@ 990-1032 (lines=43) @@
|
| 987 |
|
self.submission_obj.updated_at = testtime |
| 988 |
|
self.submission_obj.save() |
| 989 |
|
|
| 990 |
|
@patch('biosample.tasks.send_message_to_websocket') |
| 991 |
|
@patch('asyncio.get_event_loop') |
| 992 |
|
def test_error_in_submitted_status(self, asyncio_mock, |
| 993 |
|
send_message_to_websocket_mock): |
| 994 |
|
tmp = asyncio_mock.return_value |
| 995 |
|
tmp.run_until_complete = Mock() |
| 996 |
|
# a still running submission |
| 997 |
|
self.my_submission = Mock() |
| 998 |
|
self.my_submission.name = "test-fetch" |
| 999 |
|
self.my_submission.status = 'Submitted' |
| 1000 |
|
|
| 1001 |
|
# assert task and mock methods called |
| 1002 |
|
self.common_tests(self.my_submission) |
| 1003 |
|
|
| 1004 |
|
# test email sent |
| 1005 |
|
self.assertEqual(len(mail.outbox), 1) |
| 1006 |
|
|
| 1007 |
|
# read email |
| 1008 |
|
email = mail.outbox[0] |
| 1009 |
|
|
| 1010 |
|
self.assertEqual( |
| 1011 |
|
"Error in biosample submission %s" % self.submission_obj_id, |
| 1012 |
|
email.subject) |
| 1013 |
|
|
| 1014 |
|
# check submission.state changed |
| 1015 |
|
self.submission_obj.refresh_from_db() |
| 1016 |
|
|
| 1017 |
|
self.assertEqual(self.submission_obj.status, ERROR) |
| 1018 |
|
self.assertIn( |
| 1019 |
|
"Biosample subission {} remained with the same status".format( |
| 1020 |
|
self.submission_obj), |
| 1021 |
|
self.submission_obj.message |
| 1022 |
|
) |
| 1023 |
|
|
| 1024 |
|
self.assertEqual(asyncio_mock.call_count, 1) |
| 1025 |
|
self.assertEqual(tmp.run_until_complete.call_count, 1) |
| 1026 |
|
self.assertEqual(send_message_to_websocket_mock.call_count, 1) |
| 1027 |
|
send_message_to_websocket_mock.assert_called_with( |
| 1028 |
|
{'message': 'Error', |
| 1029 |
|
'notification_message': ( |
| 1030 |
|
'Biosample subission Cryoweb ' |
| 1031 |
|
'(United Kingdom, test) remained with the ' |
| 1032 |
|
'same status for more than 5 days. Please ' |
| 1033 |
|
'report it to InjectTool team') |
| 1034 |
|
}, 1) |
| 1035 |
|
|