From b4de4582ab951357f029831d1d928cd8ccbd751a Mon Sep 17 00:00:00 2001 From: Erik Reid <erik.reid@geant.org> Date: Wed, 15 Jan 2020 22:23:38 +0100 Subject: [PATCH] updated test to match new rsp schema --- test/test_classifier_routes.py | 75 ++++++++++++++++++++++++++++++---- 1 file changed, 68 insertions(+), 7 deletions(-) diff --git a/test/test_classifier_routes.py b/test/test_classifier_routes.py index 81fa8e87..7723dfab 100644 --- a/test/test_classifier_routes.py +++ b/test/test_classifier_routes.py @@ -8,11 +8,31 @@ DEFAULT_REQUEST_HEADERS = { "Accept": ["application/json"] } +LOCATION_END_DEFINITION = { + "type": "object", + "properties": { + "equipment": {"type": "string"}, + "name": {"type": "string"}, + "abbreviation": {"type": "string"} + }, + "required": ["equipment", "name", "abbreviation"], + "additionalProperties": False +} +LOCATION_DEFINITION = { + "type": "object", + "properties": { + "a": LOCATION_END_DEFINITION, + "b": LOCATION_END_DEFINITION + }, + "required": ["a"], + "additionalProperties": False +} JUNIPER_LINK_METADATA = { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "definitions": { + "location": LOCATION_DEFINITION, "ip-address": { "type": "string", "oneOf": [ @@ -123,6 +143,10 @@ JUNIPER_LINK_METADATA = { "related-services": { "type": "array", "items": {"$ref": "#/definitions/service-info"} + }, + "locations": { + "type": "array", + "items": {"$ref": "#/definitions/location"} } }, # "required": ["interface"], @@ -156,12 +180,18 @@ def test_juniper_link_info_not_found(client): 'ipv4': [], 'ipv6': [], 'bundle': [] - } + }, + 'locations': [{ + 'a': { + 'equipment': 'mx1.ams.nl.geant.net', + 'name': 'Amsterdam', + 'abbreviation': 'ams'} + }] } -VPN_RR_PEER_INFO_KEYS = {'vpn-rr-peer-info'} -IX_PUBLIC_PEER_INFO_KEYS = {'ix-public-peer-info', 'interfaces'} +VPN_RR_PEER_INFO_KEYS = {'vpn-rr-peer-info', 'locations'} +IX_PUBLIC_PEER_INFO_KEYS = {'ix-public-peer-info', 'interfaces', 'locations'} @pytest.mark.parametrize('peer_address,expected_response_keys', [ @@ -178,6 +208,7 @@ def test_peer_info( "type": "object", "definitions": { + "location": LOCATION_DEFINITION, "ip-address": { "type": "string", "oneOf": [ @@ -272,6 +303,10 @@ def test_peer_info( "interfaces": { "type": "array", "items": {"$ref": "#/definitions/interface-lookup-info"} + }, + "locations": { + "type": "array", + "items": {"$ref": "#/definitions/location"} } }, "additionalProperties": False @@ -301,7 +336,7 @@ def test_peer_not_found(client): headers=DEFAULT_REQUEST_HEADERS) assert rv.status_code == 200 response_data = json.loads(rv.data.decode('utf-8')) - assert response_data == {} + assert response_data == {'locations': []} @pytest.mark.parametrize('id_,equipment,entity_name,card_id,port_number', [ @@ -325,7 +360,27 @@ def test_coriant_info( 'inventory_provider.db.db.connection', mocked_connection) mocker.patch( 'inventory_provider.db.opsdb.lookup_coriant_path', - lambda a, b, c, d: {'id': '123', 'C': a, 'E': b, 'CID': c, 'P': d}) + lambda a, b, c, d: { + 'id': '123', + 'C': a, + 'E': b, + 'CID': c, + 'P': d, + 'a': { + 'equipment name': 'abc', + 'pop': { + 'name': 'zzz', + 'abbreviation': '123' + } + }, + 'b': { + 'equipment name': 'ddd', + 'pop': { + 'name': 'aaa', + 'abbreviation': '999' + } + } + }) rv = client.get( '/classifier/coriant-info/{equipment}/{entity}'.format( @@ -346,8 +401,14 @@ def test_coriant_info( 'C': CONNECTION, 'E': equipment, 'CID': card_id, - 'P': port_number - } + 'P': port_number, + 'a': {'equipment name': 'abc', 'pop': {'name': 'zzz', 'abbreviation': '123'}}, + 'b': {'equipment name': 'ddd', 'pop': {'name': 'aaa', 'abbreviation': '999'}} + }, + 'locations': [{ + 'a': {'equipment': 'abc', 'name': 'zzz', 'abbreviation': '123'}, + 'b': {'equipment': 'ddd', 'name': 'aaa', 'abbreviation': '999'} + }] } assert response_data == expected_response -- GitLab