aboutsummaryrefslogtreecommitdiffstats
path: root/moon_manager/tests
diff options
context:
space:
mode:
authorMohamedAssem <mmagraby.ext@orange.com>2018-01-04 10:53:25 +0200
committerMohamedAssem <mmagraby.ext@orange.com>2018-01-04 10:53:25 +0200
commitf1da426dedd4320793b5406616147e0f91699265 (patch)
tree1a416d674aa296b4bf3798b9986dc1f230a69d79 /moon_manager/tests
parent9165dfcf59b1325f317e8a412e5f775855354300 (diff)
add unittest for policies in moon_manager
Change-Id: I5c6beb10484013df9853c217d00d64bda51c5803 Signed-off-by: MohamedAssem <mmagraby.ext@orange.com>
Diffstat (limited to 'moon_manager/tests')
-rw-r--r--moon_manager/tests/unit_python/api/test_policies.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/moon_manager/tests/unit_python/api/test_policies.py b/moon_manager/tests/unit_python/api/test_policies.py
new file mode 100644
index 00000000..4d4e387e
--- /dev/null
+++ b/moon_manager/tests/unit_python/api/test_policies.py
@@ -0,0 +1,69 @@
+import json
+import api.utilities as utilities
+
+
+def get_policies(client):
+ req = client.get("/policies")
+ policies = utilities.get_json(req.data)
+ return req, policies
+
+
+def add_policies(client, name):
+ data = {
+ "name": name,
+ "description": "description of {}".format(name),
+ "model_id": "modelId",
+ "genre": "genre"
+ }
+ req = client.post("/policies", data=json.dumps(data),
+ headers={'Content-Type': 'application/json'})
+ policies = utilities.get_json(req.data)
+ return req, policies
+
+
+def delete_policies(client, name):
+ request, policies = get_policies(client)
+ for key, value in policies['policies'].items():
+ if value['name'] == name:
+ req = client.delete("/policies/{}".format(key))
+ break
+ return req
+
+
+def delete_policies_without_id(client):
+ req = client.delete("/policies/{}".format(""))
+ return req
+
+
+def test_get_policies():
+ client = utilities.register_client()
+ req, policies = get_policies(client)
+ assert req.status_code == 200
+ assert isinstance(policies, dict)
+ assert "policies" in policies
+
+
+def test_add_policies():
+ client = utilities.register_client()
+ req, policies = add_policies(client, "testuser")
+ assert req.status_code == 200
+ assert isinstance(policies, dict)
+ value = list(policies["policies"].values())[0]
+ assert "policies" in policies
+ assert value['name'] == "testuser"
+ assert value["description"] == "description of {}".format("testuser")
+ assert value["model_id"] == "modelId"
+ assert value["genre"] == "genre"
+
+
+def test_delete_policies():
+ client = utilities.register_client()
+ req = delete_policies(client, "testuser")
+ assert req.status_code == 200
+
+
+def test_delete_policies_without_id():
+ client = utilities.register_client()
+ req = delete_policies_without_id(client)
+ assert req.status_code == 500
+