From d425d4edf13ed389cd34113bd9fd78eaa0a08c20 Mon Sep 17 00:00:00 2001 From: Thomas Duval Date: Wed, 14 Mar 2018 11:25:06 +0100 Subject: Fix bugs due to the modification of python_moondb Change-Id: Id3855a6e8da9f8ef942c7a34a3e8da4f87be4c9e --- .../unit_python/api/import_export_utilities.py | 24 +++++++++++++++++++--- moon_manager/tests/unit_python/api/test_data.py | 17 +++++++++++---- moon_manager/tests/unit_python/api/test_export.py | 6 +++++- moon_manager/tests/unit_python/api/test_import.py | 9 +++++++- 4 files changed, 47 insertions(+), 9 deletions(-) (limited to 'moon_manager/tests/unit_python/api') 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 15c3e333..98586d02 100644 --- a/moon_manager/tests/unit_python/api/import_export_utilities.py +++ b/moon_manager/tests/unit_python/api/import_export_utilities.py @@ -1,3 +1,8 @@ +# 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 api.utilities as utilities import api.test_models as test_models import api.test_policies as test_policies @@ -7,6 +12,10 @@ import api.test_data as test_data import api.meta_rules_test as test_meta_rules import api.test_assignemnt as test_assignments import api.test_rules as test_rules +import logging + +logger = logging.getLogger("moon.manager.test.api." + __name__) + def clean_models(client): req, models = test_models.get_models(client) @@ -25,9 +34,11 @@ def clean_policies(client): def clean_subjects(client): subjects = test_perimeter.get_subjects(client) + logger.info("subjects {}".format(subjects)) for key in subjects["subjects"]: subject = subjects["subjects"][key] policy_keys = subject["policy_list"] + logger.info("subjects policy_keys {}".format(policy_keys)) for policy_key in policy_keys: client.delete("/policies/{}/subjects/{}".format(policy_key,key)) client.delete("/subjects/{}".format(key)) @@ -36,9 +47,11 @@ def clean_subjects(client): def clean_objects(client): objects = test_perimeter.get_objects(client) + logger.info("objects {}".format(objects)) for key in objects["objects"]: object_ = objects["objects"][key] policy_keys = object_["policy_list"] + logger.info("objects policy_keys {}".format(policy_keys)) for policy_key in policy_keys: print("/policies/{}/objects/{}".format(policy_key, key)) req = client.delete("/policies/{}/objects/{}".format(policy_key, key)) @@ -48,9 +61,11 @@ def clean_objects(client): def clean_actions(client): actions = test_perimeter.get_actions(client) + logger.info("objects {}".format(actions)) for key in actions["actions"]: action = actions["actions"][key] policy_keys = action["policy_list"] + logger.info("action policy_keys {}".format(policy_keys)) for policy_key in policy_keys: client.delete("/policies/{}/actions/{}".format(policy_key, key)) client.delete("/actions/{}".format(key)) @@ -59,19 +74,21 @@ def clean_actions(client): def clean_subject_categories(client): req, categories = test_categories.get_subject_categories(client) - print(categories) + logger.info(categories) for key in categories["subject_categories"]: client.delete("/subject_categories/{}".format(key)) def clean_object_categories(client): req, categories = test_categories.get_object_categories(client) + logger.info(categories) for key in categories["object_categories"]: client.delete("/object_categories/{}".format(key)) def clean_action_categories(client): req, categories = test_categories.get_action_categories(client) + logger.info(categories) for key in categories["action_categories"]: client.delete("/action_categories/{}".format(key)) @@ -174,8 +191,9 @@ def clean_all(client): clean_object_data(client) clean_action_data(client) - clean_policies(client) - clean_models(client) clean_actions(client) clean_objects(client) clean_subjects(client) + + clean_policies(client) + clean_models(client) \ No newline at end of file diff --git a/moon_manager/tests/unit_python/api/test_data.py b/moon_manager/tests/unit_python/api/test_data.py index f636aaa5..724f919f 100644 --- a/moon_manager/tests/unit_python/api/test_data.py +++ b/moon_manager/tests/unit_python/api/test_data.py @@ -1,3 +1,8 @@ +# 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 api.utilities as utilities import json @@ -106,8 +111,12 @@ def test_add_object_data(): value = object_data["object_data"]['data'] assert "object_data" in object_data id = list(value.keys())[0] - assert value[id]['value']['name'] == "testuser" - assert value[id]['value']['description'] == "description of {}".format("testuser") + print("-----------------------") + print(id) + print(value[id]) + print("-----------------------") + assert value[id]['name'] == "testuser" + assert value[id]['description'] == "description of {}".format("testuser") def test_delete_object_data(): @@ -164,8 +173,8 @@ def test_add_action_data(): value = action_data["action_data"]['data'] assert "action_data" in action_data id = list(value.keys())[0] - assert value[id]['value']['name'] == "testuser" - assert value[id]['value']['description'] == "description of {}".format("testuser") + assert value[id]['name'] == "testuser" + assert value[id]['description'] == "description of {}".format("testuser") def test_delete_action_data(): diff --git a/moon_manager/tests/unit_python/api/test_export.py b/moon_manager/tests/unit_python/api/test_export.py index 0b9cd6a7..122ab927 100644 --- a/moon_manager/tests/unit_python/api/test_export.py +++ b/moon_manager/tests/unit_python/api/test_export.py @@ -1,3 +1,8 @@ +# 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 import api.import_export_utilities as import_export_utilities @@ -169,7 +174,6 @@ def test_export_subject_object_action_categories(): req = client.get("/export") assert req.status_code == 200 data = utilities.get_json(req.data) - print(data) assert "content" in data type_elements = ["subject", "object", "action"] for type_element in type_elements: diff --git a/moon_manager/tests/unit_python/api/test_import.py b/moon_manager/tests/unit_python/api/test_import.py index da7872dc..4e970a0e 100644 --- a/moon_manager/tests/unit_python/api/test_import.py +++ b/moon_manager/tests/unit_python/api/test_import.py @@ -1,3 +1,8 @@ +# 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 api.utilities as utilities import api.test_models as test_models import api.test_policies as test_policies @@ -512,4 +517,6 @@ def test_import_subject_object_action_data(): def test_clean(): client = utilities.register_client() - import_export_utilities.clean_all(client) \ No newline at end of file + import_export_utilities.clean_all(client) + #restore the database as previously + utilities.get_policy_id() \ No newline at end of file -- cgit 1.2.3-korg