aboutsummaryrefslogtreecommitdiffstats
path: root/moon_manager/tests/unit_python/helpers/data_builder.py
diff options
context:
space:
mode:
Diffstat (limited to 'moon_manager/tests/unit_python/helpers/data_builder.py')
-rw-r--r--moon_manager/tests/unit_python/helpers/data_builder.py71
1 files changed, 47 insertions, 24 deletions
diff --git a/moon_manager/tests/unit_python/helpers/data_builder.py b/moon_manager/tests/unit_python/helpers/data_builder.py
index 91808cbe..e2799375 100644
--- a/moon_manager/tests/unit_python/helpers/data_builder.py
+++ b/moon_manager/tests/unit_python/helpers/data_builder.py
@@ -1,15 +1,21 @@
-# Copyright 2015 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'.
+# Software Name: MOON
+# Version: 5.4
+
+# SPDX-FileCopyrightText: Copyright (c) 2018-2020 Orange and its contributors
+# SPDX-License-Identifier: Apache-2.0
+
+# This software is distributed under the 'Apache License 2.0',
+# the text of which is available at 'http://www.apache.org/licenses/LICENSE-2.0.txt'
+# or see the "LICENSE" file for more details.
+
+
+import hug
from .category_helper import *
from .policy_helper import *
from .data_helper import *
from helpers import model_helper
from .meta_rule_helper import *
-import api.utilities as utilities
-import json
from uuid import uuid4
@@ -55,7 +61,7 @@ def create_pdp(policies_ids):
value = {
"name": "test_pdp",
"security_pipeline": policies_ids,
- "keystone_project_id": "keystone_project_id1",
+ "vim_project_id": "vim_project_id1",
"description": "...",
}
return value
@@ -96,7 +102,7 @@ def create_new_policy(subject_category_name=None, object_category_name=None,
def create_new_meta_rule(subject_category_name=None, object_category_name=None,
- action_category_name=None, meta_rule_name=None):
+ action_category_name=None, meta_rule_name=None, empty=None):
if not subject_category_name:
subject_category_name = "subjectCategory_" + uuid4().hex
if not object_category_name:
@@ -116,6 +122,12 @@ def create_new_meta_rule(subject_category_name=None, object_category_name=None,
"object_categories": [object_category_id],
"action_categories": [action_category_id]
}
+ if empty == 'subject':
+ value["subject_categories"] = []
+ if empty == 'object':
+ value["object_categories"] = []
+ if empty == 'action':
+ value["action_categories"] = []
meta_rule = add_meta_rule(value=value)
return subject_category_id, object_category_id, action_category_id, list(meta_rule.keys())[0]
@@ -179,7 +191,10 @@ def create_action_data(policy_id, category_id):
def get_policy_id_with_subject_assignment():
- client = utilities.register_client()
+ from moon_manager.api import assignments
+ from moon_utilities.auth_functions import get_api_key_for_user
+ auth_headers = {"X-Api-Key": get_api_key_for_user("admin")}
+
subject_category_id, object_category_id, action_category_id, meta_rule_id, policy_id = create_new_policy(
subject_category_name="subject_category1" + uuid4().hex,
object_category_name="object_category1" + uuid4().hex,
@@ -193,13 +208,16 @@ def get_policy_id_with_subject_assignment():
"category_id": subject_category_id,
"data_id": data_id
}
- client.post("/policies/{}/subject_assignments".format(policy_id), data=json.dumps(data),
- headers={'Content-Type': 'application/json'})
+ response = hug.test.post(assignments, "/policies/{}/subject_assignments/".format(policy_id),
+ body=data, headers=auth_headers)
return policy_id
def get_policy_id_with_object_assignment():
- client = utilities.register_client()
+ from moon_manager.api import assignments
+ from moon_utilities.auth_functions import get_api_key_for_user
+ auth_headers = {"X-Api-Key": get_api_key_for_user("admin")}
+
subject_category_id, object_category_id, action_category_id, meta_rule_id, policy_id = create_new_policy(
subject_category_name="subject_category1" + uuid4().hex,
object_category_name="object_category1" + uuid4().hex,
@@ -214,13 +232,16 @@ def get_policy_id_with_object_assignment():
"data_id": data_id
}
- client.post("/policies/{}/object_assignments".format(policy_id), data=json.dumps(data),
- headers={'Content-Type': 'application/json'})
+ hug.test.post(assignments, "policies/{}/object_assignments".format(policy_id), body=data,
+ headers=auth_headers)
return policy_id
def get_policy_id_with_action_assignment():
- client = utilities.register_client()
+ from moon_manager.api import assignments
+ from moon_utilities.auth_functions import get_api_key_for_user
+ auth_headers = {"X-Api-Key": get_api_key_for_user("admin")}
+
subject_category_id, object_category_id, action_category_id, meta_rule_id, policy_id = create_new_policy(
subject_category_name="subject_category1" + uuid4().hex,
object_category_name="object_category1" + uuid4().hex,
@@ -234,12 +255,16 @@ def get_policy_id_with_action_assignment():
"category_id": action_category_id,
"data_id": data_id
}
- client.post("/policies/{}/action_assignments".format(policy_id), data=json.dumps(data),
- headers={'Content-Type': 'application/json'})
+ hug.test.post(assignments, "policies/{}/action_assignments".format(policy_id), body =data,
+ headers=auth_headers)
return policy_id
-def add_rules(client):
+def add_rules():
+ from moon_manager.api import rules
+ from moon_utilities.auth_functions import get_api_key_for_user
+ auth_headers = {"X-Api-Key": get_api_key_for_user("admin")}
+
sub_id, obj_id, act_id, meta_rule_id, policy_id = create_new_policy("sub_cat" + uuid4().hex,
"obj_cat" + uuid4().hex,
"act_cat" + uuid4().hex)
@@ -249,12 +274,10 @@ def add_rules(client):
data = {
"meta_rule_id": meta_rule_id,
"rule": [sub_data_id, obj_data_id, act_data_id],
- "instructions": (
+ "instructions": [
{"decision": "grant"},
- ),
+ ],
"enabled": True
}
- req = client.post("/policies/{}/rules".format(policy_id), data=json.dumps(data),
- headers={'Content-Type': 'application/json'})
- rules = utilities.get_json(req.data)
- return req, rules, policy_id
+ req = hug.test.post(rules, "policies/{}/rules".format(policy_id), body=data, headers=auth_headers)
+ return req, req.data, policy_id