diff options
Diffstat (limited to 'integration_tests/test_06_customer.py')
-rw-r--r-- | integration_tests/test_06_customer.py | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/integration_tests/test_06_customer.py b/integration_tests/test_06_customer.py new file mode 100644 index 0000000..62ac3f0 --- /dev/null +++ b/integration_tests/test_06_customer.py @@ -0,0 +1,85 @@ +# Copyright 2022 Orange, 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 uuid import uuid4 + +import pytest + +import requests +from onapsdk.aai.cloud_infrastructure import CloudRegion, Tenant +from onapsdk.aai.business import Customer, ServiceSubscription +from onapsdk.exceptions import ParameterError +from onapsdk.sdc.service import Service + + +@pytest.mark.integration +def test_create_customer(): + + requests.get(f"{Customer.base_url}/reset") + + customers = list(Customer.get_all()) + assert len(customers) == 0 + + customer = Customer.create(global_customer_id="test_global_customer_id", + subscriber_name="test_subscriber_name", + subscriber_type="test_subscriber_type") + assert customer.global_customer_id == "test_global_customer_id" + assert customer.subscriber_name == "test_subscriber_name" + assert customer.subscriber_type == "test_subscriber_type" + + customers = list(Customer.get_all()) + assert len(customers) == 1 + + +@pytest.mark.integration +def test_subscribe_service(): + + requests.get(f"{Customer.base_url}/reset") + + customer = Customer.create(global_customer_id="test_global_customer_id", + subscriber_name="test_subscriber_name", + subscriber_type="test_subscriber_type") + assert len(list(customer.service_subscriptions)) == 0 + + customer.subscribe_service("service_type") + assert len(list(customer.service_subscriptions)) == 1 + assert customer.get_service_subscription_by_service_type("service_type") + + +@pytest.mark.integration +def test_link_service_subscription_to_cloud_region_and_tenant(): + + requests.get(f"{Customer.base_url}/reset") + + customer = Customer.create(global_customer_id="test_global_customer_id", + subscriber_name="test_subscriber_name", + subscriber_type="test_subscriber_type") + customer.subscribe_service("service_type") + service_subscription = customer.get_service_subscription_by_service_type("service_type") + + assert len(list(service_subscription.relationships)) == 0 + with pytest.raises(ParameterError): + service_subscription.cloud_region + with pytest.raises(ParameterError): + service_subscription.tenant + + cloud_region = CloudRegion.create( + "test_owner", "test_cloud_region", orchestration_disabled=True, in_maint=False + ) + cloud_region.add_tenant( + tenant_id="test_tenant_name", tenant_name="test_tenant_name", tenant_context="test_tenant_context" + ) + tenant = cloud_region.get_tenant(tenant_id="test_tenant_name") + service_subscription.link_to_cloud_region_and_tenant(cloud_region=cloud_region, tenant=tenant) + assert service_subscription.cloud_region + assert service_subscription.tenant |