Skip to content
Snippets Groups Projects
Commit 6efd4f85 authored by Karel van Klink's avatar Karel van Klink :smiley_cat:
Browse files

Add MockedKentikClient for unit testing

parent 20ca3ebd
No related branches found
Tags 2.26
1 merge request!257Feature/add kentik workflow
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
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment