diff options
author | Thomas Duval <thomas.duval@orange.com> | 2017-11-28 14:41:57 +0100 |
---|---|---|
committer | Thomas Duval <thomas.duval@orange.com> | 2017-11-28 14:41:57 +0100 |
commit | 2c43d2766b0139493a59c86dfa777a9aa4a38f43 (patch) | |
tree | 4a1a9eb0eb9bfc7dde5f2ed7b624398e42384dcd /moonv4/moon_manager/tests/api | |
parent | 920a49cfa055733d575282973e23558c33087a4a (diff) |
Add examples of unittest with pytest for Moon Manager
Change-Id: I555d8d60985982f4c1c5b9c12101c0f8d9ce3b10
Diffstat (limited to 'moonv4/moon_manager/tests/api')
-rw-r--r-- | moonv4/moon_manager/tests/api/__init__.py | 0 | ||||
-rw-r--r-- | moonv4/moon_manager/tests/api/test_perimeter.py | 59 |
2 files changed, 59 insertions, 0 deletions
diff --git a/moonv4/moon_manager/tests/api/__init__.py b/moonv4/moon_manager/tests/api/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/moonv4/moon_manager/tests/api/__init__.py diff --git a/moonv4/moon_manager/tests/api/test_perimeter.py b/moonv4/moon_manager/tests/api/test_perimeter.py new file mode 100644 index 00000000..18d3837a --- /dev/null +++ b/moonv4/moon_manager/tests/api/test_perimeter.py @@ -0,0 +1,59 @@ +# import moon_manager +# import moon_manager.api +import json + + +def get_json(data): + return json.loads(data.decode("utf-8")) + + +def get_subjects(client): + req = client.get("/subjects") + assert req.status_code == 200 + subjects = get_json(req.data) + assert isinstance(subjects, dict) + assert "subjects" in subjects + return subjects + + +def add_subjects(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 == 200 + subjects = get_json(req.data) + assert isinstance(subjects, dict) + key = list(subjects["subjects"].keys())[0] + value = list(subjects["subjects"].values())[0] + assert "subjects" in subjects + assert key == "1111111111111" + assert value['id'] == "1111111111111" + assert value['name'] == name + assert value["description"] == "description of {}".format(name) + assert value["email"] == "{}@moon".format(name) + return subjects + + +def delete_subject(client, name): + subjects = get_subjects(client) + for key, value in subjects['subjects'].items(): + if value['name'] == name: + req = client.delete("/subjects/{}".format(key)) + assert req.status_code == 200 + break + subjects = get_subjects(client) + assert name not in [x['name'] for x in subjects["subjects"].values()] + + +def test_subject(): + import moon_manager.server + server = moon_manager.server.main() + client = server.app.test_client() + get_subjects(client) + add_subjects(client, "testuser") + delete_subject(client, "testuser") |