aboutsummaryrefslogtreecommitdiffstats
path: root/integration_tests/test_06_customer.py
blob: 62ac3f025623933043a03e322ea83fc8b5b2ac71 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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