aboutsummaryrefslogtreecommitdiffstats
path: root/old/moon_wrapper/tests/unit_python/api
diff options
context:
space:
mode:
authorThomas Duval <thomas.duval@orange.com>2020-06-03 10:06:52 +0200
committerThomas Duval <thomas.duval@orange.com>2020-06-03 10:06:52 +0200
commit7bb53c64da2dcf88894bfd31503accdd81498f3d (patch)
tree4310e12366818af27947b5e2c80cb162da93a4b5 /old/moon_wrapper/tests/unit_python/api
parentcbea4e360e9bfaa9698cf7c61c83c96a1ba89b8c (diff)
Update to new version 5.4HEADstable/jermamaster
Signed-off-by: Thomas Duval <thomas.duval@orange.com> Change-Id: Idcd868133d75928a1ffd74d749ce98503e0555ea
Diffstat (limited to 'old/moon_wrapper/tests/unit_python/api')
-rw-r--r--old/moon_wrapper/tests/unit_python/api/__init__.py0
-rw-r--r--old/moon_wrapper/tests/unit_python/api/test_wrapper.py72
2 files changed, 72 insertions, 0 deletions
diff --git a/old/moon_wrapper/tests/unit_python/api/__init__.py b/old/moon_wrapper/tests/unit_python/api/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/old/moon_wrapper/tests/unit_python/api/__init__.py
diff --git a/old/moon_wrapper/tests/unit_python/api/test_wrapper.py b/old/moon_wrapper/tests/unit_python/api/test_wrapper.py
new file mode 100644
index 00000000..bd6baf32
--- /dev/null
+++ b/old/moon_wrapper/tests/unit_python/api/test_wrapper.py
@@ -0,0 +1,72 @@
+# 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'.
+
+import json
+
+
+def get_json(data):
+ return json.loads(data.decode("utf-8"))
+
+
+def test_authz_true(context):
+ import moon_wrapper.server
+ server = moon_wrapper.server.main()
+ client = server.app.test_client()
+ _target = {
+ 'target': {
+ "name": context.get('object_name'),
+ },
+ "project_id": context.get('project_id'),
+ "user_id": context.get('subject_name')
+ }
+ authz_data = {
+ 'rule': context.get('action_name'),
+ 'target': json.dumps(_target),
+ 'credentials': 'null'}
+ req = client.post("/authz/oslo", data=json.dumps(authz_data))
+ assert req.status_code is 200
+ assert req.data
+ assert isinstance(req.data, bytes)
+ assert req.data == b"True"
+
+def test_authz_error_response_code(context):
+ import moon_wrapper.server
+ server = moon_wrapper.server.main()
+ client = server.app.test_client()
+ _target = {
+ 'target': {
+ "name": context.get('object_name'),
+ },
+ "project_id": context.get('invalid_project_id'),
+ "user_id": context.get('subject_name')
+ }
+ authz_data = {
+ 'rule': context.get('action_name'),
+ 'target': json.dumps(_target),
+ 'credentials': 'null'}
+ req = client.post("/authz/oslo", data=json.dumps(authz_data))
+ assert req.status_code is 200
+ assert req.data
+ assert isinstance(req.data, bytes)
+ assert req.data == b"False"
+
+def test_authz_error_no_interface_key(context):
+ import moon_wrapper.server
+ server = moon_wrapper.server.main()
+ client = server.app.test_client()
+ _target = {
+ 'target': {
+ "name": context.get('object_name'),
+ },
+ "project_id": context.get('project_with_no_interface_key'),
+ "user_id": context.get('subject_name')
+ }
+ authz_data = {
+ 'rule': context.get('action_name'),
+ 'target': json.dumps(_target),
+ 'credentials': 'null'}
+ req = client.post("/authz/oslo", data=json.dumps(authz_data))
+
+ assert req.data == b"False" \ No newline at end of file