aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_so_orchestration_request.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_so_orchestration_request.py')
-rw-r--r--tests/test_so_orchestration_request.py103
1 files changed, 103 insertions, 0 deletions
diff --git a/tests/test_so_orchestration_request.py b/tests/test_so_orchestration_request.py
new file mode 100644
index 0000000..c93189b
--- /dev/null
+++ b/tests/test_so_orchestration_request.py
@@ -0,0 +1,103 @@
+# Copyright 2022 Orange, Deutsche Telekom AG
+#
+# 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 import mock
+
+from onapsdk.so.so_element import OrchestrationRequest, SoElement
+from onapsdk.utils.headers_creator import headers_so_creator
+from onapsdk.onap_service import OnapService
+
+
+IN_PROGRESS = {
+ "request": {
+ "requestStatus": {
+ "requestState": "IN_PROGRESS"
+ }
+ }
+}
+FAILED = {
+ "request": {
+ "requestStatus": {
+ "requestState": "FAILED"
+ }
+ }
+}
+COMPLETE = {
+ "request": {
+ "requestStatus": {
+ "requestState": "COMPLETE"
+ }
+ }
+}
+UNKNOWN = {
+ "request": {
+ "requestStatus": {
+ "requestState": "INVALID"
+ }
+ }
+}
+BAD_RESPONSE = {}
+
+
+@mock.patch.object(OrchestrationRequest, "send_message_json")
+def test_orchestration_request_status(mock_send_message):
+ orchestration_req = OrchestrationRequest(request_id="test")
+
+ mock_send_message.return_value = BAD_RESPONSE
+ assert orchestration_req.status == OrchestrationRequest.StatusEnum.UNKNOWN
+
+ mock_send_message.return_value = UNKNOWN
+ assert orchestration_req.status == OrchestrationRequest.StatusEnum.UNKNOWN
+
+ mock_send_message.return_value = FAILED
+ assert orchestration_req.status == OrchestrationRequest.StatusEnum.FAILED
+
+ mock_send_message.return_value = COMPLETE
+ assert orchestration_req.status == OrchestrationRequest.StatusEnum.COMPLETED
+
+ mock_send_message.return_value = IN_PROGRESS
+ assert orchestration_req.status == OrchestrationRequest.StatusEnum.IN_PROGRESS
+ assert not orchestration_req.finished
+ assert not orchestration_req.completed
+ assert not orchestration_req.failed
+
+ mock_send_message.return_value = COMPLETE
+ assert orchestration_req.finished
+ assert orchestration_req.completed
+ assert not orchestration_req.failed
+
+ mock_send_message.return_value = FAILED
+ assert orchestration_req.finished
+ assert not orchestration_req.completed
+ assert orchestration_req.failed
+
+
+#Test the Class SoElement
+def test_SoElement_headers():
+ """Test the header property"""
+ element = SoElement()
+ assert element.headers != headers_so_creator(OnapService.headers)
+ #check x-transactionid for headers
+
+
+def test_get_subscription_service_type():
+ """Test SO Element class method"""
+ vf_object_name = SoElement.get_subscription_service_type("vf_name")
+ assert vf_object_name == "vf_name"
+
+
+def test_base_create_url():
+ """Test base create url class method"""
+ assert SoElement._base_create_url() == "{}/onap/so/infra/serviceInstantiation/{}/serviceInstances".\
+ format(SoElement.base_url, SoElement.api_version)
+