diff options
author | Michal Jagiello <michal.jagiello@t-mobile.pl> | 2021-11-30 08:25:09 +0000 |
---|---|---|
committer | Michal Jagiello <michal.jagiello@t-mobile.pl> | 2021-12-03 09:58:59 +0000 |
commit | 66e44262b8eb996c06670dcededd899dd1cbd7dc (patch) | |
tree | 3fcea0fe3317f8069281cb93c61add4b1599ab83 /tests/test_tenant_resource.py | |
parent | 2416a1a546c1d2922c37d513df42e9d26bbaaa42 (diff) |
Data provider release
Change-Id: Ia041a07152e8dabd87de05992d3670cbdc1ddaae
Issue-ID: INT-2010
Signed-off-by: Michal Jagiello <michal.jagiello@t-mobile.pl>
Diffstat (limited to 'tests/test_tenant_resource.py')
-rw-r--r-- | tests/test_tenant_resource.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/test_tenant_resource.py b/tests/test_tenant_resource.py new file mode 100644 index 0000000..2c89651 --- /dev/null +++ b/tests/test_tenant_resource.py @@ -0,0 +1,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 + ) |