From 18fc49f56205a69467aaf3037f9408301336d67a Mon Sep 17 00:00:00 2001 From: Erik Reid <erik.reid@geant.org> Date: Wed, 10 Apr 2019 12:14:35 +0200 Subject: [PATCH] added a test of coriant route, but that mocks all sql access --- test/test_classifier_routes.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/test_classifier_routes.py b/test/test_classifier_routes.py index 2b4e76a5..54555fec 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 -- GitLab