From 58a1c13883f815197c76487b382eddf2eed67207 Mon Sep 17 00:00:00 2001 From: Kiran Date: Tue, 17 Oct 2023 19:32:38 +0530 Subject: changes for update functionality for entities.. Issue-ID: TEST-412 Change-Id: I598c289f87fff80323ef979600df45d4fa4591dd Signed-off-by: Kiran --- tests/test_aai_cloud_region.py | 26 ++++++++++++++++++++++++++ tests/test_aai_complex.py | 14 ++++++++++++++ tests/test_aai_customer.py | 17 +++++++++++++++++ tests/test_aai_owning_entity.py | 16 ++++++++++++++++ 4 files changed, 73 insertions(+) (limited to 'tests') diff --git a/tests/test_aai_cloud_region.py b/tests/test_aai_cloud_region.py index a821090..13ba539 100644 --- a/tests/test_aai_cloud_region.py +++ b/tests/test_aai_cloud_region.py @@ -69,3 +69,29 @@ def test_cloud_region_get_tenants_by_name(mock_tenants): def test_cloud_region_count(mock_send_message_json): mock_send_message_json.return_value = COUNT assert CloudRegion.count() == 2 + +@mock.patch.object(CloudRegion, "send_message") +def test_cloud_region_delete(mock_send_message): + cloud_region = CloudRegion("test_cloud_owner", "test_cloud_region_id", False, False) + cloud_region.delete() + mock_send_message.assert_called_once_with( + "DELETE", + f"Delete cloud region {cloud_region.cloud_region_id}", + f"{cloud_region.url}", + params={'resource-version': cloud_region.resource_version} + ) + + +@mock.patch.object(CloudRegion, "send_message") +def test_cloud_region_update(mock_send_message): + cloud_region = CloudRegion("test_cloud_owner", "test_cloud_region_id", False, False) + cloud_region.update("test_cloud_owner", "test_cloud_region_id", False, False) + mock_send_message.assert_called_once() + assert cloud_region.cloud_owner == "test_cloud_owner" + assert cloud_region.cloud_region_id == "test_cloud_region_id" + assert cloud_region.url == (f"{CloudRegion.base_url}{CloudRegion.api_version}/cloud-infrastructure/cloud-regions/" + f"cloud-region/test_cloud_owner/test_cloud_region_id") + method, _, url = mock_send_message.call_args[0] + assert method == "PATCH" + assert url == (f"{CloudRegion.base_url}{CloudRegion.api_version}/cloud-infrastructure/cloud-regions/" + "cloud-region/test_cloud_owner/test_cloud_region_id") diff --git a/tests/test_aai_complex.py b/tests/test_aai_complex.py index 8368d18..9b36426 100644 --- a/tests/test_aai_complex.py +++ b/tests/test_aai_complex.py @@ -77,6 +77,20 @@ def test_complex(mock_send_message): assert url == (f"{Complex.base_url}{Complex.api_version}/cloud-infrastructure/" "complexes/complex/test_location_id") +@mock.patch.object(Complex, "send_message") +def test_complex_update(mock_send_message): + cmplx1 = Complex.update(name="test_complex_name", + physical_location_id="test_location_id") + mock_send_message.assert_called_once() + assert cmplx1.name == "test_complex_name" + assert cmplx1.physical_location_id == "test_location_id" + assert cmplx1.url == (f"{Complex.base_url}{Complex.api_version}/cloud-infrastructure/" + "complexes/complex/test_location_id") + method, _, url = mock_send_message.call_args[0] + assert method == "PATCH" + assert url == (f"{Complex.base_url}{Complex.api_version}/cloud-infrastructure/" + "complexes/complex/test_location_id") + @mock.patch.object(Complex, "send_message_json") def test_complex_get_all(mock_send_message_json): diff --git a/tests/test_aai_customer.py b/tests/test_aai_customer.py index 260520c..1597ac2 100644 --- a/tests/test_aai_customer.py +++ b/tests/test_aai_customer.py @@ -392,6 +392,23 @@ def test_customer_delete(mock_send): customer.url ) +@mock.patch.object(Customer, "send_message") +@mock.patch.object(Customer, "send_message_json") +def test_customer_update(mock_send_json, mock_send): + """Test Customer's update method.""" + mock_send_json.return_value = SIMPLE_CUSTOMER_2 + customer = Customer.update("generic", "generic", "INFRA") + assert customer.global_customer_id == "generic" + assert customer.subscriber_name == "generic" + assert customer.subscriber_type == "INFRA" + assert customer.resource_version is not None + + customer = Customer.create("generic", "generic", "INFRA", service_subscriptions=["test-service-type"]) + assert customer.global_customer_id == "generic" + assert customer.subscriber_name == "generic" + assert customer.subscriber_type == "INFRA" + assert customer.resource_version is not None + @mock.patch.object(Customer, "send_message") def test_delete_subscribed_service(mock_send): diff --git a/tests/test_aai_owning_entity.py b/tests/test_aai_owning_entity.py index dce8986..49658b1 100644 --- a/tests/test_aai_owning_entity.py +++ b/tests/test_aai_owning_entity.py @@ -96,3 +96,19 @@ def test_owning_entity_delete(mock_send_message): "Delete owning entity", f"{owning_entity.url}?resource-version={owning_entity.resource_version}" ) + +@mock.patch.object(OwningEntity, "send_message") +@mock.patch.object(OwningEntity, "send_message_json") +def test_owning_entity_update(mock_send_json, mock_send): + mock_send_json.return_value = OWNING_ENTITY + OwningEntity.update( + name="OE-generic", + owning_entity_id="OE-generic" + ) + + owning_entity = OwningEntity.update( + name="OE-generic", + owning_entity_id="OE-generic" + ) + assert owning_entity.owning_entity_id == "OE-generic" + assert owning_entity.name == "OE-generic" -- cgit 1.2.3-korg