summaryrefslogtreecommitdiffstats
path: root/ms/py-executor/resource_resolution/tests
diff options
context:
space:
mode:
Diffstat (limited to 'ms/py-executor/resource_resolution/tests')
-rw-r--r--ms/py-executor/resource_resolution/tests/authorization_interceptor_test.py2
-rw-r--r--ms/py-executor/resource_resolution/tests/grpc_client_test.py (renamed from ms/py-executor/resource_resolution/tests/client_test.py)4
-rw-r--r--ms/py-executor/resource_resolution/tests/http_client_test.py38
-rw-r--r--ms/py-executor/resource_resolution/tests/resource_resolution_test.py64
4 files changed, 105 insertions, 3 deletions
diff --git a/ms/py-executor/resource_resolution/tests/authorization_interceptor_test.py b/ms/py-executor/resource_resolution/tests/authorization_interceptor_test.py
index 4b03f0b36..734059f3d 100644
--- a/ms/py-executor/resource_resolution/tests/authorization_interceptor_test.py
+++ b/ms/py-executor/resource_resolution/tests/authorization_interceptor_test.py
@@ -17,7 +17,7 @@ from unittest.mock import MagicMock, _Call
import pytest
-from resource_resolution.authorization import AuthTokenInterceptor, NewClientCallDetails
+from resource_resolution.grpc.authorization import AuthTokenInterceptor, NewClientCallDetails
def test_resource_resolution_auth_token_interceptor():
diff --git a/ms/py-executor/resource_resolution/tests/client_test.py b/ms/py-executor/resource_resolution/tests/grpc_client_test.py
index 2b94220f6..8217b0f25 100644
--- a/ms/py-executor/resource_resolution/tests/client_test.py
+++ b/ms/py-executor/resource_resolution/tests/grpc_client_test.py
@@ -15,10 +15,10 @@ limitations under the License.
from unittest.mock import MagicMock, patch
-from resource_resolution.client import Client
+from resource_resolution.grpc.client import Client
-@patch("resource_resolution.client.insecure_channel")
+@patch("resource_resolution.grpc.client.insecure_channel")
def test_resource_resoulution_insecure_channel(insecure_channel_mock: MagicMock):
"""Test if insecure_channel connection is called."""
with patch.object(Client, "close") as client_close_method_mock: # Type MagicMock
diff --git a/ms/py-executor/resource_resolution/tests/http_client_test.py b/ms/py-executor/resource_resolution/tests/http_client_test.py
new file mode 100644
index 000000000..2279fde7a
--- /dev/null
+++ b/ms/py-executor/resource_resolution/tests/http_client_test.py
@@ -0,0 +1,38 @@
+"""Copyright 2020 Deutsche Telekom.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+"""
+
+from unittest.mock import MagicMock, patch
+
+from resource_resolution.http.client import Client
+
+
+@patch("resource_resolution.http.client.request")
+def test_http_client(request_mock):
+ c = Client("127.0.0.1", 8080)
+ assert c.auth is None
+ c = Client("127.0.0.1", 8080, auth_user="user")
+ assert c.auth is None
+ c = Client("127.0.0.1", 8080, auth_user="user", auth_pass="pass")
+ assert c.auth == ("user", "pass")
+
+ assert c.protocol == "http"
+ assert c.url == "http://127.0.0.1:8080/api/v1"
+
+ c = Client("127.0.0.1", 8081, use_ssl=True)
+ assert c.protocol == "https"
+ assert c.url == "https://127.0.0.1:8081/api/v1"
+
+ c.send_request("GET", "something")
+ request_mock.assert_called_once_with(method="GET", url=f"{c.url}/something", verify=False, auth=None)
diff --git a/ms/py-executor/resource_resolution/tests/resource_resolution_test.py b/ms/py-executor/resource_resolution/tests/resource_resolution_test.py
index 8a41357e6..274802279 100644
--- a/ms/py-executor/resource_resolution/tests/resource_resolution_test.py
+++ b/ms/py-executor/resource_resolution/tests/resource_resolution_test.py
@@ -13,12 +13,17 @@ See the License for the specific language governing permissions and
limitations under the License.
"""
+import json
+from unittest.mock import patch, MagicMock
+
from google.protobuf import json_format
from pytest import raises
from resource_resolution.resource_resolution import (
ExecutionServiceInput,
ExecutionServiceOutput,
+ ResourceResolution,
+ Template,
WorkflowExecution,
WorkflowExecutionResult,
WorkflowMode,
@@ -103,3 +108,62 @@ def test_workflow_execution_result_class():
execution_output.status.code = 500
assert execution_result.has_error
assert execution_result.error_message == ""
+
+
+def test_resource_resolution_check_resolve_params():
+ """Check values of potentially HTTP parameters."""
+ rr = ResourceResolution()
+ with raises(AttributeError):
+ rr._check_template_resolve_params()
+ rr._check_template_resolve_params(resource_type="test")
+ rr._check_template_resolve_params(resource_id="test")
+ rr._check_template_resolve_params(resolution_key="test")
+ rr._check_template_resolve_params(resource_type="test", resource_id="test")
+
+
+def test_store_template():
+ """Test store_template method.
+
+ Checks if http_client send_request method is called with valid parameters.
+ """
+ rr = ResourceResolution(server_address="127.0.0.1", http_server_port=8080)
+ rr.http_client = MagicMock()
+ rr.store_template(
+ blueprint_name="test_blueprint_name",
+ blueprint_version="test_blueprint_version",
+ artifact_name="test_artifact_name",
+ resolution_key="test_resolution_key",
+ result="test_result",
+ )
+ rr.http_client.send_request.assert_called_once_with(
+ "POST",
+ "template/test_blueprint_name/test_blueprint_version/test_artifact_name/test_resolution_key",
+ data=json.dumps({"result": "test_result"}),
+ headers={"Content-Type": "application/json"},
+ )
+
+
+def test_retrieve_template():
+ """Test retrieve_template method.
+
+ Checks if http_client send_request method is called with valid parameters.
+ """
+ rr = ResourceResolution(server_address="127.0.0.1", http_server_port=8080)
+ rr.http_client = MagicMock()
+ rr.retrieve_template(
+ blueprint_name="test_blueprint_name",
+ blueprint_version="test_blueprint_version",
+ artifact_name="test_artifact_name",
+ resolution_key="test_resolution_key",
+ )
+ rr.http_client.send_request.assert_called_once_with(
+ "GET",
+ "template",
+ params={
+ "bpName": "test_blueprint_name",
+ "bpVersion": "test_blueprint_version",
+ "artifactName": "test_artifact_name",
+ "resolutionKey": "test_resolution_key",
+ },
+ headers={"Accept": "application/json"},
+ )