aboutsummaryrefslogtreecommitdiffstats
path: root/moon_manager/tests
diff options
context:
space:
mode:
authorMohamedAssem <mmagraby.ext@orange.com>2018-01-02 09:49:42 +0200
committerMohamedAssem <mmagraby.ext@orange.com>2018-01-02 09:49:42 +0200
commita63b301483041603ed35bb43e551af76c3add098 (patch)
tree57ce0bde37e8c8ec46e15b7c4e3dd77b1d6cd06d /moon_manager/tests
parent176674ec7b91ffccf99844a836fd928d92cc09b3 (diff)
add unittests for perimeter module
Change-Id: I67a930652dbac7de79d13f388de44778516a9d7f Signed-off-by: MohamedAssem <mmagraby.ext@orange.com>
Diffstat (limited to 'moon_manager/tests')
-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")