diff --git a/src/ModemReporter.py b/src/ModemReporter.py index eecf09f..982c517 100644 --- a/src/ModemReporter.py +++ b/src/ModemReporter.py @@ -80,7 +80,7 @@ def report_events(self, events): try: self.connect_database() sql = "INSERT INTO `modem_events` (`description`, `priority`, `created_at`, `maintenance`) VALUES " - value_string = '(%s, %s, %s, %s)' + value_string = '("%s", %s, "%s", %s)' event_datetime = None value_list = [] diff --git a/src/tests/ModemReporter_test.py b/src/tests/ModemReporter_test.py index aa8a1d4..9142f1c 100644 --- a/src/tests/ModemReporter_test.py +++ b/src/tests/ModemReporter_test.py @@ -139,7 +139,7 @@ def test_report_events(self, connect_mock): ['Wed Sep 09 11:00:00 2020', 'Error (4)', 'The description'], ['Thu Sep 10 09:00:00 2020', 'Error (4)', 'The description'] ] - SQL_QUERY = "INSERT INTO `modem_events` (`description`, `priority`, `created_at`, `maintenance`) VALUES (The description, 4, 2020-09-09 11:00:00, False), (The description, 4, 2020-09-10 09:00:00, False)" + SQL_QUERY = 'INSERT INTO `modem_events` (`description`, `priority`, `created_at`, `maintenance`) VALUES ("The description", 4, "2020-09-09 11:00:00", False), ("The description", 4, "2020-09-10 09:00:00", False)' cursor_mock = MagicMock() CONNECTION_MOCK.cursor.return_value = cursor_mock connect_mock.return_value = CONNECTION_MOCK @@ -161,7 +161,7 @@ def test_report_events_when_no_times_have_been_established(self, connect_mock): ['Time Not Established', 'Error (4)', 'The description'], ['Time Not Established', 'Error (4)', 'The description'] ] - SQL_QUERY = "INSERT INTO `modem_events` (`description`, `priority`, `created_at`, `maintenance`) VALUES (The description, 4, 2020-09-15 13:05:00, False), (The description, 4, 2020-09-15 13:05:00, False), (The description, 4, 2020-09-15 13:05:00, False)" + SQL_QUERY = 'INSERT INTO `modem_events` (`description`, `priority`, `created_at`, `maintenance`) VALUES ("The description", 4, "2020-09-15 13:05:00", False), ("The description", 4, "2020-09-15 13:05:00", False), ("The description", 4, "2020-09-15 13:05:00", False)' cursor_mock = MagicMock() CONNECTION_MOCK.cursor.return_value = cursor_mock connect_mock.return_value = CONNECTION_MOCK @@ -182,7 +182,7 @@ def test_report_events_when_an_earlier_event_has_no_time_established(self, conne ['Wed Sep 09 11:00:00 2020', 'Error (4)', 'The description'], ['Thu Sep 10 09:00:00 2020', 'Error (4)', 'The description'] ] - SQL_QUERY = "INSERT INTO `modem_events` (`description`, `priority`, `created_at`, `maintenance`) VALUES (The description, 4, 2020-09-09 11:00:00, False), (The description, 4, 2020-09-09 11:00:00, False), (The description, 4, 2020-09-10 09:00:00, False)" + SQL_QUERY = 'INSERT INTO `modem_events` (`description`, `priority`, `created_at`, `maintenance`) VALUES ("The description", 4, "2020-09-09 11:00:00", False), ("The description", 4, "2020-09-09 11:00:00", False), ("The description", 4, "2020-09-10 09:00:00", False)' cursor_mock = MagicMock() CONNECTION_MOCK.cursor.return_value = cursor_mock connect_mock.return_value = CONNECTION_MOCK @@ -197,13 +197,13 @@ def test_report_events_when_an_earlier_event_has_no_time_established(self, conne CONNECTION_MOCK.close.assert_called_once() @patch('mysql.connector.connect') - def test_report_events_when_an_later_event_has_no_time_established(self, connect_mock): + def test_report_events_when_a_later_event_has_no_time_established(self, connect_mock): EVENTS = [ ['Wed Sep 09 11:00:00 2020', 'Error (4)', 'The description'], ['Thu Sep 10 09:00:00 2020', 'Error (4)', 'The description'], ['Time Not Established', 'Error (4)', 'The description'] ] - SQL_QUERY = "INSERT INTO `modem_events` (`description`, `priority`, `created_at`, `maintenance`) VALUES (The description, 4, 2020-09-09 11:00:00, False), (The description, 4, 2020-09-10 09:00:00, False), (The description, 4, 2020-09-10 09:00:00, False)" + SQL_QUERY = 'INSERT INTO `modem_events` (`description`, `priority`, `created_at`, `maintenance`) VALUES ("The description", 4, "2020-09-09 11:00:00", False), ("The description", 4, "2020-09-10 09:00:00", False), ("The description", 4, "2020-09-10 09:00:00", False)' cursor_mock = MagicMock() CONNECTION_MOCK.cursor.return_value = cursor_mock connect_mock.return_value = CONNECTION_MOCK