aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRuan HE <ruan.he@orange.com>2018-01-02 08:31:14 +0000
committerGerrit Code Review <gerrit@opnfv.org>2018-01-02 08:31:14 +0000
commit8e2c9d229720d3f6fd6e764f5a801c8bbe82a201 (patch)
tree3bbe234229f7f397a2b437848f19b39a9a3e64a6
parent0b785d7a9c075e45245edbbdc1415680c0818c5d (diff)
parenta63b301483041603ed35bb43e551af76c3add098 (diff)
Merge "add unittests for perimeter module"
-rw-r--r--moon_manager/tests/unit_python/api/test_perimeter.py107
1 files changed, 107 insertions, 0 deletions
diff --git a/moon_manager/tests/unit_python/api/test_perimeter.py b/moon_manager/tests/unit_python/api/test_perimeter.py
index 18d3837a..d255ae65 100644
--- a/moon_manager/tests/unit_python/api/test_perimeter.py
+++ b/moon_manager/tests/unit_python/api/test_perimeter.py
@@ -39,6 +39,18 @@ def add_subjects(client, name):
return subjects
+def add_subjects_without_name(client, name):
+ data = {
+ "name": name,
+ "description": "description of {}".format(name),
+ "password": "password for {}".format(name),
+ "email": "{}@moon".format(name)
+ }
+ req = client.post("/subjects", data=json.dumps(data),
+ headers={'Content-Type': 'application/json'})
+ assert req.status_code == 500
+
+
def delete_subject(client, name):
subjects = get_subjects(client)
for key, value in subjects['subjects'].items():
@@ -56,4 +68,99 @@ def test_subject():
client = server.app.test_client()
get_subjects(client)
add_subjects(client, "testuser")
+ add_subjects_without_name(client, "")
delete_subject(client, "testuser")
+
+
+def get_objects(client):
+ req = client.get("/objects")
+ assert req.status_code == 200
+ objects = get_json(req.data)
+ assert isinstance(objects, dict)
+ assert "objects" in objects
+ return objects
+
+
+def add_objects(client, name):
+ data = {
+ "name": name,
+ "description": "description of {}".format(name),
+ }
+ req = client.post("/objects", data=json.dumps(data),
+ headers={'Content-Type': 'application/json'})
+ assert req.status_code == 200
+ objects = get_json(req.data)
+ assert isinstance(objects, dict)
+ key = list(objects["objects"].keys())[0]
+ value = list(objects["objects"].values())[0]
+ assert "objects" in objects
+ assert value['name'] == name
+ assert value["description"] == "description of {}".format(name)
+ return objects
+
+
+def delete_objects(client, name):
+ objects = get_objects(client)
+ for key, value in objects['objects'].items():
+ if value['name'] == name:
+ req = client.delete("/objects/{}".format(key))
+ assert req.status_code == 200
+ break
+ objects = get_objects(client)
+ assert name not in [x['name'] for x in objects["objects"].values()]
+
+
+def test_objects():
+ import moon_manager.server
+ server = moon_manager.server.main()
+ client = server.app.test_client()
+ get_objects(client)
+ add_objects(client, "testuser")
+ delete_objects(client, "testuser")
+
+
+def get_actions(client):
+ req = client.get("/actions")
+ assert req.status_code == 200
+ actions = get_json(req.data)
+ assert isinstance(actions, dict)
+ assert "actions" in actions
+ return actions
+
+
+def add_actions(client, name):
+ data = {
+ "name": name,
+ "description": "description of {}".format(name),
+ }
+ req = client.post("/actions", data=json.dumps(data),
+ headers={'Content-Type': 'application/json'})
+ assert req.status_code == 200
+ actions = get_json(req.data)
+ assert isinstance(actions, dict)
+ key = list(actions["actions"].keys())[0]
+ value = list(actions["actions"].values())[0]
+ assert "actions" in actions
+ assert value['name'] == name
+ assert value["description"] == "description of {}".format(name)
+ return actions
+
+
+def delete_actions(client, name):
+ actions = get_actions(client)
+ for key, value in actions['actions'].items():
+ if value['name'] == name:
+ req = client.delete("/actions/{}".format(key))
+ assert req.status_code == 200
+ break
+ actions = get_actions(client)
+ assert name not in [x['name'] for x in actions["actions"].values()]
+
+
+def test_actions():
+ import moon_manager.server
+ server = moon_manager.server.main()
+ client = server.app.test_client()
+ get_actions(client)
+ add_actions(client, "testuser")
+ delete_actions(client, "testuser")