aboutsummaryrefslogtreecommitdiffstats
path: root/moonv4/python_moonclient/tests/unit_python
diff options
context:
space:
mode:
authorRHE <rebirthmonkey@gmail.com>2017-12-21 10:06:52 +0100
committerThomas Duval <thomas.duval@orange.com>2017-12-21 10:33:15 +0100
commit8b326a5aeb0f9655ff0ebfe0d87ff1ea8f66bc38 (patch)
tree16f319475de8f256914e18a6be0183b48ccc692a /moonv4/python_moonclient/tests/unit_python
parenta7f99c33c0b2b2c617dd044e658a263ae910b53a (diff)
python_moonclient init
Change-Id: Iaf104b3208a07dc80cc266830be444d019b0f196 Signed-off-by: RHE <rebirthmonkey@gmail.com>
Diffstat (limited to 'moonv4/python_moonclient/tests/unit_python')
-rw-r--r--moonv4/python_moonclient/tests/unit_python/conftest.py12
-rw-r--r--moonv4/python_moonclient/tests/unit_python/mock_config.py35
-rw-r--r--moonv4/python_moonclient/tests/unit_python/requirements.txt2
-rw-r--r--moonv4/python_moonclient/tests/unit_python/test_config.py8
-rw-r--r--moonv4/python_moonclient/tests/unit_python/utilities.py153
5 files changed, 210 insertions, 0 deletions
diff --git a/moonv4/python_moonclient/tests/unit_python/conftest.py b/moonv4/python_moonclient/tests/unit_python/conftest.py
new file mode 100644
index 00000000..d26df946
--- /dev/null
+++ b/moonv4/python_moonclient/tests/unit_python/conftest.py
@@ -0,0 +1,12 @@
+import pytest
+import requests_mock
+import mock_config
+
+
+@pytest.fixture(autouse=True)
+def no_requests(monkeypatch):
+ """ Modify the response from Requests module
+ """
+ with requests_mock.Mocker(real_http=True) as m:
+ mock_config.register_consul(m)
+ yield m
diff --git a/moonv4/python_moonclient/tests/unit_python/mock_config.py b/moonv4/python_moonclient/tests/unit_python/mock_config.py
new file mode 100644
index 00000000..a3084485
--- /dev/null
+++ b/moonv4/python_moonclient/tests/unit_python/mock_config.py
@@ -0,0 +1,35 @@
+import utilities
+
+
+components_manager_mock = {
+ "port": 8082,
+ "bind": "0.0.0.0",
+ "hostname": "manager",
+ "container": "wukongsun/moon_manager:v4.3.1",
+ "external": {
+ "port": 30001,
+ "hostname": "88.88.88.2"
+ }
+}
+
+
+openstack_keystone_mock = {
+ "url": "http://keystone:5000/v3",
+ "user": "admin",
+ "password": "p4ssw0rd",
+ "domain": "default",
+ "project": "admin",
+ "check_token": False,
+ "certificate": False,
+ "external": {
+ "url": "http://88.88.88.2:30006/v3"
+ }
+}
+
+
+def register_consul(m):
+ for component in utilities.COMPONENTS:
+ m.register_uri(
+ 'GET', 'http://consul:8500/v1/kv/{}'.format(component),
+ json=[{'Key': component, 'Value': utilities.get_b64_conf(component)}]
+ )
diff --git a/moonv4/python_moonclient/tests/unit_python/requirements.txt b/moonv4/python_moonclient/tests/unit_python/requirements.txt
new file mode 100644
index 00000000..3c1ad607
--- /dev/null
+++ b/moonv4/python_moonclient/tests/unit_python/requirements.txt
@@ -0,0 +1,2 @@
+pytest
+requests_mock \ No newline at end of file
diff --git a/moonv4/python_moonclient/tests/unit_python/test_config.py b/moonv4/python_moonclient/tests/unit_python/test_config.py
new file mode 100644
index 00000000..21b5f630
--- /dev/null
+++ b/moonv4/python_moonclient/tests/unit_python/test_config.py
@@ -0,0 +1,8 @@
+import pytest
+import utilities
+
+
+def test_authz_request():
+ from python_moonclient import config
+ conf_data = config.get_config_data("consul", 8500)
+ assert isinstance(conf_data, dict)
diff --git a/moonv4/python_moonclient/tests/unit_python/utilities.py b/moonv4/python_moonclient/tests/unit_python/utilities.py
new file mode 100644
index 00000000..ae2932c7
--- /dev/null
+++ b/moonv4/python_moonclient/tests/unit_python/utilities.py
@@ -0,0 +1,153 @@
+import base64
+import json
+
+CONF = {
+ "openstack": {
+ "keystone": {
+ "url": "http://keystone:5000/v3",
+ "user": "admin",
+ "check_token": False,
+ "password": "p4ssw0rd",
+ "domain": "default",
+ "certificate": False,
+ "project": "admin",
+ "external": {
+ "url": "http://keystone:5000/v3",
+ }
+ }
+ },
+ "components": {
+ "wrapper": {
+ "bind": "0.0.0.0",
+ "port": 8080,
+ "container": "wukongsun/moon_wrapper:v4.3",
+ "timeout": 5,
+ "hostname": "wrapper"
+ },
+ "manager": {
+ "bind": "0.0.0.0",
+ "port": 8082,
+ "container": "wukongsun/moon_manager:v4.3",
+ "hostname": "manager",
+ "external": {
+ "hostname": "manager",
+ "port": 30001
+ }
+ },
+ "port_start": 31001,
+ "orchestrator": {
+ "bind": "0.0.0.0",
+ "port": 8083,
+ "container": "wukongsun/moon_orchestrator:v4.3",
+ "hostname": "orchestrator"
+ },
+ "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"
+ }
+ },
+ "logging": {
+ "handlers": {
+ "file": {
+ "filename": "/tmp/moon.log",
+ "class": "logging.handlers.RotatingFileHandler",
+ "level": "DEBUG",
+ "formatter": "custom",
+ "backupCount": 3,
+ "maxBytes": 1048576
+ },
+ "console": {
+ "class": "logging.StreamHandler",
+ "formatter": "brief",
+ "level": "INFO",
+ "stream": "ext://sys.stdout"
+ }
+ },
+ "formatters": {
+ "brief": {
+ "format": "%(levelname)s %(name)s %(message)-30s"
+ },
+ "custom": {
+ "format": "%(asctime)-15s %(levelname)s %(name)s %(message)s"
+ }
+ },
+ "root": {
+ "handlers": [
+ "console"
+ ],
+ "level": "ERROR"
+ },
+ "version": 1,
+ "loggers": {
+ "moon": {
+ "handlers": [
+ "console",
+ "file"
+ ],
+ "propagate": False,
+ "level": "DEBUG"
+ }
+ }
+ },
+ "slave": {
+ "name": None,
+ "master": {
+ "url": None,
+ "login": None,
+ "password": None
+ }
+ },
+ "docker": {
+ "url": "tcp://172.88.88.1:2376",
+ "network": "moon"
+ },
+ "database": {
+ "url": "sqlite:///database.db",
+ # "url": "mysql+pymysql://moon:p4sswOrd1@db/moon",
+ "driver": "sql"
+ },
+ "messenger": {
+ "url": "rabbit://moon:p4sswOrd1@messenger:5672/moon"
+ }
+}
+
+COMPONENTS = (
+ "logging",
+ "openstack/keystone",
+ "database",
+ "slave",
+ "components/manager",
+ "components/orchestrator",
+ "components/interface",
+ "components/wrapper",
+)
+
+
+def get_b64_conf(component=None):
+ if component == "components":
+ return base64.b64encode(
+ json.dumps(CONF["components"]).encode('utf-8')+b"\n").decode('utf-8')
+ elif component in CONF:
+ return base64.b64encode(
+ json.dumps(
+ CONF[component]).encode('utf-8')+b"\n").decode('utf-8')
+ elif not component:
+ return base64.b64encode(
+ json.dumps(CONF).encode('utf-8')+b"\n").decode('utf-8')
+ elif "/" in component:
+ key1, _, key2 = component.partition("/")
+ return base64.b64encode(
+ json.dumps(
+ CONF[key1][key2]).encode('utf-8')+b"\n").decode('utf-8')