blob: 2c896513bb0b1c0a52d045da1b082a4a3e69a05f (
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
|
from unittest.mock import MagicMock, patch, PropertyMock
from onap_data_provider.resources.tenant_resource import TenantResource
from onapsdk.exceptions import ResourceNotFound
TENANT_RESOURCE_DATA = {"tenant-id": "Test ID", "tenant-name": "Test name"}
def test_tenant_resource_tenant():
cloud_region_mock = MagicMock()
tenant_resource = TenantResource(TENANT_RESOURCE_DATA, cloud_region_mock)
cloud_region_mock.get_tenant.side_effect = ResourceNotFound
assert tenant_resource.tenant is None
cloud_region_mock.get_tenant.side_effect = None
cloud_region_mock.get_tenant.return_value = 1
assert tenant_resource.tenant == 1
cloud_region_mock.reset_mock()
assert tenant_resource.tenant == 1
cloud_region_mock.assert_not_called()
@patch(
"onap_data_provider.resources.tenant_resource.TenantResource.tenant",
new_callable=PropertyMock,
)
def test_tenant_resource_exists(mock_tenant):
mock_tenant.return_value = None
cloud_region_mock = MagicMock()
tenant_resource = TenantResource(TENANT_RESOURCE_DATA, cloud_region_mock)
assert tenant_resource.exists is False
mock_tenant.return_value = 1
assert tenant_resource.exists is True
@patch(
"onap_data_provider.resources.tenant_resource.TenantResource.exists",
new_callable=PropertyMock,
)
def test_tenant_resource_create(mock_exists):
cloud_region_mock = MagicMock()
tenant_resource = TenantResource(TENANT_RESOURCE_DATA, cloud_region_mock)
mock_exists.return_value = True
tenant_resource.create()
cloud_region_mock.add_tenant.assert_not_called()
mock_exists.return_value = False
tenant_resource.create()
cloud_region_mock.add_tenant.assert_called_once_with(
tenant_id="Test ID", tenant_name="Test name", tenant_context=None
)
|