From 1c249823b9a15d4dd3e2e5eae90c09131bc7f09b Mon Sep 17 00:00:00 2001 From: ReemMahmoud Date: Wed, 21 Mar 2018 12:49:05 +0200 Subject: Rename test_models of unit_python Add licences in some files. Change-Id: I7c473efcdb228cc030501328d93b5a6265917591 Signed-off-by: ReemMahmoud --- .../unit_python/api/import_export_utilities.py | 2 +- moon_manager/tests/unit_python/api/test_import.py | 2 +- moon_manager/tests/unit_python/api/test_models.py | 76 -------------------- .../tests/unit_python/api/test_policies.py | 13 +++- .../tests/unit_python/api/test_unit_models.py | 81 ++++++++++++++++++++++ 5 files changed, 93 insertions(+), 81 deletions(-) delete mode 100644 moon_manager/tests/unit_python/api/test_models.py create mode 100644 moon_manager/tests/unit_python/api/test_unit_models.py (limited to 'moon_manager/tests/unit_python') diff --git a/moon_manager/tests/unit_python/api/import_export_utilities.py b/moon_manager/tests/unit_python/api/import_export_utilities.py index 98586d02..3c921e21 100644 --- a/moon_manager/tests/unit_python/api/import_export_utilities.py +++ b/moon_manager/tests/unit_python/api/import_export_utilities.py @@ -4,7 +4,7 @@ # or at 'http://www.apache.org/licenses/LICENSE-2.0'. import api.utilities as utilities -import api.test_models as test_models +import api.test_unit_models as test_models import api.test_policies as test_policies import api.test_perimeter as test_perimeter import api.meta_data_test as test_categories diff --git a/moon_manager/tests/unit_python/api/test_import.py b/moon_manager/tests/unit_python/api/test_import.py index 4e970a0e..3c45f8a1 100644 --- a/moon_manager/tests/unit_python/api/test_import.py +++ b/moon_manager/tests/unit_python/api/test_import.py @@ -4,7 +4,7 @@ # or at 'http://www.apache.org/licenses/LICENSE-2.0'. import api.utilities as utilities -import api.test_models as test_models +import api.test_unit_models as test_models import api.test_policies as test_policies import api.test_perimeter as test_perimeter import api.meta_data_test as test_categories diff --git a/moon_manager/tests/unit_python/api/test_models.py b/moon_manager/tests/unit_python/api/test_models.py deleted file mode 100644 index b80e19f4..00000000 --- a/moon_manager/tests/unit_python/api/test_models.py +++ /dev/null @@ -1,76 +0,0 @@ -import json -import api.utilities as utilities - - -def get_models(client): - req = client.get("/models") - models = utilities.get_json(req.data) - return req, models - - -def add_models(client, name): - data = { - "name": name, - "description": "description of {}".format(name), - "meta_rules": ["meta_rule_id1", "meta_rule_id2"] - } - req = client.post("/models", data=json.dumps(data), - headers={'Content-Type': 'application/json'}) - models = utilities.get_json(req.data) - return req, models - - -def delete_models(client, name): - request, models = get_models(client) - for key, value in models['models'].items(): - if value['name'] == name: - req = client.delete("/models/{}".format(key)) - break - return req - - -def delete_models_without_id(client): - req = client.delete("/models/{}".format("")) - return req - - -def clean_models(): - client = utilities.register_client() - req, models= get_models(client) - for key, value in models['models'].items(): - print(key) - print(value) - client.delete("/models/{}".format(key)) - -def test_get_models(): - client = utilities.register_client() - req, models= get_models(client) - assert req.status_code == 200 - assert isinstance(models, dict) - assert "models" in models - - -def test_add_models(): - clean_models() - client = utilities.register_client() - req, models = add_models(client, "testuser") - assert req.status_code == 200 - assert isinstance(models, dict) - value = list(models["models"].values())[0] - assert "models" in models - assert value['name'] == "testuser" - assert value["description"] == "description of {}".format("testuser") - assert value["meta_rules"][0] == "meta_rule_id1" - - -def test_delete_models(): - client = utilities.register_client() - req = delete_models(client, "testuser") - assert req.status_code == 200 - - -def test_delete_models_without_id(): - client = utilities.register_client() - req = delete_models_without_id(client) - assert req.status_code == 500 - diff --git a/moon_manager/tests/unit_python/api/test_policies.py b/moon_manager/tests/unit_python/api/test_policies.py index 4d4e387e..40be35e6 100644 --- a/moon_manager/tests/unit_python/api/test_policies.py +++ b/moon_manager/tests/unit_python/api/test_policies.py @@ -1,5 +1,11 @@ +# Copyright 2018 Open Platform for NFV Project, Inc. and its contributors +# This software is distributed under the terms and conditions of the 'Apache-2.0' +# license which can be found in the file 'LICENSE' in this package distribution +# or at 'http://www.apache.org/licenses/LICENSE-2.0'. + import json import api.utilities as utilities +from uuid import uuid4 def get_policies(client): @@ -45,13 +51,14 @@ def test_get_policies(): def test_add_policies(): client = utilities.register_client() - req, policies = add_policies(client, "testuser") + policy_name = "testuser" + uuid4().hex + req, policies = add_policies(client, policy_name) 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['name'] == policy_name + assert value["description"] == "description of {}".format(policy_name) assert value["model_id"] == "modelId" assert value["genre"] == "genre" diff --git a/moon_manager/tests/unit_python/api/test_unit_models.py b/moon_manager/tests/unit_python/api/test_unit_models.py new file mode 100644 index 00000000..6f97b1ae --- /dev/null +++ b/moon_manager/tests/unit_python/api/test_unit_models.py @@ -0,0 +1,81 @@ +# Copyright 2018 Open Platform for NFV Project, Inc. and its contributors +# This software is distributed under the terms and conditions of the 'Apache-2.0' +# license which can be found in the file 'LICENSE' in this package distribution +# or at 'http://www.apache.org/licenses/LICENSE-2.0'. + +import json +import api.utilities as utilities + + +def get_models(client): + req = client.get("/models") + models = utilities.get_json(req.data) + return req, models + + +def add_models(client, name): + data = { + "name": name, + "description": "description of {}".format(name), + "meta_rules": ["meta_rule_id1", "meta_rule_id2"] + } + req = client.post("/models", data=json.dumps(data), + headers={'Content-Type': 'application/json'}) + models = utilities.get_json(req.data) + return req, models + + +def delete_models(client, name): + request, models = get_models(client) + for key, value in models['models'].items(): + if value['name'] == name: + req = client.delete("/models/{}".format(key)) + break + return req + + +def delete_models_without_id(client): + req = client.delete("/models/{}".format("")) + return req + + +def clean_models(): + client = utilities.register_client() + req, models= get_models(client) + for key, value in models['models'].items(): + print(key) + print(value) + client.delete("/models/{}".format(key)) + +def test_get_models(): + client = utilities.register_client() + req, models= get_models(client) + assert req.status_code == 200 + assert isinstance(models, dict) + assert "models" in models + + +def test_add_models(): + clean_models() + client = utilities.register_client() + req, models = add_models(client, "testuser") + assert req.status_code == 200 + assert isinstance(models, dict) + value = list(models["models"].values())[0] + assert "models" in models + assert value['name'] == "testuser" + assert value["description"] == "description of {}".format("testuser") + assert value["meta_rules"][0] == "meta_rule_id1" + + +def test_delete_models(): + client = utilities.register_client() + req = delete_models(client, "testuser") + assert req.status_code == 200 + + +def test_delete_models_without_id(): + client = utilities.register_client() + req = delete_models_without_id(client) + assert req.status_code == 500 + -- cgit 1.2.3-korg