summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/__init__.py0
-rw-r--r--tests/config_dirs/not_yaml0
-rw-r--r--tests/config_dirs/test-data-version.yml48
-rw-r--r--tests/config_dirs/test-data.yml47
-rw-r--r--tests/test-data-version.yml48
-rw-r--r--tests/test-data.yml47
-rw-r--r--tests/test-kube-config1
-rw-r--r--tests/test_aai_service_resource.py51
-rw-r--r--tests/test_cloud_region_resource.py149
-rw-r--r--tests/test_complex_resource.py82
-rw-r--r--tests/test_config_loader.py27
-rw-r--r--tests/test_config_parser.py50
-rw-r--r--tests/test_customer_resource.py84
-rw-r--r--tests/test_esr_resource.py82
-rw-r--r--tests/test_line_of_business_resource.py51
-rw-r--r--tests/test_owning_entity_resource.py51
-rw-r--r--tests/test_platform_resource.py47
-rw-r--r--tests/test_pnf_resource.py28
-rw-r--r--tests/test_project_resource.py47
-rw-r--r--tests/test_resource_creator.py31
-rw-r--r--tests/test_service_instance_resource.py141
-rw-r--r--tests/test_service_resource.py50
-rw-r--r--tests/test_tag_handlers.py15
-rw-r--r--tests/test_tenant_resource.py56
-rw-r--r--tests/test_validator.py123
-rw-r--r--tests/test_vendor_resource.py28
-rw-r--r--tests/test_versions.py15
-rw-r--r--tests/test_vnf_resource.py28
-rw-r--r--tests/test_vsp_resource.py28
29 files changed, 1455 insertions, 0 deletions
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/__init__.py
diff --git a/tests/config_dirs/not_yaml b/tests/config_dirs/not_yaml
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/config_dirs/not_yaml
diff --git a/tests/config_dirs/test-data-version.yml b/tests/config_dirs/test-data-version.yml
new file mode 100644
index 0000000..51e92c9
--- /dev/null
+++ b/tests/config_dirs/test-data-version.yml
@@ -0,0 +1,48 @@
+odpSchemaVersion: 1.0
+resources:
+ complexes:
+ - complex:
+ data-center-code: AMICPL1
+ complex-name: AMIST-COMPLEX-1
+ physical-location-id: &complex_id AMIST-COMPLEX-1
+ physical-location-type: Office
+ street1: '505'
+ street2: Terry Fox Drive
+ city: Kanata
+ state: Ontario
+ postal-code: A1A1A1
+ region: Eastern
+ country: Canada
+
+ cloud-regions:
+ - cloud-region:
+ cloud-owner: &clown AMIST
+ cloud-region-id: AMCR1
+ cloud-region-version: '11.0'
+ orchestration-disabled: true
+ in-maint: false
+ complex:
+ physical-location-id: *complex_id
+ tenants:
+ - tenant-id: !join ['-', [*clown, 'TENANT', 1]]
+ tenant-name: AMIST-TENANT-1-NAME
+ - tenant-id: !join [*clown, '-', 'TENANT', '-', 2]
+ tenant-name: AMIST-TENANT-2-NAME
+ availability-zones:
+ - cloud-owner: *clown
+ availability-zone-name: AMIST-AZ-1
+ hypervisor-type: OpenStackAmd
+
+ customers:
+ - customer:
+ global-customer-id: AMIST-CUST-11
+ subscriber-name: AAIIST-TESTER-11
+ subscriber-type: Customer
+ service-subscriptions:
+ - service-type: amist-voip
+ - customer:
+ global-customer-id: AMIST-CUST-12
+ subscriber-name: AAIIST-TESTER-12
+ subscriber-type: Customer
+ service-subscriptions:
+ - service-type: amist-voip
diff --git a/tests/config_dirs/test-data.yml b/tests/config_dirs/test-data.yml
new file mode 100644
index 0000000..281e754
--- /dev/null
+++ b/tests/config_dirs/test-data.yml
@@ -0,0 +1,47 @@
+---
+complexes:
+- complex:
+ data-center-code: AMICPL1
+ complex-name: AMIST-COMPLEX-1
+ physical-location-id: &complex_id AMIST-COMPLEX-1
+ physical-location-type: Office
+ street1: '505'
+ street2: Terry Fox Drive
+ city: Kanata
+ state: Ontario
+ postal-code: A1A1A1
+ region: Eastern
+ country: Canada
+
+cloud-regions:
+- cloud-region:
+ cloud-owner: &clown AMIST
+ cloud-region-id: AMCR1
+ cloud-region-version: '11.0'
+ orchestration-disabled: true
+ in-maint: false
+ complex:
+ physical-location-id: *complex_id
+ tenants:
+ - tenant-id: !join ['-', [*clown, 'TENANT', 1]]
+ tenant-name: AMIST-TENANT-1-NAME
+ - tenant-id: !join [*clown, '-', 'TENANT', '-', 2]
+ tenant-name: AMIST-TENANT-2-NAME
+ availability-zones:
+ - cloud-owner: *clown
+ availability-zone-name: AMIST-AZ-1
+ hypervisor-type: OpenStackAmd
+
+customers:
+- customer:
+ global-customer-id: AMIST-CUST-11
+ subscriber-name: AAIIST-TESTER-11
+ subscriber-type: Customer
+ service-subscriptions:
+ - service-type: amist-voip
+- customer:
+ global-customer-id: AMIST-CUST-12
+ subscriber-name: AAIIST-TESTER-12
+ subscriber-type: Customer
+ service-subscriptions:
+ - service-type: amist-voip
diff --git a/tests/test-data-version.yml b/tests/test-data-version.yml
new file mode 100644
index 0000000..51e92c9
--- /dev/null
+++ b/tests/test-data-version.yml
@@ -0,0 +1,48 @@
+odpSchemaVersion: 1.0
+resources:
+ complexes:
+ - complex:
+ data-center-code: AMICPL1
+ complex-name: AMIST-COMPLEX-1
+ physical-location-id: &complex_id AMIST-COMPLEX-1
+ physical-location-type: Office
+ street1: '505'
+ street2: Terry Fox Drive
+ city: Kanata
+ state: Ontario
+ postal-code: A1A1A1
+ region: Eastern
+ country: Canada
+
+ cloud-regions:
+ - cloud-region:
+ cloud-owner: &clown AMIST
+ cloud-region-id: AMCR1
+ cloud-region-version: '11.0'
+ orchestration-disabled: true
+ in-maint: false
+ complex:
+ physical-location-id: *complex_id
+ tenants:
+ - tenant-id: !join ['-', [*clown, 'TENANT', 1]]
+ tenant-name: AMIST-TENANT-1-NAME
+ - tenant-id: !join [*clown, '-', 'TENANT', '-', 2]
+ tenant-name: AMIST-TENANT-2-NAME
+ availability-zones:
+ - cloud-owner: *clown
+ availability-zone-name: AMIST-AZ-1
+ hypervisor-type: OpenStackAmd
+
+ customers:
+ - customer:
+ global-customer-id: AMIST-CUST-11
+ subscriber-name: AAIIST-TESTER-11
+ subscriber-type: Customer
+ service-subscriptions:
+ - service-type: amist-voip
+ - customer:
+ global-customer-id: AMIST-CUST-12
+ subscriber-name: AAIIST-TESTER-12
+ subscriber-type: Customer
+ service-subscriptions:
+ - service-type: amist-voip
diff --git a/tests/test-data.yml b/tests/test-data.yml
new file mode 100644
index 0000000..281e754
--- /dev/null
+++ b/tests/test-data.yml
@@ -0,0 +1,47 @@
+---
+complexes:
+- complex:
+ data-center-code: AMICPL1
+ complex-name: AMIST-COMPLEX-1
+ physical-location-id: &complex_id AMIST-COMPLEX-1
+ physical-location-type: Office
+ street1: '505'
+ street2: Terry Fox Drive
+ city: Kanata
+ state: Ontario
+ postal-code: A1A1A1
+ region: Eastern
+ country: Canada
+
+cloud-regions:
+- cloud-region:
+ cloud-owner: &clown AMIST
+ cloud-region-id: AMCR1
+ cloud-region-version: '11.0'
+ orchestration-disabled: true
+ in-maint: false
+ complex:
+ physical-location-id: *complex_id
+ tenants:
+ - tenant-id: !join ['-', [*clown, 'TENANT', 1]]
+ tenant-name: AMIST-TENANT-1-NAME
+ - tenant-id: !join [*clown, '-', 'TENANT', '-', 2]
+ tenant-name: AMIST-TENANT-2-NAME
+ availability-zones:
+ - cloud-owner: *clown
+ availability-zone-name: AMIST-AZ-1
+ hypervisor-type: OpenStackAmd
+
+customers:
+- customer:
+ global-customer-id: AMIST-CUST-11
+ subscriber-name: AAIIST-TESTER-11
+ subscriber-type: Customer
+ service-subscriptions:
+ - service-type: amist-voip
+- customer:
+ global-customer-id: AMIST-CUST-12
+ subscriber-name: AAIIST-TESTER-12
+ subscriber-type: Customer
+ service-subscriptions:
+ - service-type: amist-voip
diff --git a/tests/test-kube-config b/tests/test-kube-config
new file mode 100644
index 0000000..3c546eb
--- /dev/null
+++ b/tests/test-kube-config
@@ -0,0 +1 @@
+dummy file \ No newline at end of file
diff --git a/tests/test_aai_service_resource.py b/tests/test_aai_service_resource.py
new file mode 100644
index 0000000..9056299
--- /dev/null
+++ b/tests/test_aai_service_resource.py
@@ -0,0 +1,51 @@
+from unittest.mock import patch, PropertyMock
+
+from onap_data_provider.resources.aai_service_resource import AaiService, AaiServiceResource, ResourceNotFound
+
+
+AAI_SERVICE_DATA = {
+ "service-id": "123",
+ "service-description": "123"
+}
+
+
+@patch("onap_data_provider.resources.aai_service_resource.AaiService.get_all")
+def test_aai_service_resource_aai_resource(mock_aai_service_get_all):
+ mock_aai_service_get_all.side_effect = ResourceNotFound
+ mock_aai_service_get_all.return_value = iter([])
+ aai_service_resource = AaiServiceResource(AAI_SERVICE_DATA)
+ assert aai_service_resource.aai_service is None
+ mock_aai_service_get_all.side_effect = None
+ mock_aai_service_get_all.return_value = iter([AaiService(service_id="123", service_description="123", resource_version="123")])
+ assert aai_service_resource.aai_service is not None
+
+
+@patch(
+ "onap_data_provider.resources.aai_service_resource.AaiServiceResource.aai_service",
+ new_callable=PropertyMock,
+)
+def test_aai_service_resource_exists(mock_aai_service):
+ mock_aai_service.return_value = None
+ aai_service_resource = AaiServiceResource(AAI_SERVICE_DATA)
+ assert aai_service_resource.exists is False
+ mock_aai_service.return_value = 1 # Anything but not None
+ assert aai_service_resource.exists is True
+
+
+@patch(
+ "onap_data_provider.resources.aai_service_resource.AaiServiceResource.exists",
+ new_callable=PropertyMock,
+)
+@patch("onap_data_provider.resources.aai_service_resource.AaiService.create")
+def test_aai_service_resource_create(mock_aai_service_create, mock_exists):
+ mock_exists.return_value = True
+ aai_service_resource = AaiServiceResource(AAI_SERVICE_DATA)
+ aai_service_resource.create()
+ mock_aai_service_create.assert_not_called()
+
+ mock_exists.return_value = False
+ aai_service_resource.create()
+ mock_aai_service_create.assert_called_once_with(
+ service_id="123",
+ service_description="123"
+ )
diff --git a/tests/test_cloud_region_resource.py b/tests/test_cloud_region_resource.py
new file mode 100644
index 0000000..b704720
--- /dev/null
+++ b/tests/test_cloud_region_resource.py
@@ -0,0 +1,149 @@
+from pathlib import Path
+from unittest.mock import MagicMock, patch, PropertyMock
+
+from onapsdk.aai.cloud_infrastructure.complex import Complex
+
+from onap_data_provider.resources.cloud_region_resource import (
+ CloudRegion,
+ CloudRegionResource,
+)
+from onapsdk.exceptions import ResourceNotFound
+
+CLOUD_REGION_DATA = {
+ "cloud-owner": "test",
+ "cloud-region-id": "test",
+ "orchestration-disabled": True,
+ "in-maint": False,
+}
+
+CLOUD_REGION_K8S_TYPE = {
+ "cloud-region-id": "k8s-test",
+ "cloud-owner": "k8s-test",
+ "orchestration-disabled": True,
+ "in-maint": False,
+ "cloud-type": "k8s",
+ "kube-config": Path(Path(__file__).parent, "test-kube-config"),
+}
+
+
+@patch("onap_data_provider.resources.cloud_region_resource.CloudRegion.get_by_id")
+def test_cloud_region_resource_cloud_region(mock_cloud_region_get_by_id):
+ mock_cloud_region_get_by_id.side_effect = ResourceNotFound
+ cloud_region_resource = CloudRegionResource(CLOUD_REGION_DATA)
+ assert cloud_region_resource.cloud_region is None
+
+ mock_cloud_region_get_by_id.side_effect = None
+ mock_cloud_region_get_by_id.return_value = 1
+ assert cloud_region_resource.cloud_region == 1
+
+
+@patch(
+ "onap_data_provider.resources.cloud_region_resource.CloudRegionResource.cloud_region",
+ new_callable=PropertyMock,
+)
+def test_cloud_region_resource_exists(mock_cloud_region):
+ mock_cloud_region.return_value = None
+ cloud_region_resource = CloudRegionResource(CLOUD_REGION_DATA)
+ assert cloud_region_resource.exists is False
+ mock_cloud_region.return_value = 1 # Anything but not None
+ assert cloud_region_resource.exists is True
+
+
+@patch(
+ "onap_data_provider.resources.cloud_region_resource.CloudRegionResource.exists",
+ new_callable=PropertyMock,
+)
+@patch("onap_data_provider.resources.cloud_region_resource.CloudRegion.create")
+def test_cloud_region_create(mock_cloud_region_create, mock_exists):
+
+ cloud_region_resource = CloudRegionResource(CLOUD_REGION_DATA)
+ assert cloud_region_resource.data == CLOUD_REGION_DATA
+
+ mock_exists.return_value = False
+ cloud_region_resource.create()
+ assert mock_cloud_region_create.called_once_with(
+ cloud_owner="test",
+ cloud_region_id="test",
+ orchestration_disabled=True,
+ in_maint=False,
+ )
+
+ mock_exists.reset_mock()
+ mock_cloud_region_create.reset_mock()
+
+ mock_exists.return_value = True
+ cloud_region_resource.create()
+ mock_cloud_region_create.assert_not_called()
+
+
+@patch(
+ "onap_data_provider.resources.cloud_region_resource.CloudRegionResource.cloud_region",
+ new_callable=PropertyMock,
+)
+@patch("onap_data_provider.resources.cloud_region_resource.Complex.get_all")
+def test_cloud_region_resource_link_to_complex(
+ mock_complex_get_all, mock_cloud_region_property
+):
+ mock_cloud_region_property.return_value.complex = MagicMock()
+ cloud_region_resource = CloudRegionResource(CLOUD_REGION_DATA)
+ cloud_region_resource._link_to_complex("test")
+ mock_complex_get_all.assert_not_called()
+
+ mock_cloud_region_property.return_value.complex = None
+ mock_complex_get_all.return_value = iter(())
+ cloud_region_resource._link_to_complex("test")
+ mock_cloud_region_property.return_value.link_to_complex.assert_not_called()
+
+ mock_complex_get_all.return_value = iter([Complex("test")])
+ cloud_region_resource._link_to_complex("test")
+ mock_cloud_region_property.return_value.link_to_complex.assert_called_once()
+
+
+@patch(
+ "onap_data_provider.resources.cloud_region_resource.CloudRegionResource.cloud_region",
+ new_callable=PropertyMock,
+)
+def test_cloud_region_resource_create_availability_zones(mock_cloud_region_property):
+ cloud_region_resource = CloudRegionResource(CLOUD_REGION_DATA)
+ cloud_region_resource.data["availability-zones"] = [
+ {"availability-zone-name": "testzone1", "hypervisor-type": "OpenStackTest"}
+ ]
+ cloud_region_resource.create()
+ mock_cloud_region_property.return_value.add_availability_zone.assert_called_once()
+
+
+@patch(
+ "onap_data_provider.resources.cloud_region_resource.CloudRegionResource.exists",
+ new_callable=PropertyMock,
+)
+@patch("onap_data_provider.resources.cloud_region_resource.ConnectivityInfo")
+@patch("onap_data_provider.resources.cloud_region_resource.CloudRegion.create")
+@patch("onap_data_provider.resources.cloud_region_resource.CloudRegion.complex")
+@patch("onap_data_provider.resources.cloud_region_resource.SoDbAdapter.add_cloud_site")
+def test_cloud_region_k8s_type(
+ mock_add_cloud_site,
+ _,
+ mock_cloud_region_create,
+ mock_connectivity_info,
+ mock_exists,
+):
+ mock_exists.return_value = False
+ mock_cloud_region_create.return_value = CloudRegion(
+ cloud_owner=CLOUD_REGION_K8S_TYPE["cloud-owner"],
+ cloud_region_id=CLOUD_REGION_K8S_TYPE["cloud-region-id"],
+ orchestration_disabled=CLOUD_REGION_K8S_TYPE["orchestration-disabled"],
+ in_maint=CLOUD_REGION_K8S_TYPE["in-maint"],
+ cloud_type=CLOUD_REGION_K8S_TYPE["cloud-type"],
+ )
+ cloud_region_resource = CloudRegionResource(CLOUD_REGION_K8S_TYPE)
+ cloud_region_resource.create()
+ mock_connectivity_info.get_connectivity_info_by_region_id.assert_called_once_with(
+ CLOUD_REGION_K8S_TYPE["cloud-region-id"]
+ )
+ mock_add_cloud_site.assert_called_once()
+
+ mock_connectivity_info.get_connectivity_info_by_region_id.side_effect = (
+ ResourceNotFound
+ )
+ cloud_region_resource.create()
+ mock_connectivity_info.create.assert_called_once()
diff --git a/tests/test_complex_resource.py b/tests/test_complex_resource.py
new file mode 100644
index 0000000..441b37c
--- /dev/null
+++ b/tests/test_complex_resource.py
@@ -0,0 +1,82 @@
+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",
+ )
diff --git a/tests/test_config_loader.py b/tests/test_config_loader.py
new file mode 100644
index 0000000..c10e329
--- /dev/null
+++ b/tests/test_config_loader.py
@@ -0,0 +1,27 @@
+
+from pathlib import Path
+
+from onap_data_provider.config_loader import ConfigLoader
+
+
+def test_config_loader_no_dirs():
+ config_loader = ConfigLoader([Path(Path(__file__).parent, "test-data.yml")])
+ configs = list(config_loader.load())
+ assert len(configs) == 1
+
+ config_loader = ConfigLoader([Path(Path(__file__).parent, "test-data.yml"),
+ Path(Path(__file__).parent, "test-data-version.yml")])
+ configs = list(config_loader.load())
+ assert len(configs) == 2
+
+def test_config_loader_dir():
+ config_loader = ConfigLoader([Path(Path(__file__).parent, "config_dirs")])
+ configs = list(config_loader.load())
+ assert len(configs) == 2
+
+def test_config_loader_both_dirs_and_files():
+ config_loader = ConfigLoader([Path(Path(__file__).parent, "test-data.yml"),
+ Path(Path(__file__).parent, "test-data-version.yml"),
+ Path(Path(__file__).parent, "config_dirs")])
+ configs = list(config_loader.load())
+ assert len(configs) == 4
diff --git a/tests/test_config_parser.py b/tests/test_config_parser.py
new file mode 100644
index 0000000..dc118c9
--- /dev/null
+++ b/tests/test_config_parser.py
@@ -0,0 +1,50 @@
+from pathlib import Path
+
+from onap_data_provider.resources.cloud_region_resource import CloudRegionResource
+from onap_data_provider.config_parser import ConfigParser
+
+
+def test_create_cloud_region_resource():
+ parser = ConfigParser([Path("tests/test-data.yml")])
+ parsed_objects = list(parser.parse())
+ assert isinstance(parsed_objects[1], CloudRegionResource)
+ assert parsed_objects[1].data['cloud-owner'] == 'AMIST'
+ assert parsed_objects[1].data['tenants'][0]['tenant-id'] == '-'.join(
+ [parsed_objects[1].data['cloud-owner'], 'TENANT', '1'])
+ assert parsed_objects[1].data['tenants'][1]['tenant-id'] == ''.join(
+ [parsed_objects[1].data['cloud-owner'], '-', 'TENANT', '-', '2'])
+
+
+def test_config_parser_versioning():
+ parser = ConfigParser([Path("tests/test-data.yml")])
+ config = parser.configs[0]
+ assert config.version.value.version_number == "None"
+ parsed_objects = list(parser.parse())
+ assert isinstance(parsed_objects[1], CloudRegionResource)
+ assert parsed_objects[1].data['cloud-owner'] == 'AMIST'
+ assert parsed_objects[1].data['tenants'][0]['tenant-id'] == '-'.join(
+ [parsed_objects[1].data['cloud-owner'], 'TENANT', '1'])
+ assert parsed_objects[1].data['tenants'][1]['tenant-id'] == ''.join(
+ [parsed_objects[1].data['cloud-owner'], '-', 'TENANT', '-', '2'])
+
+ parser = ConfigParser([Path("tests/test-data-version.yml")])
+ config = parser.configs[0]
+ assert config.version.value.version_number == "1.0"
+ parsed_objects = list(parser.parse())
+ assert isinstance(parsed_objects[1], CloudRegionResource)
+ assert parsed_objects[1].data['cloud-owner'] == 'AMIST'
+ assert parsed_objects[1].data['tenants'][0]['tenant-id'] == '-'.join(
+ [parsed_objects[1].data['cloud-owner'], 'TENANT', '1'])
+ assert parsed_objects[1].data['tenants'][1]['tenant-id'] == ''.join(
+ [parsed_objects[1].data['cloud-owner'], '-', 'TENANT', '-', '2'])
+
+ parser = ConfigParser([Path("tests/test-data.yml"), Path("tests/test-data-version.yml")])
+ assert parser.configs[0].version.value.version_number == "None"
+ assert parser.configs[1].version.value.version_number == "1.0"
+ parsed_objects = list(parser.parse())
+ assert isinstance(parsed_objects[1], CloudRegionResource)
+ assert parsed_objects[1].data['cloud-owner'] == 'AMIST'
+ assert parsed_objects[1].data['tenants'][0]['tenant-id'] == '-'.join(
+ [parsed_objects[1].data['cloud-owner'], 'TENANT', '1'])
+ assert parsed_objects[1].data['tenants'][1]['tenant-id'] == ''.join(
+ [parsed_objects[1].data['cloud-owner'], '-', 'TENANT', '-', '2'])
diff --git a/tests/test_customer_resource.py b/tests/test_customer_resource.py
new file mode 100644
index 0000000..23b51ef
--- /dev/null
+++ b/tests/test_customer_resource.py
@@ -0,0 +1,84 @@
+from unittest.mock import MagicMock, patch, PropertyMock
+
+from onap_data_provider.resources.customer_resource import CustomerResource
+
+from onapsdk.exceptions import ResourceNotFound
+
+CUSTOMER_DATA = {
+ "global-customer-id": "test_id",
+ "subscriber-name": "test_name",
+ "subscriber-type": "Customer",
+ "service-subscriptions": [{"service-type": "test_voip"}],
+}
+
+SERVICE_SUBSCRIPTION_WITH_TENANTS_DATA = {
+ "service-type": "test-service-subscription",
+ "tenants": [
+ {
+ "tenant-id": "1234",
+ "cloud-owner": "test-cloud-owner",
+ "cloud-region-id": "test-cloud-region",
+ }
+ ],
+}
+
+
+@patch(
+ "onap_data_provider.resources.customer_resource.Customer.get_by_global_customer_id"
+)
+def test_customer_resource_customer(mock_customer_get_by_global_customer_id):
+ mock_customer_get_by_global_customer_id.side_effect = ResourceNotFound
+ customer_resource = CustomerResource(CUSTOMER_DATA)
+ assert customer_resource.customer is None
+ mock_customer_get_by_global_customer_id.side_effect = None
+ mock_customer_get_by_global_customer_id.return_value = 1
+ assert customer_resource.customer == 1
+
+
+@patch(
+ "onap_data_provider.resources.customer_resource.CustomerResource.customer",
+ new_callable=PropertyMock,
+)
+def test_customer_exists(mock_customer):
+ mock_customer.return_value = None
+ customer_resource = CustomerResource(CUSTOMER_DATA)
+ assert customer_resource.exists is False
+ mock_customer.return_value = 1 # Anything but not None
+ assert customer_resource.exists is True
+
+
+@patch(
+ "onap_data_provider.resources.customer_resource.CustomerResource.exists",
+ new_callable=PropertyMock,
+)
+@patch("onap_data_provider.resources.customer_resource.Customer.create")
+def test_customer_create(mock_customer_create, mock_exists):
+ customer_resource = CustomerResource(CUSTOMER_DATA)
+ assert customer_resource.data == CUSTOMER_DATA
+ mock_exists.return_value = False
+ customer_resource.create()
+ assert mock_customer_create.called_once_with(
+ global_customer_id="test_id",
+ subscriber_name="test_name",
+ subscriber_type="Customer",
+ )
+
+
+@patch(
+ "onap_data_provider.resources.customer_resource.CustomerResource.ServiceSubscriptionResource.service_subscription",
+ new_callable=PropertyMock,
+)
+@patch("onap_data_provider.resources.customer_resource.CloudRegion")
+def test_service_subscription_with_tenants(
+ mock_cloud_region, _
+):
+ cloud_region_mock = MagicMock()
+ mock_cloud_region.get_by_id.return_value = cloud_region_mock
+ service_subscription_resource = CustomerResource.ServiceSubscriptionResource(
+ SERVICE_SUBSCRIPTION_WITH_TENANTS_DATA, MagicMock()
+ )
+ service_subscription_resource.create()
+ mock_cloud_region.get_by_id.assert_called_once_with(
+ "test-cloud-owner", "test-cloud-region"
+ )
+ cloud_region_mock.get_tenant.assert_called_once_with("1234")
diff --git a/tests/test_esr_resource.py b/tests/test_esr_resource.py
new file mode 100644
index 0000000..d6c8901
--- /dev/null
+++ b/tests/test_esr_resource.py
@@ -0,0 +1,82 @@
+from collections import namedtuple
+from unittest.mock import MagicMock, patch, PropertyMock
+
+from onap_data_provider.resources.esr_system_info_resource import (
+ CloudRegion,
+ EsrSystemInfoResource,
+)
+
+
+ESR_RESOURCE_DATA = {
+ "esr-system-info-id": "Test ID",
+ "user-name": "Test name",
+ "password": "testpass",
+ "system-type": "test type",
+ "service-url": "test url",
+ "cloud-domain": "test cloud domain",
+}
+
+
+EsrSystemInfoNamedtuple = namedtuple("EsrSystemInfo", ["esr_system_info_id"])
+
+
+@patch(
+ "onap_data_provider.resources.esr_system_info_resource.CloudRegion.esr_system_infos",
+ new_callable=PropertyMock,
+)
+def test_esr_system_info_resource_esr_system_info(mock_cloud_region_esr_system_infos):
+ cloud_region = CloudRegion(
+ cloud_owner="test",
+ cloud_region_id="test",
+ orchestration_disabled=True,
+ in_maint=True,
+ )
+ esr_resource = EsrSystemInfoResource(ESR_RESOURCE_DATA, cloud_region)
+ mock_cloud_region_esr_system_infos.return_value = iter([])
+ assert esr_resource.esr_system_info is None
+
+ mock_cloud_region_esr_system_infos.return_value = iter(
+ [EsrSystemInfoNamedtuple("Test ID")]
+ )
+ assert esr_resource.esr_system_info is not None
+
+
+@patch(
+ "onap_data_provider.resources.esr_system_info_resource.EsrSystemInfoResource.esr_system_info",
+ new_callable=PropertyMock,
+)
+def test_esr_system_info_resource_exists(mock_esr_system_info):
+ mock_esr_system_info.return_value = None
+ cloud_region_mock = MagicMock()
+ esr_resource = EsrSystemInfoResource(ESR_RESOURCE_DATA, cloud_region_mock)
+ assert esr_resource.exists is False
+
+ mock_esr_system_info.return_value = 1
+ assert esr_resource.exists is True
+
+
+@patch(
+ "onap_data_provider.resources.esr_system_info_resource.EsrSystemInfoResource.exists",
+ new_callable=PropertyMock,
+)
+def test_esr_system_info_resource_create(mock_exists):
+
+ cloud_region_mock = MagicMock()
+ esr_resource = EsrSystemInfoResource(ESR_RESOURCE_DATA, cloud_region_mock)
+
+ mock_exists.return_value = True
+ esr_resource.create()
+ cloud_region_mock.add_esr_system_info.assert_not_called()
+
+ mock_exists.return_value = False
+ esr_resource.create()
+ cloud_region_mock.add_esr_system_info.assert_called_once_with(
+ esr_system_info_id="Test ID",
+ user_name="Test name",
+ password="testpass",
+ system_type="test type",
+ system_status="active",
+ service_url="test url",
+ cloud_domain="test cloud domain",
+ default_tenant=None,
+ )
diff --git a/tests/test_line_of_business_resource.py b/tests/test_line_of_business_resource.py
new file mode 100644
index 0000000..1a60e8f
--- /dev/null
+++ b/tests/test_line_of_business_resource.py
@@ -0,0 +1,51 @@
+from unittest import mock
+
+from onap_data_provider.resources.line_of_business_resource import (
+ LineOfBusinessResource,
+ ResourceNotFound,
+)
+
+
+LINE_OF_BUSINESS = {"name": "test-name"}
+
+
+@mock.patch(
+ "onap_data_provider.resources.line_of_business_resource.LineOfBusiness.get_by_name"
+)
+def test_line_of_business_resource_line_of_business_property(mock_get_by_name):
+
+ lob = LineOfBusinessResource(LINE_OF_BUSINESS)
+ mock_get_by_name.side_effect = ResourceNotFound
+ assert lob.line_of_business is None
+
+ mock_get_by_name.side_effect = None
+ assert lob.line_of_business is not None
+
+
+@mock.patch(
+ "onap_data_provider.resources.line_of_business_resource.LineOfBusinessResource.line_of_business",
+ new_callable=mock.PropertyMock,
+)
+def test_line_of_business_resource_exists(mock_line_of_business):
+
+ lob = LineOfBusinessResource(LINE_OF_BUSINESS)
+ assert lob.exists is True
+ mock_line_of_business.return_value = None
+ assert lob.exists is False
+
+
+@mock.patch(
+ "onap_data_provider.resources.line_of_business_resource.LineOfBusinessResource.exists",
+ new_callable=mock.PropertyMock,
+)
+@mock.patch(
+ "onap_data_provider.resources.line_of_business_resource.LineOfBusiness.send_message"
+)
+def test_line_of_business_create(mock_send_message, mock_exists):
+ mock_exists.return_value = True
+ lob = LineOfBusinessResource(LINE_OF_BUSINESS)
+ lob.create()
+ mock_send_message.assert_not_called()
+ mock_exists.return_value = False
+ lob.create()
+ mock_send_message.assert_called()
diff --git a/tests/test_owning_entity_resource.py b/tests/test_owning_entity_resource.py
new file mode 100644
index 0000000..c32351c
--- /dev/null
+++ b/tests/test_owning_entity_resource.py
@@ -0,0 +1,51 @@
+from unittest import mock
+
+from onap_data_provider.resources.owning_entity_resource import (
+ OwningEntityResource,
+ ResourceNotFound,
+)
+
+
+OWNING_ENTITY = {"name": "test-name"}
+
+
+@mock.patch(
+ "onap_data_provider.resources.owning_entity_resource.OwningEntity.get_by_owning_entity_name"
+)
+def test_owning_entity_resource_owning_entity_property(mock_get_by_name):
+
+ owning_entity = OwningEntityResource(OWNING_ENTITY)
+ mock_get_by_name.side_effect = ResourceNotFound
+ assert owning_entity.owning_entity is None
+
+ mock_get_by_name.side_effect = None
+ assert owning_entity.owning_entity is not None
+
+
+@mock.patch(
+ "onap_data_provider.resources.owning_entity_resource.OwningEntityResource.owning_entity",
+ new_callable=mock.PropertyMock,
+)
+def test_owning_entity_resource_exists(mock_owning_entity):
+
+ owning_entity = OwningEntityResource(OWNING_ENTITY)
+ assert owning_entity.exists is True
+ mock_owning_entity.return_value = None
+ assert owning_entity.exists is False
+
+
+@mock.patch(
+ "onap_data_provider.resources.owning_entity_resource.OwningEntityResource.exists",
+ new_callable=mock.PropertyMock,
+)
+@mock.patch(
+ "onap_data_provider.resources.owning_entity_resource.OwningEntity.send_message"
+)
+def test_owning_entity_create(mock_send_message, mock_exists):
+ mock_exists.return_value = True
+ owning_entity = OwningEntityResource(OWNING_ENTITY)
+ owning_entity.create()
+ mock_send_message.assert_not_called()
+ mock_exists.return_value = False
+ owning_entity.create()
+ mock_send_message.assert_called()
diff --git a/tests/test_platform_resource.py b/tests/test_platform_resource.py
new file mode 100644
index 0000000..eafbae4
--- /dev/null
+++ b/tests/test_platform_resource.py
@@ -0,0 +1,47 @@
+from unittest import mock
+
+from onap_data_provider.resources.platform_resource import (
+ PlatformResource,
+ ResourceNotFound,
+)
+
+
+PLATFORM = {"name": "test-name"}
+
+
+@mock.patch("onap_data_provider.resources.platform_resource.Platform.get_by_name")
+def test_platform_resource_platform_property(mock_get_by_name):
+
+ platform = PlatformResource(PLATFORM)
+ mock_get_by_name.side_effect = ResourceNotFound
+ assert platform.platform is None
+
+ mock_get_by_name.side_effect = None
+ assert platform.platform is not None
+
+
+@mock.patch(
+ "onap_data_provider.resources.platform_resource.PlatformResource.platform",
+ new_callable=mock.PropertyMock,
+)
+def test_platform_resource_exists(mock_platform):
+
+ platform = PlatformResource(PLATFORM)
+ assert platform.exists is True
+ mock_platform.return_value = None
+ assert platform.exists is False
+
+
+@mock.patch(
+ "onap_data_provider.resources.platform_resource.PlatformResource.exists",
+ new_callable=mock.PropertyMock,
+)
+@mock.patch("onap_data_provider.resources.platform_resource.Platform.send_message")
+def test_platform_create(mock_send_message, mock_exists):
+ mock_exists.return_value = True
+ platform = PlatformResource(PLATFORM)
+ platform.create()
+ mock_send_message.assert_not_called()
+ mock_exists.return_value = False
+ platform.create()
+ mock_send_message.assert_called()
diff --git a/tests/test_pnf_resource.py b/tests/test_pnf_resource.py
new file mode 100644
index 0000000..c58717a
--- /dev/null
+++ b/tests/test_pnf_resource.py
@@ -0,0 +1,28 @@
+from unittest.mock import patch, PropertyMock
+
+from onap_data_provider.resources.pnf_resource import PnfResource
+
+PNF_RESOURCE_DATA = {"name": "test_pnf"}
+
+
+@patch(
+ "onap_data_provider.resources.pnf_resource.PnfResource.pnf",
+ new_callable=PropertyMock,
+)
+def test_pnf_resource_exists(mock_pnf):
+ mock_pnf.return_value = None
+ pnf_resource = PnfResource(PNF_RESOURCE_DATA)
+ assert pnf_resource.exists is False
+ mock_pnf.return_value = 1 # Anything but not None
+ assert pnf_resource.exists is True
+
+
+@patch(
+ "onap_data_provider.resources.pnf_resource.Pnf.created",
+)
+def test_pnf_resource_pnf(mock_pnf_created):
+ mock_pnf_created.return_value = False
+ pnf_resource = PnfResource(PNF_RESOURCE_DATA)
+ assert pnf_resource.pnf is None
+ mock_pnf_created.return_value = True
+ assert pnf_resource.pnf is not None
diff --git a/tests/test_project_resource.py b/tests/test_project_resource.py
new file mode 100644
index 0000000..c1ff167
--- /dev/null
+++ b/tests/test_project_resource.py
@@ -0,0 +1,47 @@
+from unittest import mock
+
+from onap_data_provider.resources.project_resource import (
+ ProjectResource,
+ ResourceNotFound,
+)
+
+
+PROJECT = {"name": "test-name"}
+
+
+@mock.patch("onap_data_provider.resources.project_resource.Project.get_by_name")
+def test_project_resource_project_property(mock_get_by_name):
+
+ project = ProjectResource(PROJECT)
+ mock_get_by_name.side_effect = ResourceNotFound
+ assert project.project is None
+
+ mock_get_by_name.side_effect = None
+ assert project.project is not None
+
+
+@mock.patch(
+ "onap_data_provider.resources.project_resource.ProjectResource.project",
+ new_callable=mock.PropertyMock,
+)
+def test_project_resource_exists(mock_project):
+
+ project = ProjectResource(PROJECT)
+ assert project.exists is True
+ mock_project.return_value = None
+ assert project.exists is False
+
+
+@mock.patch(
+ "onap_data_provider.resources.project_resource.ProjectResource.exists",
+ new_callable=mock.PropertyMock,
+)
+@mock.patch("onap_data_provider.resources.project_resource.Project.send_message")
+def test_project_create(mock_send_message, mock_exists):
+ mock_exists.return_value = True
+ project = ProjectResource(PROJECT)
+ project.create()
+ mock_send_message.assert_not_called()
+ mock_exists.return_value = False
+ project.create()
+ mock_send_message.assert_called()
diff --git a/tests/test_resource_creator.py b/tests/test_resource_creator.py
new file mode 100644
index 0000000..a8e62ed
--- /dev/null
+++ b/tests/test_resource_creator.py
@@ -0,0 +1,31 @@
+import pytest
+
+from onap_data_provider.resources.cloud_region_resource import CloudRegionResource
+from onap_data_provider.resources.complex_resource import ComplexResource
+from onap_data_provider.resources.resource_creator import ResourceCreator
+from onap_data_provider.versions import VersionsEnum
+
+
+def test_create_cloud_region_resource():
+ cloud_region_resource = ResourceCreator.create("cloud-region", {"a": "B"}, VersionsEnum.NONE)
+ assert isinstance(cloud_region_resource, CloudRegionResource)
+ assert cloud_region_resource.data == {"a": "B"}
+ cloud_region_resource = ResourceCreator.create("cloud-region", {"a": "B"}, VersionsEnum.V1_0)
+ assert isinstance(cloud_region_resource, CloudRegionResource)
+ assert cloud_region_resource.data == {"a": "B"}
+
+
+def test_create_complex_resource():
+ complex_resource = ResourceCreator.create("complex", {"a": "B"}, VersionsEnum.NONE)
+ assert isinstance(complex_resource, ComplexResource)
+ assert complex_resource.data == {"a": "B"}
+ complex_resource = ResourceCreator.create("complex", {"a": "B"}, VersionsEnum.V1_0)
+ assert isinstance(complex_resource, ComplexResource)
+ assert complex_resource.data == {"a": "B"}
+
+
+def test_create_invalid_resource():
+ with pytest.raises(ValueError):
+ ResourceCreator.create("invalid", {}, VersionsEnum.NONE)
+ with pytest.raises(ValueError):
+ ResourceCreator.create("invalid", {}, VersionsEnum.V1_0)
diff --git a/tests/test_service_instance_resource.py b/tests/test_service_instance_resource.py
new file mode 100644
index 0000000..69a9e57
--- /dev/null
+++ b/tests/test_service_instance_resource.py
@@ -0,0 +1,141 @@
+from unittest.mock import MagicMock, patch, PropertyMock
+
+from onap_data_provider.resources.service_instance_resource import (
+ ServiceInstanceResource
+)
+from onapsdk.exceptions import APIError
+
+RESOURCE_DATA_1_0 = {
+ "service_instance_name": "vFW-Macro-1",
+ "service_name": "service1",
+ "cloud_region": "test",
+ "customer_id": "*cust1",
+ "owning_entity": "test",
+ "project": "test",
+ "platform": "test",
+ "line_of_business": "test",
+ "cloud_region_id": "*cloudregionid1",
+ "cloud_owner": "*cloudowner1",
+ "tenant_id": "test",
+ "instantiation_parameters": [],
+}
+
+
+RESOURCE_DATA_1_1 = {
+ "service_instance_name": "vFW-Macro-1",
+ "service_name": "service1",
+ "cloud_region": "test",
+ "customer_id": "*cust1",
+ "owning_entity": "test",
+ "project": "test",
+ "platform": "test",
+ "line_of_business": "test",
+ "cloud_region_id": "*cloudregionid1",
+ "cloud_owner": "*cloudowner1",
+ "tenant_id": "test",
+ "instantiation_parameters": [],
+ "aai_service": "test"
+}
+
+
+INSTANTIATION_PARAMETERS_DATA = {
+ "service_name": "service1",
+ "instantiation_parameters": [
+ {
+ "vnf_name": "test",
+ "parameters": {"a": "b", "c": "d"},
+ "vf_modules": [
+ {
+ "name": "base_ubuntu20",
+ "parameters": {
+ "ubuntu20_image_name": "Ubuntu_2004",
+ "ubuntu20_key_name": "cleouverte",
+ "ubuntu20_pub_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDY15cdBmIs2XOpe4EiFCsaY6bmUmK/GysMoLl4UG51JCfJwvwoWCoA+6mDIbymZxhxq9IGxilp/yTA6WQ9s/5pBag1cUMJmFuda9PjOkXl04jgqh5tR6I+GZ97AvCg93KAECis5ubSqw1xOCj4utfEUtPoF1OuzqM/lE5mY4N6VKXn+fT7pCD6cifBEs6JHhVNvs5OLLp/tO8Pa3kKYQOdyS0xc3rh+t2lrzvKUSWGZbX+dLiFiEpjsUL3tDqzkEMNUn4pdv69OJuzWHCxRWPfdrY9Wg0j3mJesP29EBht+w+EC9/kBKq+1VKdmsXUXAcjEvjovVL8l1BrX3BY0R8D imported-openssh-key",
+ "ubuntu20_flavor_name": "m1.smaller",
+ "VM_name": "ubuntu20agent-VM-01",
+ "vnf_id": "ubuntu20agent-VNF-instance",
+ "vf_module_id": "ubuntu20agent-vfmodule-instance",
+ "vnf_name": "ubuntu20agent-VNF",
+ "admin_plane_net_name": "admin",
+ "ubuntu20_name_0": "ubuntu20agent-VNF",
+ },
+ }
+ ],
+ }
+ ]
+}
+
+
+@patch(
+ "onap_data_provider.resources.service_instance_resource.ServiceInstanceResource.service_instance",
+ new_callable=PropertyMock,
+)
+def test_si_resource_exists(mock_si):
+ mock_si.return_value = None
+ si_resource = ServiceInstanceResource(RESOURCE_DATA_1_1)
+ assert si_resource.exists is False
+ mock_si.return_value = 1 # Anything but not None
+ assert si_resource.exists is True
+
+
+@patch(
+ "onap_data_provider.resources.service_instance_resource.ServiceInstanceResource.exists",
+ new_callable=PropertyMock,
+)
+@patch("onap_data_provider.resources.service_instance_resource.Customer")
+@patch("onap_data_provider.resources.service_instance_resource.Project")
+@patch("onap_data_provider.resources.service_instance_resource.OwningEntity")
+@patch("onap_data_provider.resources.service_instance_resource.CloudRegion")
+@patch("onap_data_provider.resources.service_instance_resource.ServiceInstantiation")
+@patch("onap_data_provider.resources.service_instance_resource.Service")
+@patch("onap_data_provider.resources.service_instance_resource.AaiService")
+def test_si_resource_create(
+ mock_aai_service,
+ mock_service,
+ mock_service_instantionation,
+ mock_cr,
+ mock_oe,
+ mock_project,
+ mock_customer,
+ mock_si_resource_exists,
+):
+ si_resource = ServiceInstanceResource(RESOURCE_DATA_1_1)
+ mock_oe.get_by_owning_entity_name.side_effect = APIError
+ mock_si_resource_exists.return_value = True
+ si_resource.create()
+ mock_service.assert_not_called()
+
+ mock_si_resource_exists.return_value = False
+ si_resource.create()
+ mock_oe.create.assert_called_once()
+ mock_oe.get_by_owning_entity_name.assert_called_once()
+ mock_aai_service.get_all.called_once_with(service_id="test")
+ mock_service_instantionation.instantiate_macro.assert_called_once()
+
+
+def test_so_service():
+ si_resource = ServiceInstanceResource(INSTANTIATION_PARAMETERS_DATA)
+ so_service = si_resource.so_service
+ assert so_service.subscription_service_type == "service1"
+ assert len(so_service.vnfs) == 1
+ vnf = so_service.vnfs[0]
+ assert vnf["model_name"] == "test"
+ assert vnf["vnf_name"] == "test"
+ assert len(vnf["parameters"]) == 2
+ assert len(vnf["vf_modules"]) == 1
+ vf_module = vnf["vf_modules"][0]
+ assert vf_module["model_name"] == "base_ubuntu20"
+ assert vf_module["vf_module_name"] == "base_ubuntu20"
+ assert len(vf_module["parameters"]) == 10
+
+
+@patch("onap_data_provider.resources.service_instance_resource.AaiService.get_all")
+def test_service_instance_resource_version_1_0_and_1_1(mock_aai_service_get_all):
+ si_resource_1_0 = ServiceInstanceResource(RESOURCE_DATA_1_0)
+ assert si_resource_1_0.aai_service is None
+ mock_aai_service_get_all.assert_not_called()
+
+ mock_aai_service_get_all.return_value = iter([MagicMock()])
+ si_resource_1_0 = ServiceInstanceResource(RESOURCE_DATA_1_1)
+ assert si_resource_1_0.aai_service is not None
+ mock_aai_service_get_all.assert_called_once()
diff --git a/tests/test_service_resource.py b/tests/test_service_resource.py
new file mode 100644
index 0000000..f664676
--- /dev/null
+++ b/tests/test_service_resource.py
@@ -0,0 +1,50 @@
+from collections import namedtuple
+from unittest.mock import patch, PropertyMock
+
+from onap_data_provider.resources.service_resource import ServiceResource
+
+
+SERVICE_RESOURCE_DATA = {
+ "name": "test",
+}
+
+
+@patch("onap_data_provider.resources.service_resource.Service.created")
+def test_service_resource_service_property(mock_service_created):
+ service_resource = ServiceResource(SERVICE_RESOURCE_DATA)
+ mock_service_created.return_value = False
+ assert service_resource.service is None
+
+ mock_service_created.return_value = True
+ assert service_resource.service is not None
+
+
+@patch(
+ "onap_data_provider.resources.service_resource.ServiceResource.service",
+ new_callable=PropertyMock,
+)
+def test_service_resource_exists(mock_service_resource_service):
+ service_resource = ServiceResource(SERVICE_RESOURCE_DATA)
+ mock_service_resource_service.return_value = None
+ assert service_resource.exists is False
+ ServiceNamedtuple = namedtuple(
+ "ServiceNamedtuple", ["distributed"], defaults=[True]
+ )
+ mock_service_resource_service.return_value = ServiceNamedtuple()
+ assert service_resource.exists is True
+
+
+@patch(
+ "onap_data_provider.resources.service_resource.ServiceResource.exists",
+ new_callable=PropertyMock,
+)
+@patch("onap_data_provider.resources.service_resource.Service")
+def test_service_resource_create(mock_service, mock_service_resource_exists):
+ service_resource = ServiceResource(SERVICE_RESOURCE_DATA)
+ mock_service_resource_exists.return_value = True
+ service_resource.create()
+ mock_service.assert_not_called()
+
+ mock_service_resource_exists.return_value = False
+ service_resource.create()
+ mock_service.assert_called_once()
diff --git a/tests/test_tag_handlers.py b/tests/test_tag_handlers.py
new file mode 100644
index 0000000..719295f
--- /dev/null
+++ b/tests/test_tag_handlers.py
@@ -0,0 +1,15 @@
+from unittest.mock import patch, PropertyMock
+from onap_data_provider.tag_handlers import join, generate_random_uuid
+
+
+def test_generate_random_uuid():
+ uuid1 = generate_random_uuid(None, None)
+ uuid2 = generate_random_uuid(None, None)
+ assert isinstance(uuid1, str)
+ assert uuid1 != uuid2
+
+
+@patch("yaml.SafeLoader", new_callable=PropertyMock)
+def test_join(mock_safe_loader):
+ mock_safe_loader.construct_sequence.return_value = ["-", ["cloud", "owner", "DC1"]]
+ assert join(mock_safe_loader, None) == "cloud-owner-DC1"
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
+ )
diff --git a/tests/test_validator.py b/tests/test_validator.py
new file mode 100644
index 0000000..ad291a9
--- /dev/null
+++ b/tests/test_validator.py
@@ -0,0 +1,123 @@
+from pytest import raises
+from jsonschema import ValidationError
+
+from onap_data_provider.validator import Validator
+from onap_data_provider.versions import VersionsEnum
+
+
+def test_validator_customer():
+ validator = Validator()
+ input_data = {
+ "customers": [
+ {
+ "customer": {
+ "global-customer-id": "test",
+ "subscriber-name": "test",
+ "subscriber-type": "test",
+ }
+ }
+ ]
+ }
+ validator.validate(VersionsEnum.NONE, input_data)
+ input_data = {
+ "customers": [
+ {
+ "customer": {
+ "global-customer-id": "test",
+ "subscriber-name": "test",
+ "subscriber-type": "test",
+ }
+ }
+ ]
+ }
+ validator.validate(VersionsEnum.V1_0, input_data)
+
+ invalid_input_data = { # Missing subscriber-type
+ "customers": [
+ {"customer": {"global-customer-id": "test", "subscriber-name": "test"}}
+ ]
+ }
+ with raises(ValidationError):
+ validator.validate(VersionsEnum.V1_0, invalid_input_data)
+
+
+def test_validator_vsps():
+ validator = Validator()
+ input_data = {
+ "vsps": [
+ {
+ "vsp": {
+ "name": "test",
+ "vendor": "test",
+ "package": "test",
+ }
+ }
+ ]
+ }
+ validator.validate(VersionsEnum.NONE, input_data)
+
+ input_data = {
+ "vsps": [
+ {
+ "vsp": {
+ "name": "test",
+ "vendor": "test",
+ "package": "test",
+ }
+ }
+ ]
+ }
+ validator.validate(VersionsEnum.V1_0, input_data)
+
+ input_data = {
+ "vsps": [
+ {
+ "vsp": {
+ "name": "test",
+ }
+ }
+ ]
+ }
+ with raises(ValidationError):
+ validator.validate(VersionsEnum.V1_0, input_data)
+
+
+def test_validator_service():
+ validator = Validator()
+ input_data = {
+ "services": [
+ {
+ "service": {
+ "name": "test",
+ "resources": [
+ {"name": "test", "type": "test"},
+ {"name": "test1", "type": "test2"},
+ ],
+ "properties": [
+ {"name": "test", "type": "test", "value": "test"},
+ {"name": "test1", "type": "test1"},
+ ],
+ }
+ }
+ ]
+ }
+ validator.validate(VersionsEnum.NONE, input_data)
+
+ input_data = {
+ "services": [
+ {
+ "service": {
+ "name": "test",
+ "resources": [
+ {"name": "test", "type": "test"},
+ {"name": "test1", "type": "test2"},
+ ],
+ "properties": [
+ {"name": "test", "type": "test", "value": "test"},
+ {"name": "test1", "type": "test1"},
+ ],
+ }
+ }
+ ]
+ }
+ validator.validate(VersionsEnum.V1_0, input_data)
diff --git a/tests/test_vendor_resource.py b/tests/test_vendor_resource.py
new file mode 100644
index 0000000..2a4d0aa
--- /dev/null
+++ b/tests/test_vendor_resource.py
@@ -0,0 +1,28 @@
+from unittest.mock import patch, PropertyMock
+
+from onap_data_provider.resources.vendor_resource import VendorResource
+
+VENDOR_RESOURCE_DATA = {"name": "testVendor"}
+
+
+@patch(
+ "onap_data_provider.resources.vendor_resource.VendorResource.vendor",
+ new_callable=PropertyMock,
+)
+def test_vendor_resource_exists(mock_vendor):
+ mock_vendor.return_value = None
+ vendor_resource = VendorResource(VENDOR_RESOURCE_DATA)
+ assert vendor_resource.exists is False
+ mock_vendor.return_value = 1 # Anything but not None
+ assert vendor_resource.exists is True
+
+
+@patch(
+ "onap_data_provider.resources.vendor_resource.Vendor.created",
+)
+def test_vendor_resource_vendor(mock_vendor_created):
+ mock_vendor_created.return_value = False
+ vendor_resource = VendorResource(VENDOR_RESOURCE_DATA)
+ assert vendor_resource.vendor is None
+ mock_vendor_created.return_value = True
+ assert vendor_resource.vendor is not None
diff --git a/tests/test_versions.py b/tests/test_versions.py
new file mode 100644
index 0000000..7571854
--- /dev/null
+++ b/tests/test_versions.py
@@ -0,0 +1,15 @@
+import warnings
+
+from onap_data_provider.versions import VersionsEnum
+
+
+def test_versions_init():
+ v_none = VersionsEnum.get_version_by_number("None")
+ assert v_none == VersionsEnum.NONE
+ assert v_none.value.version_number == "None"
+ assert v_none.value.schema_path
+
+ v_1_0 = VersionsEnum.get_version_by_number("1.0")
+ assert v_1_0 == VersionsEnum.V1_0
+ assert v_1_0.value.version_number == "1.0"
+ assert v_1_0.value.schema_path
diff --git a/tests/test_vnf_resource.py b/tests/test_vnf_resource.py
new file mode 100644
index 0000000..6398aec
--- /dev/null
+++ b/tests/test_vnf_resource.py
@@ -0,0 +1,28 @@
+from unittest.mock import patch, PropertyMock
+
+from onap_data_provider.resources.vnf_resource import VnfResource
+
+VNF_RESOURCE_DATA = {"name": "test_vnf"}
+
+
+@patch(
+ "onap_data_provider.resources.vnf_resource.VnfResource.vnf",
+ new_callable=PropertyMock,
+)
+def test_vnf_resource_exists(mock_vnf):
+ mock_vnf.return_value = None
+ vnf_resource = VnfResource(VNF_RESOURCE_DATA)
+ assert vnf_resource.exists is False
+ mock_vnf.return_value = 1 # Anything but not None
+ assert vnf_resource.exists is True
+
+
+@patch(
+ "onap_data_provider.resources.vnf_resource.Vf.created",
+)
+def test_vnf_resource_vnf(mock_vnf_created):
+ mock_vnf_created.return_value = False
+ vnf_resource = VnfResource(VNF_RESOURCE_DATA)
+ assert vnf_resource.vnf is None
+ mock_vnf_created.return_value = True
+ assert vnf_resource.vnf is not None
diff --git a/tests/test_vsp_resource.py b/tests/test_vsp_resource.py
new file mode 100644
index 0000000..9ad5bb6
--- /dev/null
+++ b/tests/test_vsp_resource.py
@@ -0,0 +1,28 @@
+from unittest.mock import patch, PropertyMock
+
+from onap_data_provider.resources.vsp_resource import VspResource
+
+
+VSP_RESOURCE_DATA = {"name": "test", "vendor": "test", "package": "test"}
+
+
+@patch("onap_data_provider.resources.vsp_resource.Vsp.created")
+def test_vsp_resource_vsp_property(mock_vsp_created):
+ vsp_resource = VspResource(VSP_RESOURCE_DATA)
+ mock_vsp_created.return_value = False
+ assert vsp_resource.vsp is None
+
+ mock_vsp_created.return_value = True
+ assert vsp_resource.vsp is not None
+
+
+@patch(
+ "onap_data_provider.resources.vsp_resource.VspResource.vsp",
+ new_callable=PropertyMock,
+)
+def test_vsp_resource_exists(mock_vsp):
+ mock_vsp.return_value = None
+ vsp_resource = VspResource(VSP_RESOURCE_DATA)
+ assert not vsp_resource.exists
+ mock_vsp.return_value = 1
+ assert vsp_resource.exists