summaryrefslogtreecommitdiffstats
path: root/ms/py-executor/resource_resolution/tests
diff options
context:
space:
mode:
authorMichal Jagiello <michal.jagiello@t-mobile.pl>2020-03-27 12:16:22 +0000
committerDan Timoney <dtimoney@att.com>2020-04-29 19:48:16 +0000
commit687b9ee9bf3dd169b2e032c0aa572e93b38306ca (patch)
tree178c77b4e2ec79b93979b5400928847bcca08beb /ms/py-executor/resource_resolution/tests
parent57d845ac71712fd60a350f084a186e63932bc327 (diff)
PyExecutor ResourceResolution store/retrieve templates
Issue-ID: CCSDK-2156 Signed-off-by: Michal Jagiello <michal.jagiello@t-mobile.pl> Change-Id: I59df2772d004e349532a1b42c4e4abd367c13256 (cherry picked from commit daf7bf3b0726c9574f9f1b7aa34af4f199ee32c3)
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"},
+ )
tories>mvn:org.onap.ccsdk.features/ccsdk-features/blueprints-processor-features/${project.version}/xml/features</features.repositories> <include.transitive.dependencies>false</include.transitive.dependencies> </properties> <dependencies> <dependency> <groupId>org.onap.ccsdk.features</groupId> <artifactId>ccsdk-blueprints-processor</artifactId> <version>${project.version}</version> <classifier>features</classifier> <type>xml</type> <exclusions> <exclusion> <groupId>*</groupId> <artifactId>*</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.onap.ccsdk.features</groupId> <artifactId>blueprints-data-adaptor-provider</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>org.onap.ccsdk.features</groupId> <artifactId>blueprints-rest-adaptor-provider</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>org.onap.ccsdk.features</groupId> <artifactId>blueprints-assignment-provider</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>org.onap.ccsdk.features</groupId> <artifactId>blueprints-generator-provider</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>org.onap.ccsdk.features</groupId> <artifactId>blueprints-model-provider</artifactId> <version>${project.version}</version> </dependency> </dependencies> <build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <executions> <execution> <id>maven-repo-zip</id> <goals> <goal>single</goal> </goals> <phase>package</phase> <configuration> <attach>true</attach> <finalName>stage/${application.name}-${project.version}</finalName> <descriptors> <descriptor>src/assembly/assemble_mvnrepo_zip.xml</descriptor> </descriptors> <appendAssemblyId>true</appendAssemblyId> </configuration> </execution> <execution> <id>installer-zip</id> <goals> <goal>single</goal> </goals> <phase>package</phase> <configuration> <attach>true</attach> <finalName>${application.name}-${project.version}-installer</finalName> <descriptors> <descriptor>src/assembly/assemble_installer_zip.xml</descriptor> </descriptors> <appendAssemblyId>false</appendAssemblyId> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <goals> <goal>copy-dependencies</goal> </goals> <phase>prepare-package</phase> <configuration> <transitive>false</transitive> <outputDirectory>${project.build.directory}/assembly/system</outputDirectory> <overWriteReleases>false</overWriteReleases> <overWriteSnapshots>true</overWriteSnapshots> <overWriteIfNewer>true</overWriteIfNewer> <useRepositoryLayout>true</useRepositoryLayout> <addParentPoms>false</addParentPoms> <copyPom>false</copyPom> <includeGroupIds>org.onap.ccsdk.features</includeGroupIds> <scope>provided</scope> </configuration> </execution> </executions> </plugin> <plugin> <artifactId>maven-resources-plugin</artifactId> <version>2.6</version> <executions> <execution> <id>copy-version</id> <goals> <goal>copy-resources</goal> </goals><!-- here the phase you need --> <phase>validate</phase> <configuration> <outputDirectory>${basedir}/target/stage</outputDirectory> <resources> <resource> <directory>src/main/resources/scripts</directory> <includes> <include>install-feature.sh</include> </includes> <filtering>true</filtering> </resource> </resources> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>