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
|
"""
Copyright 2022 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.mock import patch, PropertyMock
from onapsdk.aai.cloud_infrastructure.complex import Complex
from onap_data_provider.resources.complex_resource import ComplexResource
from onapsdk.exceptions import ResourceNotFound
COMPLEX_DATA = {
"physical-location-id": "123",
"complex-name": "NB central office 1",
"data-center-code": "veniam",
"identity-url": "https://estevan.org",
"physical-location-type": "centraloffice",
"street1": "Ravensburgstraße",
"street2": "123",
"city": "Neubrandenburg",
"state": "Mecklenburg-Vorpommern",
"postal-code": "17034",
"country": "DE",
"region": "Mecklenburg Lakeland",
"latitude": "53.5630015",
"longitude": "13.2722710",
"elevation": "100",
"lata": "dolorem",
}
@patch("onap_data_provider.resources.complex_resource.Complex.get_all")
def test_complex_resource_complex(mock_complex_get_all):
mock_complex_get_all.side_effect = ResourceNotFound
mock_complex_get_all.return_value = iter([])
complex_resource = ComplexResource(COMPLEX_DATA)
assert complex_resource.complex is None
mock_complex_get_all.side_effect = None
mock_complex_get_all.return_value = iter([Complex(physical_location_id="123")])
assert complex_resource.complex is not None
@patch(
"onap_data_provider.resources.complex_resource.ComplexResource.complex",
new_callable=PropertyMock,
)
def test_complex_resource_exists(mock_complex):
mock_complex.return_value = None
complex_resource = ComplexResource(COMPLEX_DATA)
assert complex_resource.exists is False
mock_complex.return_value = 1 # Anything but not None
assert complex_resource.exists is True
@patch(
"onap_data_provider.resources.complex_resource.ComplexResource.exists",
new_callable=PropertyMock,
)
@patch("onap_data_provider.resources.complex_resource.Complex.create")
def test_complex_resource_create(mock_complex_create, mock_exists):
mock_exists.return_value = True
complex_resource = ComplexResource(COMPLEX_DATA)
complex_resource.create()
mock_complex_create.assert_not_called()
mock_exists.return_value = False
complex_resource.create()
mock_complex_create.assert_called_once_with(
physical_location_id="123",
name="NB central office 1",
data_center_code="veniam",
identity_url="https://estevan.org",
physical_location_type="centraloffice",
street1="Ravensburgstraße",
street2="123",
city="Neubrandenburg",
state="Mecklenburg-Vorpommern",
postal_code="17034",
country="DE",
region="Mecklenburg Lakeland",
latitude="53.5630015",
longitude="13.2722710",
elevation="100",
lata="dolorem",
)
|