From 46ef692d3c1c9d57ad61bcc34bdac48eabf240b7 Mon Sep 17 00:00:00 2001 From: Tommy Carpenter Date: Mon, 9 Jul 2018 15:11:14 -0400 Subject: Finish EELF compliance. Issue-ID: DCAEGEN2-581 Change-Id: I22651dbe775b0165612c507df99b5a0e8e2ee22c Signed-off-by: Tommy Carpenter --- app/app/tests/test_controller.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'app/app/tests/test_controller.py') diff --git a/app/app/tests/test_controller.py b/app/app/tests/test_controller.py index cda1fc7..0650a38 100644 --- a/app/app/tests/test_controller.py +++ b/app/app/tests/test_controller.py @@ -21,7 +21,7 @@ import pytest from config_binding_service import client, controller -# pytest doesnt support objects in conftest yet +# pytest doesnt support objects in conftest class FakeConnexion(object): def __init__(self, headers, path, host, remote_addr): self.headers = headers @@ -30,13 +30,22 @@ class FakeConnexion(object): self.remote_addr = remote_addr +# pytest doesnt support objects in conftest +class FakeReq(object): + """used to fake the logging params""" + def __init__(self): + self.path = "/unittest in {0}".format(__name__) + self.host = "localhost" + self.remote_addr = "6.6.6.6" + + def test_bind_config_for_scn(monkeypatch, monkeyed_requests_put): monkeypatch.setattr('requests.put', monkeyed_requests_put) monkeypatch.setattr('connexion.request', FakeConnexion({"x-onap-requestid": 123456789}, "/service_component", "mytestingmachine", "myremoteclient")) - assert(client.resolve("scn_exists") == {"foo3": "bar3"}) + assert(client.resolve("scn_exists", FakeReq(), "unit test xer") == {"foo3": "bar3"}) with pytest.raises(client.CantGetConfig): - client.resolve("scn_NOTexists") + client.resolve("scn_NOTexists", FakeReq(), "unit test xer") R = controller.bind_config_for_scn("scn_exists") assert(json.loads(R.data) == {"foo3": "bar3"}) @@ -55,10 +64,9 @@ def test_bind_config_for_scn(monkeypatch, monkeyed_requests_put): def test_generic(monkeypatch, monkeyed_requests_get, monkeyed_requests_put): monkeypatch.setattr('requests.put', monkeyed_requests_put) monkeypatch.setattr('requests.get', monkeyed_requests_get) - assert client.get_key("dti", "test_service_component_name.unknown.unknown.unknown.dcae.onap.org") == json.loads('{"my": "dti"}') + assert client.get_key("dti", "test_service_component_name.unknown.unknown.unknown.dcae.onap.org", FakeReq(), "unit test xer") == json.loads('{"my": "dti"}') with pytest.raises(client.CantGetConfig): - client.get_key( - "nokeyforyou", "test_service_component_name.unknown.unknown.unknown.dcae.onap.org") + client.get_key("nokeyforyou", "test_service_component_name.unknown.unknown.unknown.dcae.onap.org", FakeReq(), "unit test xer") monkeypatch.setattr('connexion.request', FakeConnexion({}, "/get_key", "mytestingmachine", "myremoteclient")) @@ -81,8 +89,7 @@ def test_generic(monkeypatch, monkeyed_requests_get, monkeyed_requests_put): def test_resolve_all(monkeypatch, monkeyed_requests_put, monkeyed_get_connection_info_from_consul, expected_config): monkeypatch.setattr('requests.put', monkeyed_requests_put) - allk = client.resolve_all( - "test_service_component_name.unknown.unknown.unknown.dcae.onap.org") + allk = client.resolve_all("test_service_component_name.unknown.unknown.unknown.dcae.onap.org", FakeReq(), "unit test xer") withstuff = {'config': {'my': 'amazing config'}, 'dti': {'my': 'dti'}, 'policies': {'items': [{'policyName': 'DCAE_alex.Config_MS_alex_microservice.132.xml', 'policyConfigMessage': 'Config Retrieved! ', 'responseAttributes': {}, 'policyConfigStatus': 'CONFIG_RETRIEVED', 'matchingConditions': {'ONAPName': 'DCAE', 'Name': 'DCAE', 'ConfigName': 'alex_config_name'}, 'config': {'policyScope': 'alex_policy_scope', 'configName': 'alex_config_name', 'description': 'test DCAE policy-handler', 'service': 'alex_service', 'policyName': 'alex_policy_name', 'riskLevel': '3', 'key1': 'value1', 'policy_hello': 'world!', 'content': {'foo': 'microservice3', 'foo_updated': '2018-01-30T13:25:33.222Z'}, 'riskType': '1712_ETE', 'guard': 'False', 'version': '0.0.1', 'location': 'Central', 'policy_updated_ts': '2018-02-19T15:09:55.217Z', 'updated_policy_id': 'DCAE_alex.Config_MS_alex_microservice', 'policy_updated_to_ver': '132', 'priority': '4', 'policy_updated_from_ver': '131', 'templateVersion': '2', 'uuid': '5e87d7c5-0daf-4b6b-ab92-5365cf5db1ef'}, 'property': None, 'type': 'JSON', 'policyVersion': '132'}, {'policyName': 'DCAE_alex.Config_db_client_policy_id_value.133.xml', 'policyConfigMessage': 'Config Retrieved! ', 'responseAttributes': {}, 'policyConfigStatus': 'CONFIG_RETRIEVED', 'matchingConditions': {'ONAPName': 'DCAE', 'Name': 'DCAE', 'ConfigName': 'alex_config_name'}, 'config': {'db_client_ts': '2017-11-21T12:12:13.696Z', 'db_client': 'ipsum', 'policy_hello': 'world!', 'policy_updated_from_ver': '132', 'updated_policy_id': 'DCAE_alex.Config_db_client_policy_id_value', 'policy_updated_ts': '2018-02-19T15:09:55.812Z', 'policy_updated_to_ver': '133'}, 'property': None, 'type': 'JSON', 'policyVersion': '133'}], 'event': {'action': 'gathered', 'timestamp': '2018-02-19 15:36:44.877380', 'update_id': 'bb73c20a-5ff8-450f-8223-da6720ade267', 'policies_count': 2}}} @@ -90,7 +97,7 @@ def test_resolve_all(monkeypatch, monkeyed_requests_put, monkeyed_get_connection monkeypatch.setattr('config_binding_service.client._get_connection_info_from_consul', monkeyed_get_connection_info_from_consul) - allk = client.resolve_all("test_resolve_scn") + allk = client.resolve_all("test_resolve_scn", FakeReq(), "unit test xer") assert allk == {"config": expected_config} monkeypatch.setattr('connexion.request', FakeConnexion({}, "/service_component_all", "mytestingmachine", "myremoteclient")) -- cgit 1.2.3-korg