aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--moon_manager/tests/unit_python/api/test_pdp.py62
-rw-r--r--moon_manager/tests/unit_python/conftest.py61
2 files changed, 111 insertions, 12 deletions
diff --git a/moon_manager/tests/unit_python/api/test_pdp.py b/moon_manager/tests/unit_python/api/test_pdp.py
new file mode 100644
index 00000000..a2d0cb5a
--- /dev/null
+++ b/moon_manager/tests/unit_python/api/test_pdp.py
@@ -0,0 +1,62 @@
+import json
+import api.utilities as utilities
+import pytest
+
+
+def get_pdp(client):
+ req = client.get("/pdp")
+ pdp = utilities.get_json(req.data)
+ return req, pdp
+
+
+def add_pdp(client, data):
+ req = client.post("/pdp", data=json.dumps(data),
+ headers={'Content-Type': 'application/json'})
+ pdp = utilities.get_json(req.data)
+ return req, pdp
+
+
+def delete_pdp(client, key):
+ req = client.delete("/pdp/{}".format(key))
+ return req
+
+
+def delete_pdp_without_id(client):
+ req = client.delete("/pdp/{}".format(""))
+ return req
+
+
+def test_get_pdp():
+ client = utilities.register_client()
+ req, pdp = get_pdp(client)
+ assert req.status_code == 200
+ assert isinstance(pdp, dict)
+ assert "pdps" in pdp
+
+
+def test_add_pdp():
+ data = {
+ "name": "testuser",
+ "security_pipeline": ["policy_id_1", "policy_id_2"],
+ "keystone_project_id": "keystone_project_id",
+ "description": "description of testuser"
+ }
+ client = utilities.register_client()
+ req, pdp = add_pdp(client, data)
+ assert req.status_code == 200
+ assert isinstance(pdp, dict)
+ value = list(pdp["pdps"].values())[0]
+ assert "pdps" in pdp
+ assert value['name'] == "testuser"
+ assert value["description"] == "description of {}".format("testuser")
+ assert value["keystone_project_id"] == "keystone_project_id"
+
+
+def test_delete_pdp():
+ client = utilities.register_client()
+ request, pdp = get_pdp(client)
+ for key, value in pdp['pdps'].items():
+ if value['name'] == "testuser":
+ success_req = delete_pdp(client, key)
+ break
+ assert success_req.status_code == 200
diff --git a/moon_manager/tests/unit_python/conftest.py b/moon_manager/tests/unit_python/conftest.py
index 3f73f2da..902a41a2 100644
--- a/moon_manager/tests/unit_python/conftest.py
+++ b/moon_manager/tests/unit_python/conftest.py
@@ -35,7 +35,7 @@ CONF = {
"bind": "0.0.0.0",
"port": 8083,
"container": "wukongsun/moon_orchestrator:v4.3",
- "hostname": "interface"
+ "hostname": "orchestrator"
},
"pipeline": {
"interface": {
@@ -114,7 +114,7 @@ CONF = {
},
"messenger": {
"url": "rabbit://moon:p4sswOrd1@messenger:5672/moon"
- }
+ },
}
COMPONENTS = (
@@ -123,22 +123,50 @@ COMPONENTS = (
"database",
"slave",
"components/manager",
+ "components/orchestrator"
)
+PODS = {
+ "pods": {
+ "721760dd-de5f-11e7-8001-3863bbb766f3": [
+ {
+ "pdp_id": "b3d3e18abf3340e8b635fd49e6634ccd",
+ "port": 8080,
+ "genre": "interface",
+ "name": "interface-paltry",
+ "keystone_project_id": "a64beb1cc224474fb4badd43173e7101",
+ "namespace": "moon",
+ "container": "wukongsun/moon_interface:v4.3"
+ },
+ {
+ "pdp_id": "b3d3e18abf3340e8b635fd49e6634ccd",
+ "meta_rule_id": "f8f49a779ceb47b3ac810f01ef71b4e0",
+ "port": 8081,
+ "genre": "authz",
+ "name": "authz-economic",
+ "policy_id": "f8f49a779ceb47b3ac810f01ef71b4e0",
+ "keystone_project_id": "a64beb1cc224474fb4badd43173e7101",
+ "namespace": "moon",
+ "container": "wukongsun/moon_authz:v4.3"
+ }
+ ]
+ }
+}
+
def get_b64_conf(component=None):
if component in CONF:
return base64.b64encode(
json.dumps(
- CONF[component]).encode('utf-8')+b"\n").decode('utf-8')
+ CONF[component]).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')
+ CONF[key1][key2]).encode('utf-8') + b"\n").decode('utf-8')
else:
return base64.b64encode(
- json.dumps(CONF).encode('utf-8')+b"\n").decode('utf-8')
+ json.dumps(CONF).encode('utf-8') + b"\n").decode('utf-8')
@pytest.fixture(autouse=True)
@@ -150,7 +178,7 @@ def no_requests(monkeypatch):
m.register_uri(
'GET', 'http://consul:8500/v1/kv/{}'.format(component),
json=[{'Key': component, 'Value': get_b64_conf(component)}]
- )
+ )
m.register_uri(
'POST', 'http://keystone:5000/v3/auth/tokens',
headers={'X-Subject-Token': "111111111"}
@@ -169,10 +197,22 @@ def no_requests(monkeypatch):
)
m.register_uri(
'POST', 'http://keystone:5000/v3/users/',
- json={"users": [{
- "id": "1111111111111"
- }]}
+ json={"users": [{"id": "1111111111111"}]}
)
+ m.register_uri(
+ 'POST', 'http://orchestrator:8083/pods',
+ json=PODS,
+ headers={"content-type": "application/json"}
+ )
+ m.register_uri(
+ 'GET', 'http://orchestrator:8083/pods',
+ json=PODS
+ )
+ m.register_uri(
+ 'DELETE', 'http://orchestrator:8083/pods/{}'.format(list([PODS['pods'].keys()])[0]),
+ headers={"content-type": "application/json"}
+ )
+
print("Start populating the DB.")
from python_moondb.db_manager import init_engine, main
engine = init_engine()
@@ -181,7 +221,6 @@ def no_requests(monkeypatch):
print("End populating the DB.")
yield m
-
# @pytest.fixture(autouse=True, scope="session")
# def manage_database():
# from moon_db.db_manager import init_engine, run
@@ -189,5 +228,3 @@ def no_requests(monkeypatch):
# run("upgrade", logging.getLogger("db_manager"), engine)
# yield
# print("Will close the DB")
-
-