diff options
author | Michal Jagiello <michal.jagiello@t-mobile.pl> | 2022-10-17 12:46:49 +0000 |
---|---|---|
committer | Michal Jagiello <michal.jagiello@t-mobile.pl> | 2022-10-17 14:05:09 +0000 |
commit | f2adf542e878c96895210f97ebf1ebb763b2f465 (patch) | |
tree | 91fc0faeb3436e723d07aed1f38ce59a6e7cc7c5 /tests/test_aai_owning_entity.py | |
parent | 49071a0d0425ef67fa552dbf14c81e5a11cc49e7 (diff) |
Release ONAP SDKv10.2
Issue-ID: INT-2150
Signed-off-by: Michal Jagiello <michal.jagiello@t-mobile.pl>
Change-Id: I650047c599a5aae6de7c6b42d38e34aea88578e2
Diffstat (limited to 'tests/test_aai_owning_entity.py')
-rw-r--r-- | tests/test_aai_owning_entity.py | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/tests/test_aai_owning_entity.py b/tests/test_aai_owning_entity.py new file mode 100644 index 0000000..0f16044 --- /dev/null +++ b/tests/test_aai_owning_entity.py @@ -0,0 +1,87 @@ +# 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 unittest import mock + +import pytest + +from onapsdk.aai.business import OwningEntity +from onapsdk.exceptions import ResourceNotFound + + +OWNING_ENTITIES = { + "owning-entity":[ + { + "owning-entity-id":"ff6c945f-89ab-4f14-bafd-0cdd6eac791a", + "owning-entity-name":"OE-Generic", + "resource-version":"1588244348931", + }, + { + "owning-entity-id":"OE-generic", + "owning-entity-name":"OE-generic", + "resource-version":"1587388597761" + }, + { + "owning-entity-id":"b3dcdbb0-edae-4384-b91e-2f114472520c" + ,"owning-entity-name":"test", + "resource-version":"1588145971158" + } + ] +} + + +OWNING_ENTITY = { + "owning-entity-id":"OE-generic", + "owning-entity-name":"OE-generic", + "resource-version":"1587388597761" +} + + +@mock.patch.object(OwningEntity, "send_message_json") +def test_owning_entity_get_all(mock_send): + mock_send.return_value = OWNING_ENTITIES + owning_entities = list(OwningEntity.get_all()) + assert len(owning_entities) == 3 + owning_entity = owning_entities[0] + assert owning_entity.owning_entity_id == "ff6c945f-89ab-4f14-bafd-0cdd6eac791a" + assert owning_entity.name == "OE-Generic" + assert owning_entity.url == (f"{owning_entity.base_url}{owning_entity.api_version}/" + "business/owning-entities/owning-entity/" + f"{owning_entity.owning_entity_id}") + + +@mock.patch.object(OwningEntity, "send_message_json") +def test_owning_entity_get_by_name(mock_send): + mock_send.return_value = OWNING_ENTITIES + with pytest.raises(ResourceNotFound) as exc: + OwningEntity.get_by_owning_entity_name("invalid name") + assert exc.type == ResourceNotFound + owning_entity = OwningEntity.get_by_owning_entity_name("OE-Generic") + assert owning_entity.owning_entity_id == "ff6c945f-89ab-4f14-bafd-0cdd6eac791a" + assert owning_entity.name == "OE-Generic" + + +@mock.patch.object(OwningEntity, "send_message") +@mock.patch.object(OwningEntity, "send_message_json") +def test_owning_entity_create(mock_send_json, mock_send): + mock_send_json.return_value = OWNING_ENTITY + OwningEntity.create( + name="OE-generic", + ) + + owning_entity = OwningEntity.create( + name="OE-generic", + owning_entity_id="OE-generic" + ) + assert owning_entity.owning_entity_id == "OE-generic" + assert owning_entity.name == "OE-generic" |