Skip to content
Snippets Groups Projects
Commit 40869a66 authored by Robert Latta's avatar Robert Latta
Browse files

Updated tests to cope with additional DB connection

parent 68652d81
No related branches found
No related tags found
No related merge requests found
......@@ -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"
......
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