aboutsummaryrefslogtreecommitdiffstats
path: root/python_moonutilities/tests/unit_python/test_configuration.py
diff options
context:
space:
mode:
authorsgdt6900 <rhanafy.ext@orange.com>2017-12-25 15:47:40 +0200
committersgdt6900 <rhanafy.ext@orange.com>2017-12-25 15:47:40 +0200
commit12df3719531f1aac21e35efab3688927a42a4b70 (patch)
tree467d05db7799a89893bc109ca97d9c60f7bc4775 /python_moonutilities/tests/unit_python/test_configuration.py
parentb2904eb52f85938a18f55520ce2b4cf4dcb0269f (diff)
adding unit tests for cache module
Change-Id: Ie6837e63ca652374ce7b5a304d7352b3d6ddba58 Signed-off-by: sgdt6900 <rhanafy.ext@orange.com>
Diffstat (limited to 'python_moonutilities/tests/unit_python/test_configuration.py')
-rw-r--r--python_moonutilities/tests/unit_python/test_configuration.py53
1 files changed, 51 insertions, 2 deletions
diff --git a/python_moonutilities/tests/unit_python/test_configuration.py b/python_moonutilities/tests/unit_python/test_configuration.py
index 48699062..fe01c7e2 100644
--- a/python_moonutilities/tests/unit_python/test_configuration.py
+++ b/python_moonutilities/tests/unit_python/test_configuration.py
@@ -1,5 +1,54 @@
+import mock_repo.components_utilities as comp_util
+import pytest
+import requests_mock
-def test_get_components():
+
+
+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"]
+
+@requests_mock.Mocker(kw='mock')
+def test_get_configuration_not_found(**kwargs):
+ from python_moonutilities import configuration
+
+ kwargs['mock'].get('http://consul:8500/v1/kv/components/port_start_wrong', json=[
+ ], status_code=500)
+ with pytest.raises(Exception) as exception_info:
+ 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
- assert isinstance(configuration.get_components(), dict)
+ 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")}
+ ])
+ # 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")}
+ ], status_code=200)
+ with pytest.raises(Exception) as exception_info:
+ configuration.increment_port()
+ assert str(exception_info.value) == '400: Consul error'
+
+def test_increment_port_success():
+ from python_moonutilities import configuration
+ cur_port = comp_util.CONF["components"]["port_start"]
+ incremented_port = configuration.increment_port()
+ assert incremented_port == cur_port + 1
+
+
+def test_get_components():
+ from python_moonutilities import configuration
+ assert isinstance(configuration.get_components(), dict) \ No newline at end of file