Skip to content
Snippets Groups Projects
Commit 9aca0f56 authored by Matthew Andrew's avatar Matthew Andrew
Browse files

Corrected failing unit tests

parent ac1711bf
No related branches found
No related tags found
No related merge requests found
......@@ -100,7 +100,7 @@ public:
const std::string name = "My testing application name";
const Mantid::Types::Core::time_duration upTime(5, 0, 7, 0);
TestableErrorReporter errorService(name, upTime, "0", true, "name", "email",
"textBox", "fileHash");
"textBox", "stacktrace");
const std::string message = errorService.generateErrorMessage();
::Json::Reader reader;
......@@ -111,7 +111,7 @@ public:
"ParaView", "application", "host", "mantidSha1", "mantidVersion",
"osArch", "osName", "osReadable", "osVersion", "uid",
"facility", "upTime", "exitCode", "textBox", "name",
"email", "fileHash"};
"email", "stacktrace"};
for (auto expectedMember : expectedMembers) {
TSM_ASSERT(expectedMember + " not found",
std::find(members.begin(), members.end(), expectedMember) !=
......@@ -124,14 +124,14 @@ public:
TS_ASSERT_EQUALS(root["name"].asString(), "name");
TS_ASSERT_EQUALS(root["email"].asString(), "email");
TS_ASSERT_EQUALS(root["textBox"].asString(), "textBox");
TS_ASSERT_EQUALS(root["fileHash"].asString(), "fileHash");
TS_ASSERT_EQUALS(root["stacktrace"].asString(), "stacktrace");
}
void test_errorMessageWithNoShareAndRecoveryFileHash() {
const std::string name = "My testing application name";
const Mantid::Types::Core::time_duration upTime(5, 0, 7, 0);
TestableErrorReporter errorService(name, upTime, "0", false, "name",
"email", "textBox", "fileHash");
"email", "textBox", "stacktrace");
const std::string message = errorService.generateErrorMessage();
::Json::Reader reader;
......@@ -142,7 +142,7 @@ public:
"ParaView", "application", "host", "mantidSha1", "mantidVersion",
"osArch", "osName", "osReadable", "osVersion", "uid",
"facility", "upTime", "exitCode", "textBox", "name",
"email", "fileHash"};
"email", "stacktrace"};
for (auto expectedMember : expectedMembers) {
TSM_ASSERT(expectedMember + " not found",
std::find(members.begin(), members.end(), expectedMember) !=
......@@ -155,7 +155,7 @@ public:
TS_ASSERT_EQUALS(root["name"].asString(), "");
TS_ASSERT_EQUALS(root["email"].asString(), "");
TS_ASSERT_EQUALS(root["textBox"].asString(), "");
TS_ASSERT_EQUALS(root["fileHash"].asString(), "");
TS_ASSERT_EQUALS(root["stacktrace"].asString(), "");
}
};
......
......@@ -24,11 +24,6 @@ class ErrorReportPresenterTest(unittest.TestCase):
self.errorreport_mock = errorreport_patcher.start()
self.errorreport_mock.return_value = self.errorreport_mock_instance
zip_recovery_patcher = mock.patch('ErrorReporter.error_report_presenter.zip_recovery_directory')
self.addCleanup(zip_recovery_patcher.stop)
self.zip_recovery_mock = zip_recovery_patcher.start()
self.zip_recovery_mock.return_value = ('zipped_file', 'file_hash')
self.view = mock.MagicMock()
self.exit_code = 255
self.error_report_presenter = ErrorReporterPresenter(self.view, self.exit_code)
......@@ -55,32 +50,28 @@ class ErrorReportPresenterTest(unittest.TestCase):
def test_send_error_report_to_server_calls_ErrorReport_correctly(self):
name = 'John Smith'
email = 'john.smith@email.com'
file_hash = '91df56ab7a2de7264052a7a7125dcfa18b4f59de'
text_box = 'details of error'
uptime = 'time_string'
self.errorreport_mock_instance.sendErrorReport.return_value = 201
self.error_report_presenter._send_report_to_server(False, name=name, email=email,
file_hash=file_hash,
uptime=uptime, text_box=text_box)
self.errorreport_mock.assert_called_once_with('mantidplot', uptime, self.exit_code, False, name,
email, text_box, file_hash)
email, text_box, '')
self.errorreport_mock_instance.sendErrorReport.assert_called_once_with()
def test_send_error_report_to_server_calls_ErrorReport_correctly_and_triggers_view_upon_failure(self):
name = 'John Smith'
email = 'john.smith@email.com'
file_hash = '91df56ab7a2de7264052a7a7125dcfa18b4f59de'
uptime = 'time_string'
text_box = 'details of error'
self.errorreport_mock_instance.sendErrorReport.return_value = 500
self.error_report_presenter._send_report_to_server(True, name=name, email=email,
file_hash=file_hash,
uptime=uptime, text_box=text_box)
self.errorreport_mock.assert_called_once_with('mantidplot', uptime, self.exit_code, True, name,
email, text_box, file_hash)
email, text_box, '')
self.errorreport_mock_instance.sendErrorReport.assert_called_once_with()
self.view.display_message_box.assert_called_once_with('Error contacting server',
ErrorReporterPresenter.SENDING_ERROR_MESSAGE,
......@@ -93,16 +84,13 @@ class ErrorReportPresenterTest(unittest.TestCase):
continue_working = False
share = 0
self.error_report_presenter._send_report_to_server = mock.MagicMock(return_value=201)
self.error_report_presenter._upload_recovery_file = mock.MagicMock()
self.error_report_presenter._handle_exit = mock.MagicMock()
self.error_report_presenter.error_handler(continue_working, share, name, email, text_box)
self.error_report_presenter._send_report_to_server.called_once_with(share_identifiable=True, name=name,
email=email,
file_hash=mock.ANY, uptime=mock.ANY,
email=email, uptime=mock.ANY,
text_box=text_box)
self.assertEqual(self.error_report_presenter._upload_recovery_file.call_count, 1)
self.error_report_presenter._handle_exit.assert_called_once_with(False)
def test_error_handler_share_non_id_sunny_day_case(self):
......@@ -112,13 +100,11 @@ class ErrorReportPresenterTest(unittest.TestCase):
continue_working = True
share = 1
self.error_report_presenter._send_report_to_server = mock.MagicMock()
self.error_report_presenter._upload_recovery_file = mock.MagicMock()
self.error_report_presenter._handle_exit = mock.MagicMock()
self.error_report_presenter.error_handler(continue_working, share, name, email, text_box)
self.error_report_presenter._send_report_to_server.called_once_with(share_identifiable=False, uptime=mock.ANY)
self.assertEqual(self.error_report_presenter._upload_recovery_file.call_count, 0)
self.error_report_presenter._handle_exit.assert_called_once_with(True)
def test_error_handler_share_nothing_sunny_day_case(self):
......@@ -128,13 +114,11 @@ class ErrorReportPresenterTest(unittest.TestCase):
continue_working = True
share = 2
self.error_report_presenter._send_report_to_server = mock.MagicMock()
self.error_report_presenter._upload_recovery_file = mock.MagicMock()
self.error_report_presenter._handle_exit = mock.MagicMock()
self.error_report_presenter.error_handler(continue_working, share, name, email, text_box)
self.assertEqual(self.error_report_presenter._send_report_to_server.call_count, 0)
self.assertEqual(self.error_report_presenter._upload_recovery_file.call_count, 0)
self.error_report_presenter._handle_exit.assert_called_once_with(True)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment