aboutsummaryrefslogtreecommitdiffstats
path: root/python_moonutilities/tests
diff options
context:
space:
mode:
Diffstat (limited to 'python_moonutilities/tests')
-rw-r--r--python_moonutilities/tests/unit_python/mock_repo/components_utilities.py28
-rw-r--r--python_moonutilities/tests/unit_python/mock_repo/data.py2
-rw-r--r--python_moonutilities/tests/unit_python/mock_repo/urls.py15
-rw-r--r--python_moonutilities/tests/unit_python/test_configuration.py65
4 files changed, 29 insertions, 81 deletions
diff --git a/python_moonutilities/tests/unit_python/mock_repo/components_utilities.py b/python_moonutilities/tests/unit_python/mock_repo/components_utilities.py
index 53c51343..11686ce4 100644
--- a/python_moonutilities/tests/unit_python/mock_repo/components_utilities.py
+++ b/python_moonutilities/tests/unit_python/mock_repo/components_utilities.py
@@ -35,21 +35,19 @@ CONF = {
"container": "wukongsun/moon_orchestrator:v4.3",
"hostname": "interface"
},
- "interface": {
- "bind": "0.0.0.0",
- "port": 8080,
- "container": "wukongsun/moon_interface:v4.3",
- "hostname": "interface"
- }
- },
- "plugins": {
- "session": {
- "port": 8082,
- "container": "asteroide/session:latest"
- },
- "authz": {
- "port": 8081,
- "container": "wukongsun/moon_authz:v4.3"
+ "pipeline": {
+ "interface": {
+ "bind": "0.0.0.0",
+ "port": 8080,
+ "container": "wukongsun/moon_interface:v4.3",
+ "hostname": "interface"
+ },
+ "authz": {
+ "bind": "0.0.0.0",
+ "port": 8081,
+ "container": "wukongsun/moon_authz:v4.3",
+ "hostname": "authz"
+ },
}
},
"logging": {
diff --git a/python_moonutilities/tests/unit_python/mock_repo/data.py b/python_moonutilities/tests/unit_python/mock_repo/data.py
index d6f2613a..0e772e2c 100644
--- a/python_moonutilities/tests/unit_python/mock_repo/data.py
+++ b/python_moonutilities/tests/unit_python/mock_repo/data.py
@@ -5,7 +5,7 @@ components = (
"slave",
"components/manager",
"components/orchestrator",
- "components/interface",
+ "components/pipeline",
"components/port_start"
)
diff --git a/python_moonutilities/tests/unit_python/mock_repo/urls.py b/python_moonutilities/tests/unit_python/mock_repo/urls.py
index 4170213c..634f07b1 100644
--- a/python_moonutilities/tests/unit_python/mock_repo/urls.py
+++ b/python_moonutilities/tests/unit_python/mock_repo/urls.py
@@ -10,20 +10,7 @@ def register_components(m):
)
m.register_uri(
'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(
- 'GET', 'http://consul:8500/v1/kv/plugins?recurse=true',
- json=[
- {
- "LockIndex": 0,
- "Key": "plugins/authz",
- "Flags": 0,
- "Value": "eyJjb250YWluZXIiOiAid3Vrb25nc3VuL21vb25fYXV0aHo6djQuMyIsICJwb3J0IjogODA4MX0=",
- "CreateIndex": 14,
- "ModifyIndex": 656
- }
- ],
+ json=[{'Key': 'components/port_start', 'Value': comp_util.get_b64_conf("components/port_start")}]
)
m.register_uri(
'PUT', 'http://consul:8500/v1/kv/components/port_start',
diff --git a/python_moonutilities/tests/unit_python/test_configuration.py b/python_moonutilities/tests/unit_python/test_configuration.py
index 87ebb534..5267179e 100644
--- a/python_moonutilities/tests/unit_python/test_configuration.py
+++ b/python_moonutilities/tests/unit_python/test_configuration.py
@@ -5,7 +5,8 @@ import requests_mock
def test_get_configuration_success():
from python_moonutilities import configuration
- assert configuration.get_configuration("components/port_start")["port_start"] == comp_util.CONF["components"]["port_start"]
+ 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_mutliple_list_success(**kwargs):
@@ -20,6 +21,7 @@ def test_get_configuration_mutliple_list_success(**kwargs):
assert len(configuration.get_configuration("components/port_start")) == 2
+
@requests_mock.Mocker(kw='mock')
def test_get_configuration_mutliple_list_failure(**kwargs):
from python_moonutilities import configuration
@@ -34,6 +36,7 @@ def test_get_configuration_mutliple_list_failure(**kwargs):
configuration.get_configuration("components/port_start")
assert str(exception_info.value) == '500: Consul Content error'
+
@requests_mock.Mocker(kw='mock')
def test_get_configuration_not_found(**kwargs):
from python_moonutilities import configuration
@@ -44,6 +47,7 @@ def test_get_configuration_not_found(**kwargs):
configuration.get_configuration("components/port_start_wrong")
assert str(exception_info.value) == '500: Consul error'
+
@requests_mock.Mocker(kw='mock')
def test_get_configuration_invalid_response(**kwargs):
from python_moonutilities import configuration
@@ -55,6 +59,7 @@ def test_get_configuration_invalid_response(**kwargs):
configuration.get_configuration("components/port_start")
assert str(exception_info.value) == '500: Consul Content error'
+
################################ increment_port ####################################
@requests_mock.Mocker(kw='mock')
def test_put_increment_port_invalidkey_failure(**kwargs):
@@ -67,6 +72,7 @@ def test_put_increment_port_invalidkey_failure(**kwargs):
configuration.increment_port()
assert str(exception_info.value) == '500: Consul Content error'
+
@requests_mock.Mocker(kw='mock')
def test_put_increment_port_failure(**kwargs):
from python_moonutilities import configuration
@@ -76,14 +82,15 @@ def test_put_increment_port_failure(**kwargs):
], status_code=200)
with pytest.raises(Exception) as exception_info:
configuration.increment_port()
- assert str(exception_info.value) == '400: Consul error'
+ assert str(exception_info.value) == '500: Consul Content 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
+ assert incremented_port == cur_port + 1
+
################################ plugin ####################################
def test_get_plugins_success():
@@ -91,60 +98,13 @@ def test_get_plugins_success():
plugin = configuration.get_plugins()
assert plugin is not None
-@requests_mock.Mocker(kw='mock')
-def test_get_plugins_mutliple_list_success(**kwargs):
- from python_moonutilities import configuration
-
- kwargs['mock'].get('http://consul:8500/v1/kv/plugins?recurse=true',
- json=[
- {'Key': 'plugins/authz', 'Value': 'eyJjb250YWluZXIiOiAid3Vrb25nc3VuL21vb25fYXV0aHo6djQuMyIsICJwb3J0IjogODA4MX0='},
- {'Key': 'plugins/authz', 'Value': 'eyJjb250YWluZXIiOiAid3Vrb25nc3VuL21vb25fYXV0aHo6djQuMyIsICJwb3J0IjogODA4MX0='}
- ]
- )
-
- res = configuration.get_plugins()
- assert bool(res)
-
-@requests_mock.Mocker(kw='mock')
-def test_get_plugins_mutliple_list_failure(**kwargs):
- from python_moonutilities import configuration
-
- kwargs['mock'].get('http://consul:8500/v1/kv/plugins?recurse=true',
- json=[
- {'Key': 'plugins/authz', 'Value': "eyJjb250YWluZXIiOiAid3Vrb25"},
- {'invalidKey': 'plugins/authz', 'Value': "eyJjb250YWluZXIiOiAid3Vrb25"}
- ]
- )
- with pytest.raises(Exception) as exception_info:
- configuration.get_plugins()
- assert str(exception_info.value) == '500: Consul Content error'
-
-@requests_mock.Mocker(kw='mock')
-def test_get_plugins_not_found(**kwargs):
- from python_moonutilities import configuration
-
- kwargs['mock'].get('http://consul:8500/v1/kv/plugins?recurse=true', json=[
- ], status_code=500)
- with pytest.raises(Exception) as exception_info:
- configuration.get_plugins()
- assert str(exception_info.value) == '400: Consul error'
-
-@requests_mock.Mocker(kw='mock')
-def test_get_plugins_invalid_response(**kwargs):
- from python_moonutilities import configuration
-
- kwargs['mock'].get('http://consul:8500/v1/kv/plugins?recurse=true', json=[
- {"invalidKey":'invalid', 'Value': "jb250"}
- ])
- with pytest.raises(Exception) as exception_info:
- configuration.get_plugins()
- assert str(exception_info.value) == '500: Consul Content error'
################################ component ####################################
def test_get_components():
from python_moonutilities import configuration
assert isinstance(configuration.get_components(), dict)
+
@requests_mock.Mocker(kw='mock')
def test_get_components_mutliple_list_success(**kwargs):
from python_moonutilities import configuration
@@ -159,6 +119,7 @@ def test_get_components_mutliple_list_success(**kwargs):
res = configuration.get_components()
assert bool(res)
+
@requests_mock.Mocker(kw='mock')
def test_get_components_mutliple_list_failure(**kwargs):
from python_moonutilities import configuration
@@ -173,6 +134,7 @@ def test_get_components_mutliple_list_failure(**kwargs):
configuration.get_components()
assert str(exception_info.value) == '500: Consul Content error'
+
@requests_mock.Mocker(kw='mock')
def test_get_components_not_found(**kwargs):
from python_moonutilities import configuration
@@ -183,6 +145,7 @@ def test_get_components_not_found(**kwargs):
configuration.get_components()
assert str(exception_info.value) == '400: Consul error'
+
@requests_mock.Mocker(kw='mock')
def test_get_components_invalid_response(**kwargs):
from python_moonutilities import configuration