diff --git a/test/test_classifier_routes.py b/test/test_classifier_routes.py index b3b0484fd1c4446a219b740d8ad942c8de5dafeb..08e463932abc0286ea70dd616727880c352e9b31 100644 --- a/test/test_classifier_routes.py +++ b/test/test_classifier_routes.py @@ -7,7 +7,7 @@ DEFAULT_REQUEST_HEADERS = { } -def test_version_request(client): +def test_infinera_addresses(client): response_schema = { "$schema": "http://json-schema.org/draft-07/schema#", "type": "array", @@ -22,3 +22,39 @@ def test_version_request(client): json.loads(rv.data.decode("utf-8")), response_schema) + +def test_juniper_addresses(mocker, client): + + test_data = [ + {"ip_address": "a.b.c.d", "project_name": "AAABBB"}, + {"ip_address": "b.c.d.e", "project_name": "CCCCDDDDD"}, + {"ip_address": "c.d.e.f", "project_name": "EFEFEFEF"}, + {"ip_address": "::1", "project_name": "GGHHGGHH"} + ] + + class MockedRedis(): + def __init__(self): + pass + + def get(self, ignored): + return json.dumps(test_data).encode('utf-8') + + mocker.patch( + 'inventory_provider.routes.classifier.db.get_redis', + return_value=MockedRedis()) + + response_schema = { + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "array", + "items": {"type": "string"} + } + + rv = client.post( + "/classifier/juniper-server-addresses", + headers=DEFAULT_REQUEST_HEADERS) + assert rv.status_code == 200 + response_data = json.loads(rv.data.decode('utf-8')) + jsonschema.validate(response_data, response_schema) + assert len(response_data) == len(test_data) + assert set([x['ip_address'] for x in test_data]) == set(response_data) +