diff --git a/test/services/conftest.py b/test/services/conftest.py index 9aee570a13f12985576708e9bac7740e5670b103..9557b1c5b091e51150ab78cf4b58c62f8018df8e 100644 --- a/test/services/conftest.py +++ b/test/services/conftest.py @@ -1,3 +1,8 @@ +from typing import Any + +from gso.services.kentik_client import NewKentikDevice + + class MockedNetboxClient: class BaseMockObject: def __init__(self, **kwargs): @@ -57,3 +62,58 @@ class MockedSharePointClient: @staticmethod def add_list_item(list_name: str, fields: dict[str, str]) -> str: return f"http://{list_name}/{fields.popitem()}" + + +class MockedKentikClient: + class BaseMockObject: + def __init__(self, **kwargs): + for key, value in kwargs.items(): + setattr(self, key, value) + + @staticmethod + def get_devices() -> list[dict[str, Any]]: + return [{"id": 0, "device_name": "device-1.internal"}, {"id": 1, "device_name": "device-2.internal"}] + + @staticmethod + def get_device(device_id: str) -> dict[str, Any]: + return {"id": device_id, "device_name": "device-1.internal"} + + @staticmethod + def get_device_by_name(fqdn: str) -> dict[str, Any]: + return {"id": 0, "device_name": fqdn} + + @staticmethod + def get_sites() -> list[dict[str, Any]]: + return [{"id": 0, "site_name": "AMS"}, {"id": 1, "site_name": "BRU"}, {"id": 2, "site_name": "LUX"}] + + @staticmethod + def get_site_by_name(site_name: str) -> dict[str, Any]: + return {"id": 0, "site_name": site_name} + + @staticmethod + def get_plans() -> list[dict[str, Any]]: + return [{"id": 0, "plan_name": "kentik-plan-1"}, {"id": 1, "plan_name": "kentik-plan-2"}] + + @staticmethod + def get_plan(plan_id: int) -> dict[str, Any]: + return {"id": plan_id, "plan_name": "kentik-mocked-plan"} + + @staticmethod + def get_plan_by_name(plan_name: str) -> dict[str, Any]: + return {"id": 0, "plan_name": plan_name} + + @staticmethod + def create_device(device: NewKentikDevice) -> dict[str, Any]: + return device.model_dump() + + @staticmethod + def update_device(device_id: int, updated_device: dict[str, Any]) -> dict[str, Any]: + return {"id": device_id, **updated_device} + + @staticmethod + def remove_device(device_id: int, *, archive: bool) -> None: + pass + + @staticmethod + def remove_device_by_fqdn(fqdn: str, *, archive: bool) -> None: + pass diff --git a/test/workflows/router/test_promote_p_to_pe.py b/test/workflows/router/test_promote_p_to_pe.py index 90493d7e66ab4fedc178d524db352ce93c96f1b4..3bd7fdca1a65e0ad7bd0e1df59883cd020e9aca0 100644 --- a/test/workflows/router/test_promote_p_to_pe.py +++ b/test/workflows/router/test_promote_p_to_pe.py @@ -6,6 +6,7 @@ from pydantic_forms.exceptions import FormValidationError from gso.products.product_blocks.router import RouterRole from test import USER_CONFIRM_EMPTY_FORM +from test.services.conftest import MockedKentikClient from test.workflows import ( assert_complete, assert_lso_interaction_success, @@ -17,19 +18,16 @@ from test.workflows import ( @pytest.mark.workflow() @patch("gso.workflows.router.promote_p_to_pe.lso_client.execute_playbook") -@patch("gso.workflows.router.promote_p_to_pe.KentikClient.create_device") -@patch("gso.workflows.router.promote_p_to_pe.KentikClient.get_site_by_name") +@patch("gso.workflows.router.promote_p_to_pe.KentikClient") def test_promote_p_to_pe_success( - mock_kentik_create_device, - mock_kentik_get_site_by_name, + mock_kentik_client, mock_execute_playbook, nokia_router_subscription_factory, data_config_filename, faker, ): """Test the successful promotion of a Nokia P router to a PE router.""" - mock_kentik_create_device.return_value = {"id": faker.pyint()} - mock_kentik_get_site_by_name.return_value = {"id": faker.pyint()} + mock_kentik_client.return_value = MockedKentikClient router_id = nokia_router_subscription_factory(router_role=RouterRole.P, status=SubscriptionLifecycle.ACTIVE) input_data = [{"subscription_id": router_id}, {"tt_number": faker.tt_number()}] result, process_stat, step_log = run_workflow("promote_p_to_pe", input_data) @@ -41,7 +39,6 @@ def test_promote_p_to_pe_success( state = extract_state(result) assert_complete(result) assert mock_execute_playbook.call_count == 22 - assert mock_kentik_create_device.call_count == 1 assert state["subscription"]["router"]["router_role"] == RouterRole.PE