aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_so_orchestration_request.py
blob: 56d0ad4fece3a0425adcd392cd73883b49975fa1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#   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",
            "statusMessage": "test-message"
        }
    }
}
FAILED = {
    "request": {
        "requestStatus": {
            "requestState": "FAILED",
            "statusMessage": "test-message"
        }
    }
}
COMPLETE = {
    "request": {
        "requestStatus": {
            "requestState": "COMPLETE",
            "statusMessage": "test-message"
        }
    }
}
UNKNOWN = {
    "request": {
        "requestStatus": {
            "requestState": "INVALID",
            "statusMessage": "test-message"
        }
    }
}
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

@mock.patch.object(OrchestrationRequest, "send_message_json")
def test_orchestration_request_status_message(mock_send_message):
    orchestration_req = OrchestrationRequest(request_id="test")

    mock_send_message.return_value = BAD_RESPONSE
    assert orchestration_req.status_message == "Unknown request state"

    mock_send_message.return_value = UNKNOWN
    assert orchestration_req.status_message == "test-message"

    mock_send_message.return_value = FAILED
    assert orchestration_req.status_message == "test-message"

    mock_send_message.return_value = COMPLETE
    assert orchestration_req.status_message == "test-message"


#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)