diff options
Diffstat (limited to 'tests/test_aai_service.py')
-rw-r--r-- | tests/test_aai_service.py | 83 |
1 files changed, 47 insertions, 36 deletions
diff --git a/tests/test_aai_service.py b/tests/test_aai_service.py index aac4c59..a13131a 100644 --- a/tests/test_aai_service.py +++ b/tests/test_aai_service.py @@ -23,11 +23,10 @@ from onapsdk.aai.cloud_infrastructure import ( EsrSystemInfo, Tenant ) -from onapsdk.aai.business import Customer +from onapsdk.aai.business import Customer, ServiceInstance from onapsdk.aai.service_design_and_creation import Service, Model from onapsdk.onap_service import OnapService - # pylint: disable=C0301 TENANT = { "tenant": [ @@ -88,7 +87,6 @@ TENANT = { ] } - CLOUD_REGIONS = { "cloud-region": [ { @@ -122,7 +120,6 @@ CLOUD_REGIONS = { ] } - CLOUD_REGION = { "cloud-region": [ { @@ -156,7 +153,6 @@ CLOUD_REGION = { ] } - COMPLEXES = { "complex": [ { @@ -225,7 +221,6 @@ COMPLEXES = { ] } - CLOUD_REGION_RELATIONSHIP = { "relationship": [ { @@ -242,7 +237,6 @@ CLOUD_REGION_RELATIONSHIP = { ] } - SERVICE_SUBSCRIPTION = { "service-subscription": [ { @@ -282,7 +276,6 @@ SERVICE_SUBSCRIPTION = { ] } - SUBSCRIPTION_TYPES_NO_RESOURCES = { "requestError": { "serviceException": { @@ -292,8 +285,8 @@ SUBSCRIPTION_TYPES_NO_RESOURCES = { "GET", "service-design-and-creation/services", ( - "Node Not Found:No Node of type service found at: " - + "/service-design-and-creation/services" + "Node Not Found:No Node of type service found at: " + + "/service-design-and-creation/services" ), "ERR.5.4.6114", ], @@ -301,7 +294,6 @@ SUBSCRIPTION_TYPES_NO_RESOURCES = { } } - SUBSCRIPTION_TYPES_LIST = { "service": [ { @@ -322,7 +314,6 @@ SUBSCRIPTION_TYPES_LIST = { ] } - CUSTOMERS_NO_RESOURCES = { "requestError": { "serviceException": { @@ -332,8 +323,8 @@ CUSTOMERS_NO_RESOURCES = { "GET", "business/customers", ( - "Node Not Found:No Node of type customer found at: " - + "business/customers" + "Node Not Found:No Node of type customer found at: " + + "business/customers" ), "ERR.5.4.6114", ], @@ -341,7 +332,6 @@ CUSTOMERS_NO_RESOURCES = { } } - SIMPLE_CUSTOMER = { "customer": [ { @@ -353,7 +343,6 @@ SIMPLE_CUSTOMER = { ] } - ESR_SYSTEM_INFO = { 'esr-system-info': [ { @@ -368,28 +357,29 @@ ESR_SYSTEM_INFO = { ] } - CLOUD_REGIONS_ITERATOR = ( cloud_region for cloud_region in [ - CloudRegion( - cloud_owner="OPNFV", - cloud_region_id="RegionOne", - cloud_type="openstack", - owner_defined_type="N/A", - cloud_region_version="pike", - identity_url=None, - cloud_zone="OPNFV LaaS", - complex_name="Cruguil", - sriov_automation=None, - cloud_extra_info=None, - upgrade_cycle=None, - orchestration_disabled=False, - in_maint=False, - resource_version=None, - ) - ] + CloudRegion( + cloud_owner="OPNFV", + cloud_region_id="RegionOne", + cloud_type="openstack", + owner_defined_type="N/A", + cloud_region_version="pike", + identity_url=None, + cloud_zone="OPNFV LaaS", + complex_name="Cruguil", + sriov_automation=None, + cloud_extra_info=None, + upgrade_cycle=None, + orchestration_disabled=False, + in_maint=False, + resource_version=None, + ) +] ) + + # pylint: enable=C0301 @@ -410,6 +400,7 @@ def test_class_variables(): "x-transactionid": "0a3f6713-ba96-4971-a6f8-c2da85a3176e", "authorization": "Basic QUFJOkFBSQ=="} + @mock.patch.object(AaiElement, 'send_message_json') def test_customers(mock_send): """Test get_customer function of A&AI.""" @@ -422,6 +413,7 @@ def test_customers(mock_send): assert aai_customer_1.resource_version == "1561218640404" mock_send.assert_called_with("GET", 'get customers', mock.ANY) + @mock.patch.object(AaiElement, 'send_message_json') def test_customers_no_resources(mock_send): """Test get_customer function with no customer declared in A&AI.""" @@ -429,6 +421,7 @@ def test_customers_no_resources(mock_send): assert len(list(Customer.get_all())) == 0 mock_send.assert_called_with("GET", 'get customers', mock.ANY) + @mock.patch.object(AaiElement, 'send_message_json') def test_subscription_type_list(mock_send): """Test the getter of subscription types in A&AI.""" @@ -454,6 +447,7 @@ def test_subscription_type_list(mock_send): assert aai_service_3.resource_version == "1561219799684" mock_send.assert_called_with("GET", 'get subscriptions', mock.ANY) + @mock.patch.object(AaiElement, 'send_message_json') def test_subscription_types_no_resources(mock_send): """Test get_customer function with no customer declared in A&AI.""" @@ -461,6 +455,7 @@ def test_subscription_types_no_resources(mock_send): assert len(list(Service.get_all())) == 0 mock_send.assert_called_with("GET", 'get subscriptions', mock.ANY) + @mock.patch.object(AaiElement, 'send_message_json') def test_cloud_regions(mock_send): """Test get cloud regions from A&AI.""" @@ -487,6 +482,7 @@ def test_cloud_regions(mock_send): cloud_regions = list(CloudRegion.get_all()) assert len(cloud_regions) == 1 + @mock.patch.object(CloudRegion, "send_message") def test_cloud_region_creation(mock_send): """Test cloud region creation""" @@ -514,6 +510,7 @@ def test_cloud_region_creation(mock_send): assert cloud_region.cloud_extra_info == "" assert cloud_region.upgrade_cycle == "Test" + @mock.patch.object(CloudRegion, 'get_all') @mock.patch.object(AaiElement, 'send_message_json') def test_tenants_info(mock_send, mock_cloud_regions): @@ -536,6 +533,7 @@ def test_tenants_info(mock_send, mock_cloud_regions): f"resource-version=1562591004273" ) + @mock.patch.object(CloudRegion, 'get_all') @mock.patch.object(AaiElement, 'send_message_json') def test_tenants_info_wrong_cloud_name(mock_send, mock_cloud_regions): @@ -558,7 +556,7 @@ def test_cloud_regions_relationship(mock_send): assert isinstance(relationship, Relationship) assert relationship.relationship_label == "org.onap.relationships.inventory.LocatedIn" assert relationship.related_link == \ - "/aai/v16/cloud-infrastructure/complexes/complex/integration_test_complex" + "/aai/v16/cloud-infrastructure/complexes/complex/integration_test_complex" assert relationship.related_to == "complex" assert relationship.relationship_data[0]["relationship-key"] == "complex.physical-location-id" assert relationship.relationship_data[0]["relationship-value"] == "integration_test_complex" @@ -594,6 +592,7 @@ def test_cloud_regions_esr_system_infos(mock_send): assert esr_system_info.system_status is None assert esr_system_info.openstack_region_id is None + @mock.patch.object(Complex, "send_message") def test_create_complex(mock_send): """Test complex creation""" @@ -701,6 +700,8 @@ SIMPLE_MODEL = { } ] } + + # pylint: enable=C0301 @@ -708,7 +709,7 @@ def test_service_url(): """Test service property""" service = Service("12345", "description", "version1.0") assert service.url == (f"{service.base_url}{service.api_version}/service-design-and-creation/services/service/" - f"{service.service_id}?resource-version={service.resource_version}") + f"{service.service_id}?resource-version={service.resource_version}") @mock.patch.object(Service, 'send_message') @@ -768,3 +769,13 @@ def test_cloud_region_complex_property(mock_complex_get_by_physical_location_id, mock_send.return_value = CLOUD_REGION_RELATIONSHIP assert cloud_region.complex is not None assert mock_complex_get_by_physical_location_id.called_once_with("integration_test_complex") + + +@mock.patch.object(ServiceInstance, 'send_message') +def test_service_instance_create(mock_send): + """Test service instance creation""" + service_subscription = mock.MagicMock() + ServiceInstance.create(service_subscription=service_subscription, instance_id="1234") + mock_send.assert_called_once() + method, description, url = mock_send.call_args[0] + assert method == "PUT" |