From 6350d625b4e4627fc6886c3d7f052c67abf0989f Mon Sep 17 00:00:00 2001 From: sgdt6900 Date: Mon, 25 Dec 2017 16:13:21 +0200 Subject: adding comments for the cases should be handled for configuration module refactoring url of component port to match same pattern integrating request wrapper adding validation for the key in the object before accessing it update some conditions uncomment required test cases after validation done Change-Id: I5f0e22ca4fd803992c051ec238f91ed0703cd1a2 Signed-off-by: sgdt6900 --- .../tests/unit_python/mock_repo/urls.py | 6 +++--- .../tests/unit_python/test_configuration.py | 21 +++++++++------------ 2 files changed, 12 insertions(+), 15 deletions(-) (limited to 'python_moonutilities/tests/unit_python') diff --git a/python_moonutilities/tests/unit_python/mock_repo/urls.py b/python_moonutilities/tests/unit_python/mock_repo/urls.py index a5b1e63b..75b55927 100644 --- a/python_moonutilities/tests/unit_python/mock_repo/urls.py +++ b/python_moonutilities/tests/unit_python/mock_repo/urls.py @@ -9,11 +9,11 @@ def register_components(m): json=[{'Key': component, 'Value': comp_util.get_b64_conf(component)}] ) m.register_uri( - 'GET', 'http://consul:8500/v1/kv/components_port_start', - json=[{'Key': 'components_port_start', 'Value': comp_util.get_b64_conf("components/port_start")}] + 'GET', 'http://consul:8500/v1/kv/components/port_start', + json=[{'Key': 'port_start', 'Value': comp_util.get_b64_conf("components/port_start")}] ) m.register_uri( - 'PUT', 'http://consul:8500/v1/kv/components_port_start', + 'PUT', 'http://consul:8500/v1/kv/components/port_start', json=[] ) diff --git a/python_moonutilities/tests/unit_python/test_configuration.py b/python_moonutilities/tests/unit_python/test_configuration.py index 10618f1c..8ca389bf 100644 --- a/python_moonutilities/tests/unit_python/test_configuration.py +++ b/python_moonutilities/tests/unit_python/test_configuration.py @@ -5,7 +5,7 @@ import requests_mock def test_get_configuration_success(): from python_moonutilities import configuration - assert configuration.get_configuration("components/port_start")["components/port_start"] == comp_util.CONF["components"]["port_start"] + assert configuration.get_configuration("components/port_start")["port_start"] == comp_util.CONF["components"]["port_start"] @requests_mock.Mocker(kw='mock') @@ -18,27 +18,24 @@ def test_get_configuration_not_found(**kwargs): configuration.get_configuration("components/port_start_wrong") assert str(exception_info.value) == '500: Consul error' - -# [TODO] this test used to test the invalid response -# it should be un commented and run after refactoring the related part @requests_mock.Mocker(kw='mock') def test_get_configuration_invalid_response(**kwargs): from python_moonutilities import configuration - kwargs['mock'].get('http://consul:8500/v1/kv/components_port_start', json=[ - {"components_port_start":'components_port_start', 'Value': comp_util.get_b64_conf("components/port_start")} + kwargs['mock'].get('http://consul:8500/v1/kv/components/port_start', json=[ + {"port_start":'port_start', 'Value': comp_util.get_b64_conf("components/port_start")} ]) - # with pytest.raises(Exception) as exception_info: - # configuration.get_configuration("components_port_start") - # assert str(exception_info.value) == '500: Consul error' + with pytest.raises(Exception) as exception_info: + configuration.get_configuration("components/port_start") + assert str(exception_info.value) == '500: Consul error' @requests_mock.Mocker(kw='mock') def test_put_increment_port_failure(**kwargs): from python_moonutilities import configuration - kwargs['mock'].put('http://consul:8500/v1/kv/components_port_start', json=[], status_code=400) - kwargs['mock'].get('http://consul:8500/v1/kv/components_port_start', json=[ - {'Key': 'components_port_start', 'Value': comp_util.get_b64_conf("components/port_start")} + kwargs['mock'].put('http://consul:8500/v1/kv/components/port_start', json=[], status_code=400) + kwargs['mock'].get('http://consul:8500/v1/kv/components/port_start', json=[ + {'Key': 'port_start', 'Value': comp_util.get_b64_conf("components/port_start")} ], status_code=200) with pytest.raises(Exception) as exception_info: configuration.increment_port() -- cgit 1.2.3-korg