diff --git a/test/test_classifier_routes.py b/test/test_classifier_routes.py index 2b4e76a52a5610a5179387e8db383aa20010ea6b..54555fec79bdaf71e5a5e270820161cd942f6a41 100644 --- a/test/test_classifier_routes.py +++ b/test/test_classifier_routes.py @@ -271,3 +271,35 @@ def test_peer_not_found(client_with_mocked_data): '/classifier/peer-info/1.2.3.4', headers=DEFAULT_REQUEST_HEADERS) assert rv.status_code == 404 + +import contextlib + +def test_coriant_info(client, mocker): + """ + just check the correct method is called, but mock out all sql access + """ + expected_response = { + 'C': 'bogus connection', + 'E': 'bogus equipment name', + 'CID': 'bogus card id', + 'P': 'bogus card number' + } + + @contextlib.contextmanager + def mocked_connection(ignored): + yield expected_response['C'] + + mocker.patch( + 'inventory_provider.db.db.connection', mocked_connection) + mocker.patch( + 'inventory_provider.db.opsdb.get_coriant_path', + lambda a, b, c, d: {'C': a, 'E': b, 'CID': c, 'P': d}) + + rv = client.get( + '/classifier/coriant-info/{E}/{CID}/{P}'.format(**expected_response), + headers=DEFAULT_REQUEST_HEADERS) + + assert rv.status_code == 200 + assert rv.is_json + response_data = json.loads(rv.data.decode('utf-8')) + assert response_data == expected_response