aboutsummaryrefslogtreecommitdiffstats
path: root/moon_orchestrator/tests/unit_python/test_pods.py
diff options
context:
space:
mode:
authorThomas Duval <thomas.duval@orange.com>2020-06-03 10:06:52 +0200
committerThomas Duval <thomas.duval@orange.com>2020-06-03 10:06:52 +0200
commit7bb53c64da2dcf88894bfd31503accdd81498f3d (patch)
tree4310e12366818af27947b5e2c80cb162da93a4b5 /moon_orchestrator/tests/unit_python/test_pods.py
parentcbea4e360e9bfaa9698cf7c61c83c96a1ba89b8c (diff)
Update to new version 5.4HEADstable/jermamaster
Signed-off-by: Thomas Duval <thomas.duval@orange.com> Change-Id: Idcd868133d75928a1ffd74d749ce98503e0555ea
Diffstat (limited to 'moon_orchestrator/tests/unit_python/test_pods.py')
-rw-r--r--moon_orchestrator/tests/unit_python/test_pods.py287
1 files changed, 0 insertions, 287 deletions
diff --git a/moon_orchestrator/tests/unit_python/test_pods.py b/moon_orchestrator/tests/unit_python/test_pods.py
deleted file mode 100644
index 5e1b3767..00000000
--- a/moon_orchestrator/tests/unit_python/test_pods.py
+++ /dev/null
@@ -1,287 +0,0 @@
-import json
-from mock_pods import patch_k8s
-from utilities import get_json
-
-
-def test_get_pods(context, monkeypatch):
- patch_k8s(monkeypatch)
-
- import moon_orchestrator.server
- server = moon_orchestrator.server.create_server()
- _client = server.app.test_client()
- req = _client.get("/pods")
- assert req.status_code == 200
- assert req.data
- data = get_json(req.data)
- assert isinstance(data, dict)
- assert "pods" in data
- assert data["pods"]
-
-
-def test_get_pods_failure(context, monkeypatch):
- patch_k8s(monkeypatch)
-
- import moon_orchestrator.server
- server = moon_orchestrator.server.create_server()
- _client = server.app.test_client()
- req = _client.get("/pods/invalid")
- assert req.status_code == 200
- assert req.data
- data = get_json(req.data)
- assert isinstance(data, dict)
- assert not data["pods"]
-
-############################ /post ############################
-
-def test_add_pods_with_pipeline(context, monkeypatch):
- patch_k8s(monkeypatch)
-
- import moon_orchestrator.server
- server = moon_orchestrator.server.create_server()
- _client = server.app.test_client()
- data = {
- "keystone_project_id": context.get('project_id'),
- "pdp_id": context.get('pdp_id'),
- "security_pipeline": context.get('security_pipeline'),
- }
- req = _client.post("/pods", data=json.dumps(data),
- headers={'Content-Type': 'application/json'})
- assert req.status_code == 200
- assert req.data
- data = get_json(req.data)
- assert isinstance(data, dict)
- assert "pods" in data
- assert data["pods"]
-
-
-def test_add_pods_without_pipeline_with_bad_slave_name_failure(context, monkeypatch):
- patch_k8s(monkeypatch)
-
- import moon_orchestrator.server
- server = moon_orchestrator.server.create_server()
- _client = server.app.test_client()
- data = {
- "slave_name": "test",
- }
- req = _client.post("/pods", data=json.dumps(data),
- headers={'Content-Type': 'application/json'})
- assert req.status_code == 400
- assert req.data
- data = get_json(req.data)
- assert isinstance(data, dict)
- assert 'The slave is unknown.' in data['message']
-
-
-def test_add_pods_without_pipeline_with_good_slave_name(context, monkeypatch):
- patch_k8s(monkeypatch)
-
- import moon_orchestrator.server
- server = moon_orchestrator.server.create_server()
- _client = server.app.test_client()
- data = {
- "slave_name": "active_context",
- }
- req = _client.post("/pods", data=json.dumps(data),
- headers={'Content-Type': 'application/json'})
- assert req.status_code == 200
- assert req.data
- data = get_json(req.data)
- assert isinstance(data, dict)
- assert "pods" in data
- assert data["pods"]
-
-
-def test_add_pods_without_pipeline_without_slave_name_failure(context, monkeypatch):
- patch_k8s(monkeypatch)
-
- import moon_orchestrator.server
- server = moon_orchestrator.server.create_server()
- _client = server.app.test_client()
- data = {
- }
- req = _client.post("/pods", data=json.dumps(data),
- headers={'Content-Type': 'application/json'})
- assert req.status_code == 400
- assert req.data
- data = get_json(req.data)
- assert isinstance(data, dict)
- assert 'The slave is unknown.' in data['message']
-
-
-def test_add_pods_with_no_data_failure(context, monkeypatch):
- patch_k8s(monkeypatch)
- import moon_orchestrator.server
- server = moon_orchestrator.server.create_server()
- _client = server.app.test_client()
- req = _client.post("/pods", data=json.dumps({}),
- headers={'Content-Type': 'application/json'})
- assert req.status_code == 400
- assert req.data
- data = get_json(req.data)
- assert 'The slave is unknown.' in data['message']
-
-
-def test_add_pods_with_no_policies_no_models(context, monkeypatch, no_requests):
- patch_k8s(monkeypatch)
-
- import moon_orchestrator.server
- server = moon_orchestrator.server.create_server()
- _client = server.app.test_client()
- no_requests.get("http://manager:8082/policies",
- json={'policies': {}})
-
- no_requests.get("http://manager:8082/models",
- json={'models': {}})
- data = {
- "keystone_project_id": context.get('project_id'),
- "pdp_id": context.get('pdp_id'),
- "security_pipeline": context.get('security_pipeline'),
- }
- req = _client.post("/pods", data=json.dumps(data),
- headers={'Content-Type': 'application/json'})
- assert req.status_code == 200
-
-
-def test_add_pods_with_empty_pdp_id_and_keystone_project_id_failure(context, monkeypatch):
- patch_k8s(monkeypatch)
-
- import moon_orchestrator.server
- server = moon_orchestrator.server.create_server()
- _client = server.app.test_client()
- data = {
- "keystone_project_id": "",
- "pdp_id": "",
- "security_pipeline": context.get('security_pipeline'),
- }
- req = _client.post("/pods", data=json.dumps(data),
- headers={'Content-Type': 'application/json'})
- assert req.status_code == 400
- assert req.data
- data = get_json(req.data)
- assert "The pdp is unknown." in data['message']
-
-
-def test_add_pods_with_empty_security_pipeline_failure(context, monkeypatch):
- patch_k8s(monkeypatch)
-
- import moon_orchestrator.server
- server = moon_orchestrator.server.create_server()
- _client = server.app.test_client()
- data = {
- "keystone_project_id": context.get('project_id'),
- "pdp_id": context.get('pdp_id'),
- "security_pipeline": "",
- }
- req = _client.post("/pods", data=json.dumps(data),
- headers={'Content-Type': 'application/json'})
- assert req.status_code == 400
- assert req.data
- data = get_json(req.data)
- assert 'The policy is unknown.' in data['message']
-
-
-def test_add_different_pods_with_same_pdp_id(context, monkeypatch):
- patch_k8s(monkeypatch)
-
- import moon_orchestrator.server
- server = moon_orchestrator.server.create_server()
- _client = server.app.test_client()
- data = {
- "keystone_project_id": context.get('project_id'),
- "pdp_id": context.get('pdp_id'),
- "security_pipeline": context.get('security_pipeline'),
- }
- req = _client.post("/pods", data=json.dumps(data),
- headers={'Content-Type': 'application/json'})
- data["keystone_project_id"] = data["keystone_project_id"] + "x"
- req = _client.post("/pods", data=json.dumps(data),
- headers={'Content-Type': 'application/json'})
- assert req.status_code == 200
-
-
-def test_add_different_pods_with_same_keystone_project_id_failure(context, monkeypatch):
- patch_k8s(monkeypatch)
-
- import moon_orchestrator.server
- server = moon_orchestrator.server.create_server()
- _client = server.app.test_client()
- data = {
- "keystone_project_id": context.get('project_id'),
- "pdp_id": context.get('pdp_id'),
- "security_pipeline": context.get('security_pipeline'),
- }
- req = _client.post("/pods", data=json.dumps(data),
- headers={'Content-Type': 'application/json'})
- data["pdp_id"] = data["pdp_id"] + "xyz"
- req = _client.post("/pods", data=json.dumps(data),
- headers={'Content-Type': 'application/json'})
- assert req.status_code == 409
- data = get_json(req.data)
- assert isinstance(data, dict)
- assert 'A Pipeline already exist for the specified slave.' in data['message']
-
-
-def test_add_pod_with_slave_more_than_once_failure(context, monkeypatch):
- patch_k8s(monkeypatch)
-
- import moon_orchestrator.server
- server = moon_orchestrator.server.create_server()
- _client = server.app.test_client()
- data = {
- "slave_name": "active_context",
- }
- req = _client.post("/pods", data=json.dumps(data),
- headers={'Content-Type': 'application/json'})
- req = _client.post("/pods", data=json.dumps(data),
- headers={'Content-Type': 'application/json'})
- assert req.status_code == 409
- assert req.data
- data = get_json(req.data)
- assert isinstance(data, dict)
- assert 'A Wrapper already exist for the specified slave.' in data['message']
-
-############################ /delete ############################
-
-def test_delete_pod_valid_uuid(context, monkeypatch):
- patch_k8s(monkeypatch)
-
- import moon_orchestrator.server
- server = moon_orchestrator.server.create_server()
- _client = server.app.test_client()
- data = {
- "keystone_project_id": context.get('project_id'),
- "pdp_id": context.get('pdp_id'),
- "security_pipeline": context.get('security_pipeline'),
- }
- req = _client.post("/pods", data=json.dumps(data),
- headers={'Content-Type': 'application/json'})
- assert req.status_code == 200
- assert req.data
- data = get_json(req.data)
- for key in data["pods"]:
- req = _client.delete("/pods/{}".format(key))
- assert req.status_code == 200
-
-def test_delete_pod_Invalid_uuid_failure(context, monkeypatch):
- patch_k8s(monkeypatch)
-
- import moon_orchestrator.server
- server = moon_orchestrator.server.create_server()
- _client = server.app.test_client()
-
- req = _client.delete("/pods/invalid")
- assert req.status_code == 400
- data = get_json(req.data)
- assert 'The slave is unknown.' in data['message']
-
-def test_delete_pod_without_uuid_failure(context, monkeypatch):
- patch_k8s(monkeypatch)
-
- import moon_orchestrator.server
- server = moon_orchestrator.server.create_server()
- _client = server.app.test_client()
-
- req = _client.delete("/pods/")
- assert req.status_code == 400
- data = get_json(req.data)
- assert 'The slave is unknown.' in data['message'] \ No newline at end of file