aboutsummaryrefslogtreecommitdiffstats
path: root/ms/py-executor/resource_resolution/tests/resource_resolution_test.py
diff options
context:
space:
mode:
authorMichal Jagiello <michal.jagiello@t-mobile.pl>2020-03-27 12:16:22 +0000
committerMichal Jagiello <michal.jagiello@t-mobile.pl>2020-04-28 08:26:32 +0000
commitdaf7bf3b0726c9574f9f1b7aa34af4f199ee32c3 (patch)
tree023d8ce4a7a2e599cdc7a7c9d1a38e57e6d73b79 /ms/py-executor/resource_resolution/tests/resource_resolution_test.py
parent4dccd00d6b1399596ed6f1e0c7f08cdb98cbec4f (diff)
PyExecutor ResourceResolution store/retrieve templates
Issue-ID: CCSDK-2156 Signed-off-by: Michal Jagiello <michal.jagiello@t-mobile.pl> Change-Id: I59df2772d004e349532a1b42c4e4abd367c13256
Diffstat (limited to 'ms/py-executor/resource_resolution/tests/resource_resolution_test.py')
-rw-r--r--ms/py-executor/resource_resolution/tests/resource_resolution_test.py64
1 files changed, 64 insertions, 0 deletions
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"},
+ )