diff --git a/test/test_alarmsdb.py b/test/test_alarmsdb.py index 7eb707c1210bca0a21cd36ebdc3b658290cca426..7236721fc5f43d4931214a98a8d610049429c8a1 100644 --- a/test/test_alarmsdb.py +++ b/test/test_alarmsdb.py @@ -2,27 +2,23 @@ import inventory_provider.alarmsdb as alarmsdb def test_infinera_interface_status(mocker): - mocked_get_cursor = mocker.patch('inventory_provider.alarmsdb.db.cursor') - mocked_execute = mocked_get_cursor. \ - return_value.__enter__.return_value.execute - mocked_fetchone = mocked_get_cursor.return_value.__enter__. \ - return_value.fetchone - mocked_fetchone.return_value = ('Raised',) + mock = mocker.Mock() + mock.fetchone.return_value = ('Raised',) assert alarmsdb.get_last_known_infinera_interface_status( - None, 'eq1', 'intfc1' + mock, 'eq1', 'intfc1' ) == "down" - mocked_fetchone.return_value = ("Clear",) + mock.fetchone.return_value = ("Clear",) assert alarmsdb.get_last_known_infinera_interface_status( - None, 'eq1', 'intfc1' + mock, 'eq1', 'intfc1' ) == "up" - mocked_fetchone.return_value = () + mock.fetchone.return_value = () assert alarmsdb.get_last_known_infinera_interface_status( - None, 'eq1', 'intfc1' + mock, 'eq1', 'intfc1' ) == "unknown" - mocked_execute.assert_called_with( + mock.execute.assert_called_with( "SELECT status FROM infinera_alarms WHERE" " CONCAT(ne_name, '-', REPLACE(object_name, 'T', '')) = %s" " ORDER BY ne_init_time DESC, ne_clear_time DESC LIMIT 1", @@ -30,27 +26,23 @@ def test_infinera_interface_status(mocker): def test_coriant_interface_status(mocker): - mocked_get_cursor = mocker.patch('inventory_provider.alarmsdb.db.cursor') - mocked_execute = mocked_get_cursor. \ - return_value.__enter__.return_value.execute - mocked_fetchone = mocked_get_cursor.return_value.__enter__. \ - return_value.fetchone - mocked_fetchone.return_value = ('Raised',) + mock = mocker.Mock() + mock.fetchone.return_value = ('Raised',) assert alarmsdb.get_last_known_coriant_interface_status( - None, 'eq1', 'intfc1' + mock, 'eq1', 'intfc1' ) == "down" - mocked_fetchone.return_value = ("Clear",) + mock.fetchone.return_value = ("Clear",) assert alarmsdb.get_last_known_coriant_interface_status( - None, 'eq1', 'intfc1' + mock, 'eq1', 'intfc1' ) == "up" - mocked_fetchone.return_value = () + mock.fetchone.return_value = () assert alarmsdb.get_last_known_coriant_interface_status( - None, 'eq1', 'intfc1' + mock, 'eq1', 'intfc1' ) == "unknown" - mocked_execute.assert_called_with( + mock.execute.assert_called_with( "SELECT status FROM coriant_alarms" " WHERE ne_id_name = %s AND entity_string LIKE %s" " ORDER BY last_event_time DESC LIMIT 1", @@ -58,27 +50,23 @@ def test_coriant_interface_status(mocker): def test_juniper_interface_status(mocker): - mocked_get_cursor = mocker.patch('inventory_provider.alarmsdb.db.cursor') - mocked_execute = mocked_get_cursor. \ - return_value.__enter__.return_value.execute - mocked_fetchone = mocked_get_cursor.return_value.__enter__. \ - return_value.fetchone - mocked_fetchone.return_value = (0,) + mock = mocker.Mock() + mock.fetchone.return_value = (0,) assert alarmsdb.get_last_known_juniper_link_interface_status( - None, 'eq1', 'intfc1' + mock, 'eq1', 'intfc1' ) == "down" - mocked_fetchone.return_value = (1,) + mock.fetchone.return_value = (1,) assert alarmsdb.get_last_known_juniper_link_interface_status( - None, 'eq1', 'intfc1' + mock, 'eq1', 'intfc1' ) == "up" - mocked_fetchone.return_value = () + mock.fetchone.return_value = () assert alarmsdb.get_last_known_juniper_link_interface_status( - None, 'eq1', 'intfc1' + mock, 'eq1', 'intfc1' ) == "unknown" - mocked_execute.assert_called_with( + mock.execute.assert_called_with( "SELECT IF(link_admin_status = 'up'" " AND link_oper_status = 'up', 1, 0)" " AS up FROM juniper_alarms"