diff options
-rw-r--r-- | .gitlab-ci.yml | 153 | ||||
-rw-r--r-- | src/onapsdk/aai/aai_element.py | 33 | ||||
-rw-r--r-- | src/onapsdk/aai/cloud_infrastructure/cloud_region.py | 22 | ||||
-rw-r--r-- | src/onapsdk/aai/cloud_infrastructure/complex.py | 3 | ||||
-rw-r--r-- | src/onapsdk/aai/mixins/__init__.py | 14 | ||||
-rw-r--r-- | src/onapsdk/aai/mixins/link_to_complex.py | 47 | ||||
-rw-r--r-- | src/onapsdk/aai/mixins/link_to_geo_region.py | 44 | ||||
-rw-r--r-- | src/onapsdk/aai/network/site_resource.py | 36 | ||||
-rw-r--r-- | src/onapsdk/configuration/global_settings.py | 2 | ||||
-rw-r--r-- | tests/test_aai_complex.py | 7 | ||||
-rw-r--r-- | tests/test_aai_geo_region.py | 4 | ||||
-rw-r--r-- | tests/test_aai_line_of_business.py | 4 | ||||
-rw-r--r-- | tests/test_aai_platform.py | 4 | ||||
-rw-r--r-- | tests/test_aai_pnf.py | 2 | ||||
-rw-r--r-- | tests/test_aai_project.py | 4 | ||||
-rw-r--r-- | tests/test_aai_site_resource.py | 35 | ||||
-rwxr-xr-x | tests/test_service.py | 6 | ||||
-rw-r--r-- | tests/test_sp_partner.py | 2 |
18 files changed, 230 insertions, 192 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 84ae83b..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,153 +0,0 @@ ---- - stages: - - linting - - unit_test - - build - - test - - deploy - - image: docker:git - services: - - docker:dind - variables: - DOCKER_DRIVER: overlay - # Variables for pytest.gitlab-ci.yml - PYTHON_VERSIONS: "v3.7 v3.8 v3.9 v3.10" - COVERAGE_FILE: sdk-tests-cov.xml - # Variables for Container-Scanning.gitlab-ci.yml - CI_APPLICATION_REPOSITORY: $CI_REGISTRY_IMAGE #/$CI_COMMIT_REF_SLUG - CI_APPLICATION_TAG: $CI_COMMIT_REF_SLUG #$CI_COMMIT_SHA - # Variable for pylint/pydocstyle/SAST/Code-Quality.gitlab-ci.yml - SRC_PATH: '/src' - DOC_PATH: '/docs' - # Variable for SAST - SAST_EXCLUDED_PATHS: "docs,integration_tests,scripts,tests" - SAST_BANDIT_EXCLUDED_PATHS: "docs,integration_tests,scripts,tests" - - .before_script_docker: &before_script_docker - before_script: - - docker login -u gitlab-ci-token -p "$CI_BUILD_TOKEN" "$CI_REGISTRY" - - build_master: - stage: build - <<: *before_script_docker - script: - - docker build -t "$CI_REGISTRY_IMAGE:latest" . - - docker push "$CI_REGISTRY_IMAGE:latest" - rules: - - if: '$CI_COMMIT_BRANCH == "master"' - - build_testing: - stage: build - <<: *before_script_docker - script: - - docker build -t "$CI_REGISTRY_IMAGE:${CI_COMMIT_REF_SLUG}" . - - docker push "$CI_REGISTRY_IMAGE:${CI_COMMIT_REF_SLUG}" - rules: - - if: '$CI_COMMIT_BRANCH && $CI_COMMIT_BRANCH != "master"' - - build_stable: - stage: build - <<: *before_script_docker - script: - - docker build -t "$CI_REGISTRY_IMAGE:${CI_COMMIT_TAG}" . - - docker push "$CI_REGISTRY_IMAGE:${CI_COMMIT_TAG}" - rules: - - if: '$CI_COMMIT_TAG' - - .integration_tests: &integration_tests - stage: test - variables: - FF_NETWORK_PER_BUILD: 1 # Enable https://docs.gitlab.com/runner/executors/docker.html#network-per-build feature - services: - - name: registry.gitlab.com/orange-opensource/lfn/onap/mock_servers/mock-sdc:develop - alias: sdc.api.fe.simpledemo.onap.org - - name: registry.gitlab.com/orange-opensource/lfn/onap/mock_servers/mock-sdnc:latest - alias: sdnc.api.simpledemo.onap.org - - name: registry.gitlab.com/orange-opensource/lfn/onap/mock_servers/mock-so:latest - alias: so.api.simpledemo.onap.org - - name: registry.gitlab.com/orange-opensource/lfn/onap/mock_servers/mock-aai:latest - alias: aai.api.sparky.simpledemo.onap.org - - name: registry.gitlab.com/orange-opensource/lfn/onap/mock_servers/mock-clamp:develop - alias: clamp.api.simpledemo.onap.org - - name: registry.gitlab.com/orange-opensource/lfn/onap/mock_servers/mock-cds:latest - alias: cds.api.simpledemo.onap.org - - name: registry.gitlab.com/orange-opensource/lfn/onap/mock_servers/mock-msb-k8s:latest - alias: msb.k8s.api.simpledemo.onap.org - - name: registry.gitlab.com/orange-opensource/lfn/onap/mock_servers/mock-dcae/mock-ves:latest - alias: ves.api.simpledemo.onap.org - - name: registry.gitlab.com/orange-opensource/lfn/onap/mock_servers/mock-dmaap:latest - alias: dmaap.api.simpledemo.onap.org - script: - - pip install . - - pip install pytest mock # mock is needed as pytest parse all files before selection - - PYTHONPATH=$PYTHONPATH:integration_tests/ ONAP_PYTHON_SDK_SETTINGS="urls" pytest --verbose -c /dev/null --junitxml=pytest-integration.xml integration_tests - artifacts: - reports: - junit: pytest-*.xml - - integration_tests:3.7: - image: python:3.7 - <<: *integration_tests - - integration_tests:3.8: - image: python:3.8 - <<: *integration_tests - - integration_tests:3.9: - image: python:3.9 - <<: *integration_tests - - integration_tests:3.10: - image: python:3.10 - <<: *integration_tests - - bandit: - image: python:3.10 - stage: linting - script: - - pip install -r requirements.txt - - pip3 install bandit - - bandit -r src/onapsdk - - pages: - stage: deploy - image: - name: python:3.7 - script: - - chmod +x scripts/build_all_branches_in.sh - - scripts/build_all_branches_in.sh - artifacts: - paths: - - public - except: - variables: - - $JOBS_DISABLED - - upload: - stage: deploy - image: - name: python:3.8 - script: - - pip install -r upload-requirements.txt - - python setup.py sdist bdist_wheel - - twine upload --non-interactive dist/* - rules: - - if: '$CI_COMMIT_TAG' - - # https://docs.gitlab.com/ee/update/deprecations.html#dependency-scanning-python-39-and-36-image-deprecation - gemnasium-python-dependency_scanning: - image: - name: registry.gitlab.com/gitlab-org/security-products/analyzers/gemnasium-python:2-python-3.9 - - include: - - remote: 'https://gitlab.com/Orange-OpenSource/lfn/ci_cd/gitlab-ci-templates/raw/master/pylint.gitlab-ci.yml' - - remote: 'https://gitlab.com/Orange-OpenSource/lfn/ci_cd/gitlab-ci-templates/-/raw/master/pytest.gitlab-ci.yml' - - remote: 'https://gitlab.com/Orange-OpenSource/lfn/ci_cd/gitlab-ci-templates/raw/master/pydocstyle.gitlab-ci.yml' - - remote: 'https://gitlab.com/Orange-OpenSource/lfn/ci_cd/gitlab-ci-templates/raw/master/doc8.gitlab-ci.yml' - - remote: 'https://gitlab.com/Orange-OpenSource/lfn/ci_cd/gitlab-ci-templates/raw/master/pyup.gitlab-ci.yml' - - template: License-Scanning.gitlab-ci.yml - - template: Dependency-Scanning.gitlab-ci.yml - - template: Jobs/Code-Quality.gitlab-ci.yml - - template: SAST.gitlab-ci.yml - - template: Container-Scanning.gitlab-ci.yml diff --git a/src/onapsdk/aai/aai_element.py b/src/onapsdk/aai/aai_element.py index 9472165..907028d 100644 --- a/src/onapsdk/aai/aai_element.py +++ b/src/onapsdk/aai/aai_element.py @@ -12,6 +12,7 @@ # 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. +import enum from dataclasses import dataclass, field from typing import Dict, Iterator, List, Optional @@ -58,6 +59,38 @@ class Relationship: return None +@enum.unique +class RelationshipLabelEnum(enum.Enum): + """Class to hold relationship labels.""" + + APPLIES_TO = "org.onap.relationships.inventory.AppliesTo" + BELONGS_TO = "org.onap.relationships.inventory.BelongsTo" + BINDS_TO = "org.onap.relationships.inventory.BindsTo" + CAN_BE_INSTANTIATED_IN = "org.onap.relationships.inventory.CanBeInstantiatedIn" + COMPOSED_OF = "org.onap.relationships.inventory.ComposedOf" + CONTROLLED_BY = "org.onap.relationships.inventory.ControlledBy" + DEPENDS_ON = "org.onap.relationships.inventory.DependsOn" + DESTINATION = "org.onap.relationships.inventory.Destination" + FORWARDS_TO = "org.onap.relationships.inventory.ForwardsTo" + IS_A = "org.onap.relationships.inventory.IsA" + IMPLEMENTS = "org.onap.relationships.inventory.Implements" + LINKS_TO = "org.onap.relationships.inventory.LinksTo" + LOCATED_IN = "org.onap.relationships.inventory.LocatedIn" + MEMBER_OF = "org.onap.relationships.inventory.MemberOf" + NETWORK_APPLIES_TO = "org.onap.relationships.inventory.network.AppliesTo" + NETWORK_BELONGS_TO = "org.onap.relationships.inventory.network.BelongsTo" + NETWORK_MEMBER_OF = "org.onap.relationships.inventory.network.MemberOf" + NETWORK_USES = "org.onap.relationships.inventory.network.Uses" + PART_OF = "org.onap.relationships.inventory.PartOf" + PRIMARY = "org.onap.relationships.inventory.Primary" + SECONDARY = "org.onap.relationships.inventory.Secondary" + SOURCE = "org.onap.relationships.inventory.Source" + SUPPORTS = "org.onap.relationships.inventory.Supports" + TARGET = "org.onap.relationships.inventory.Target" + TARGETS = "org.onap.relationships.inventory.Targets" + USES = "org.onap.relationships.inventory.Uses" + + class AaiElement(OnapService): """Mother Class of all A&AI elements.""" diff --git a/src/onapsdk/aai/cloud_infrastructure/cloud_region.py b/src/onapsdk/aai/cloud_infrastructure/cloud_region.py index d57a025..997f426 100644 --- a/src/onapsdk/aai/cloud_infrastructure/cloud_region.py +++ b/src/onapsdk/aai/cloud_infrastructure/cloud_region.py @@ -20,7 +20,8 @@ from onapsdk.msb.multicloud import Multicloud from onapsdk.utils.jinja import jinja_env from onapsdk.exceptions import ResourceNotFound -from ..aai_element import AaiResource, Relationship +from ..aai_element import AaiResource +from ..mixins.link_to_complex import AaiResourceLinkToComplexMixin from .complex import Complex from .tenant import Tenant @@ -65,7 +66,7 @@ class EsrSystemInfo: # pylint: disable=too-many-instance-attributes openstack_region_id: str = None -class CloudRegion(AaiResource): # pylint: disable=too-many-instance-attributes +class CloudRegion(AaiResource, AaiResourceLinkToComplexMixin): # pylint: disable=too-many-instance-attributes """Cloud region class. Represents A&AI cloud region object. @@ -602,20 +603,3 @@ class CloudRegion(AaiResource): # pylint: disable=too-many-instance-attributes self.url, params={"resource-version": self.resource_version} ) - - def link_to_complex(self, complex_object: Complex) -> None: - """Link cloud region to comples. - - It creates relationhip object and add it into cloud region. - """ - relationship = Relationship( - related_to="complex", - related_link=(f"aai/v13/cloud-infrastructure/complexes/" - f"complex/{complex_object.physical_location_id}"), - relationship_data={ - "relationship-key": "complex.physical-location-id", - "relationship-value": f"{complex_object.physical_location_id}", - }, - relationship_label="org.onap.relationships.inventory.LocatedIn", - ) - self.add_relationship(relationship) diff --git a/src/onapsdk/aai/cloud_infrastructure/complex.py b/src/onapsdk/aai/cloud_infrastructure/complex.py index a854f02..167234d 100644 --- a/src/onapsdk/aai/cloud_infrastructure/complex.py +++ b/src/onapsdk/aai/cloud_infrastructure/complex.py @@ -18,9 +18,10 @@ from urllib.parse import urlencode from onapsdk.utils.jinja import jinja_env from ..aai_element import AaiResource +from ..mixins.link_to_geo_region import AaiResourceLinkToGeoRegionMixin -class Complex(AaiResource): # pylint: disable=too-many-instance-attributes +class Complex(AaiResource, AaiResourceLinkToGeoRegionMixin): # pylint: disable=too-many-instance-attributes """Complex class. Collection of physical locations that can house cloud-regions. diff --git a/src/onapsdk/aai/mixins/__init__.py b/src/onapsdk/aai/mixins/__init__.py new file mode 100644 index 0000000..486ce72 --- /dev/null +++ b/src/onapsdk/aai/mixins/__init__.py @@ -0,0 +1,14 @@ +"""A&AI mixins package.""" +# Copyright 2023 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. diff --git a/src/onapsdk/aai/mixins/link_to_complex.py b/src/onapsdk/aai/mixins/link_to_complex.py new file mode 100644 index 0000000..af43125 --- /dev/null +++ b/src/onapsdk/aai/mixins/link_to_complex.py @@ -0,0 +1,47 @@ +"""A&AI link to complex module.""" +# Copyright 2023 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 typing import TYPE_CHECKING + +from ..aai_element import Relationship, RelationshipLabelEnum + +if TYPE_CHECKING: + from ..cloud_infrastructure.complex import Complex + + +class AaiResourceLinkToComplexMixin: # pylint: disable=too-few-public-methods + """Link aai resource to complex mixin.""" + + def link_to_complex(self, cmplx: "Complex", + relationship_label: RelationshipLabelEnum =\ + RelationshipLabelEnum.LOCATED_IN) -> None: + """Create a relationship with complex resource. + + Args: + cmplx (Complex): Complex object ot create relationship with. + + """ + relationship: Relationship = Relationship( + related_to="complex", + related_link=cmplx.url, + relationship_data=[ + { + "relationship-key": "complex.physical-location-id", + "relationship-value": cmplx.physical_location_id, + } + ], + relationship_label=relationship_label.value, + ) + self.add_relationship(relationship) diff --git a/src/onapsdk/aai/mixins/link_to_geo_region.py b/src/onapsdk/aai/mixins/link_to_geo_region.py new file mode 100644 index 0000000..b78c407 --- /dev/null +++ b/src/onapsdk/aai/mixins/link_to_geo_region.py @@ -0,0 +1,44 @@ +"""A&AI link to geo region mixin module.""" +# Copyright 2023 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 typing import TYPE_CHECKING + +from ..aai_element import Relationship, RelationshipLabelEnum + +if TYPE_CHECKING: + from ..cloud_infrastructure.geo_region import GeoRegion + +class AaiResourceLinkToGeoRegionMixin: # pylint: disable=too-few-public-methods + """Link aai resource to geo region mixin.""" + + def link_to_geo_region(self, geo_region: "GeoRegion") -> None: + """Create a relationship with geo region. + + As few resources create same relationship with geo region + + Args: + geo_region (GeoRegion): Geo region object + """ + relationship: Relationship = Relationship( + related_to="geo-region", + related_link=geo_region.url, + relationship_data=[ + { + "relationship-key": "geo-region.geo-region-id", + "relationship-value": geo_region.geo_region_id, + } + ], + relationship_label=RelationshipLabelEnum.MEMBER_OF.value, + ) + self.add_relationship(relationship) diff --git a/src/onapsdk/aai/network/site_resource.py b/src/onapsdk/aai/network/site_resource.py index 3ac3c20..11a50c1 100644 --- a/src/onapsdk/aai/network/site_resource.py +++ b/src/onapsdk/aai/network/site_resource.py @@ -16,10 +16,12 @@ from typing import Iterable, Optional from onapsdk.utils.jinja import jinja_env -from ..aai_element import AaiResource +from ..aai_element import AaiResource, Relationship, RelationshipLabelEnum +from ..cloud_infrastructure import Complex +from ..mixins.link_to_complex import AaiResourceLinkToComplexMixin -class SiteResource(AaiResource): # pylint: disable=too-many-instance-attributes +class SiteResource(AaiResource, AaiResourceLinkToComplexMixin): # pylint: disable=too-many-instance-attributes """Site resource class.""" def __init__(self, # pylint: disable=too-many-locals @@ -242,3 +244,33 @@ class SiteResource(AaiResource): # pylint: disable=too-many-instance-attributes data_source=data_source, data_source_version=data_source_version)) return cls.get_by_site_resource_id(site_resource_id) + + def link_to_complex(self, cmplx: Complex, relationship_label: RelationshipLabelEnum =\ + RelationshipLabelEnum.USES) -> None: # pylint: disable=useless-super-delegation + """Create a relationship with complex resource. + + Args: + cmplx (Complex): Complex object ot create relationship with. + + """ + return super().link_to_complex(cmplx, relationship_label) + + def link_to_site_resource(self, site_resource: "SiteResource") -> None: + """Create a relationship with site-resource resource. + + Args: + site_resource (SiteResource): Site resource object to create relationship with. + + """ + relationship: Relationship = Relationship( + related_to="site-resource", + related_link=site_resource.url, + relationship_data=[ + { + "relationship-key": "site_resource.site-resource-id", + "relationship-value": site_resource.site_resource_id, + } + ], + relationship_label=RelationshipLabelEnum.SUPPORTS.value, + ) + self.add_relationship(relationship) diff --git a/src/onapsdk/configuration/global_settings.py b/src/onapsdk/configuration/global_settings.py index 45dc249..559213a 100644 --- a/src/onapsdk/configuration/global_settings.py +++ b/src/onapsdk/configuration/global_settings.py @@ -22,7 +22,7 @@ ## API AAI_URL = "https://aai.api.sparky.simpledemo.onap.org:30233" -AAI_API_VERSION = "v23" +AAI_API_VERSION = "v27" AAI_AUTH = "Basic QUFJOkFBSQ==" AAI_BULK_CHUNK = 30 CDS_URL = "http://portal.api.simpledemo.onap.org:30449" diff --git a/tests/test_aai_complex.py b/tests/test_aai_complex.py index 13d2cf5..8368d18 100644 --- a/tests/test_aai_complex.py +++ b/tests/test_aai_complex.py @@ -105,9 +105,10 @@ def test_cloud_region_link_to_complex(mock_add_rel): mock_add_rel.assert_called_once() relationship = mock_add_rel.call_args[0][0] assert relationship.related_to == "complex" - assert relationship.related_link == (f"aai/v13/cloud-infrastructure/complexes/" - f"complex/test_location_id") - assert len(relationship.relationship_data) == 2 + assert relationship.related_link == (f"https://aai.api.sparky.simpledemo.onap.org:30233/aai/" + f"v27/cloud-infrastructure/complexes/complex" + f"/test_location_id") + assert len(relationship.relationship_data) == 1 @mock.patch.object(Complex, "send_message_json") diff --git a/tests/test_aai_geo_region.py b/tests/test_aai_geo_region.py index b33f77a..1b11aa3 100644 --- a/tests/test_aai_geo_region.py +++ b/tests/test_aai_geo_region.py @@ -52,3 +52,7 @@ def test_geo_region_create(mock_get_geo_region_by_id, mock_send_message): GeoRegion.create("123") mock_send_message.assert_called_once() assert mock_get_geo_region_by_id.called_once_with("123") + +def test_geo_region_url(): + geo_region = GeoRegion("test-geo-region") + assert geo_region.url == "https://aai.api.sparky.simpledemo.onap.org:30233/aai/v27/cloud-infrastructure/geo-regions/geo-region/test-geo-region" diff --git a/tests/test_aai_line_of_business.py b/tests/test_aai_line_of_business.py index 1bf4672..bd28c98 100644 --- a/tests/test_aai_line_of_business.py +++ b/tests/test_aai_line_of_business.py @@ -59,7 +59,7 @@ def test_line_of_business_get_by_name(mock_send): LineOfBusiness.get_by_name(name="test-name") mock_send.assert_called_once_with("GET", "Get test-name line of business", - "https://aai.api.sparky.simpledemo.onap.org:30233/aai/v23/business/lines-of-business/line-of-business/test-name") + "https://aai.api.sparky.simpledemo.onap.org:30233/aai/v27/business/lines-of-business/line-of-business/test-name") @mock.patch("onapsdk.aai.business.line_of_business.LineOfBusiness.send_message") @@ -68,7 +68,7 @@ def test_line_of_business_create(_, mock_send): LineOfBusiness.create(name="test-name") mock_send.assert_called_once_with("PUT", "Declare A&AI line of business", - "https://aai.api.sparky.simpledemo.onap.org:30233/aai/v23/business/lines-of-business/line-of-business/test-name", + "https://aai.api.sparky.simpledemo.onap.org:30233/aai/v27/business/lines-of-business/line-of-business/test-name", data='{\n "line-of-business-name": "test-name"\n}') diff --git a/tests/test_aai_platform.py b/tests/test_aai_platform.py index ed20e50..fbe2753 100644 --- a/tests/test_aai_platform.py +++ b/tests/test_aai_platform.py @@ -59,7 +59,7 @@ def test_platform_get_by_name(mock_send): Platform.get_by_name(name="test-name") mock_send.assert_called_once_with("GET", "Get test-name platform", - "https://aai.api.sparky.simpledemo.onap.org:30233/aai/v23/business/platforms/platform/test-name") + "https://aai.api.sparky.simpledemo.onap.org:30233/aai/v27/business/platforms/platform/test-name") @mock.patch("onapsdk.aai.business.platform.Platform.send_message") @@ -68,7 +68,7 @@ def test_platform_create(_, mock_send): Platform.create(name="test-name") mock_send.assert_called_once_with("PUT", "Declare A&AI platform", - "https://aai.api.sparky.simpledemo.onap.org:30233/aai/v23/business/platforms/platform/test-name", + "https://aai.api.sparky.simpledemo.onap.org:30233/aai/v27/business/platforms/platform/test-name", data='{\n "platform-name": "test-name"\n}') diff --git a/tests/test_aai_pnf.py b/tests/test_aai_pnf.py index 32e9ea7..eb2e851 100644 --- a/tests/test_aai_pnf.py +++ b/tests/test_aai_pnf.py @@ -42,7 +42,7 @@ PNF_INSTANCE = { { "related-to":"service-instance", "relationship-label":"org.onap.relationships.inventory.ComposedOf", - "related-link":"/aai/v21/business/customers/customer/test/service-subscriptions/service-subscription/test/service-instances/service-instance/4c3ab996-afdb-4956-9c4d-038b4eed3db1", + "related-link":"/aai/v27/business/customers/customer/test/service-subscriptions/service-subscription/test/service-instances/service-instance/4c3ab996-afdb-4956-9c4d-038b4eed3db1", "relationship-data":[ { "relationship-key":"customer.global-customer-id", diff --git a/tests/test_aai_project.py b/tests/test_aai_project.py index 4186772..716bac1 100644 --- a/tests/test_aai_project.py +++ b/tests/test_aai_project.py @@ -59,7 +59,7 @@ def test_project_get_by_name(mock_send): Project.get_by_name(name="test-name") mock_send.assert_called_once_with("GET", "Get test-name project", - "https://aai.api.sparky.simpledemo.onap.org:30233/aai/v23/business/projects/project/test-name") + "https://aai.api.sparky.simpledemo.onap.org:30233/aai/v27/business/projects/project/test-name") @mock.patch("onapsdk.aai.business.project.Project.send_message") @@ -68,7 +68,7 @@ def test_project_create(_, mock_send): Project.create(name="test-name") mock_send.assert_called_once_with("PUT", "Declare A&AI project", - "https://aai.api.sparky.simpledemo.onap.org:30233/aai/v23/business/projects/project/test-name", + "https://aai.api.sparky.simpledemo.onap.org:30233/aai/v27/business/projects/project/test-name", data='{\n "project-name": "test-name"\n}') diff --git a/tests/test_aai_site_resource.py b/tests/test_aai_site_resource.py index 68dd556..a0d4a12 100644 --- a/tests/test_aai_site_resource.py +++ b/tests/test_aai_site_resource.py @@ -11,7 +11,7 @@ # 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 unittest.mock import patch +from unittest.mock import patch, MagicMock from onapsdk.aai.network.site_resource import SiteResource @@ -55,3 +55,36 @@ def test_site_resource_create(mock_get_by_site_resource_id, mock_send_message): SiteResource.create("123") mock_send_message.assert_called_once() assert mock_get_by_site_resource_id.called_once_with("123") + +@patch("onapsdk.aai.network.site_resource.SiteResource.add_relationship") +def test_site_resource_link_to_complex(mock_add_relationship): + cmplx = MagicMock(physical_location_id="test-complex-physical-location-id", + url="test-complex-url") + site_resource = SiteResource("test-site-resource") + site_resource.link_to_complex(cmplx) + mock_add_relationship.assert_called_once() + relationship = mock_add_relationship.call_args[0][0] + assert relationship.related_to == "complex" + assert relationship.related_link == "test-complex-url" + assert relationship.relationship_label == "org.onap.relationships.inventory.Uses" + assert relationship.relationship_data == [{ + "relationship-key": "complex.physical-location-id", + "relationship-value": "test-complex-physical-location-id", + }] + + +@patch("onapsdk.aai.network.site_resource.SiteResource.add_relationship") +def test_site_resource_link_to_site_resource(mock_add_relationship): + site_resource_rel = MagicMock(site_resource_id="test-site-resource-id", + url="test-site-resource-url") + site_resource = SiteResource("test-site-resource") + site_resource.link_to_site_resource(site_resource_rel) + mock_add_relationship.assert_called_once() + relationship = mock_add_relationship.call_args[0][0] + assert relationship.related_to == "site-resource" + assert relationship.related_link == "test-site-resource-url" + assert relationship.relationship_label == "org.onap.relationships.inventory.Supports" + assert relationship.relationship_data == [{ + "relationship-key": "site_resource.site-resource-id", + "relationship-value": "test-site-resource-id", + }] diff --git a/tests/test_service.py b/tests/test_service.py index 2ba61db..3a11449 100755 --- a/tests/test_service.py +++ b/tests/test_service.py @@ -535,7 +535,6 @@ def test_get_tosca_bad_csart(requests_mock): svc.get_tosca(tempdir) assert not path.exists('/tmp/tosca_files') - def test_get_tosca_result(requests_mock): if path.exists('/tmp/tosca_files'): shutil.rmtree('/tmp/tosca_files') @@ -546,10 +545,9 @@ def test_get_tosca_result(requests_mock): content=file_content) svc = Service() svc.identifier = "12" - svc.get_tosca('directory') + svc.get_tosca('new/directory') assert not path.exists('/tmp/tosca_files') - def test_get_tosca_result_no_service_in_csar(requests_mock): if path.exists('/tmp/tosca_files'): shutil.rmtree('/tmp/tosca_files') @@ -561,7 +559,7 @@ def test_get_tosca_result_no_service_in_csar(requests_mock): svc = Service() svc.identifier = "12" with pytest.raises(ValidationError): - svc.get_tosca('directory') + svc.get_tosca('new/directory') @mock.patch.object(Service, 'send_message_json') def test_distributed_api_error(mock_send): diff --git a/tests/test_sp_partner.py b/tests/test_sp_partner.py index 73a4839..7005c02 100644 --- a/tests/test_sp_partner.py +++ b/tests/test_sp_partner.py @@ -80,5 +80,5 @@ def test_sp_partner_create(_, mock_send): ) mock_send.assert_called_once_with("PUT", "Declare A&AI sp partner", - "https://aai.api.sparky.simpledemo.onap.org:30233/aai/v23/business/sp-partners/sp-partner/123", + "https://aai.api.sparky.simpledemo.onap.org:30233/aai/v27/business/sp-partners/sp-partner/123", data='{\n "sp-partner-id": "123"\n \n \n \n \n \n \n}') |