Skip to content
Snippets Groups Projects
Verified Commit 612dc95a authored by Karel van Klink's avatar Karel van Klink :smiley_cat:
Browse files

Update unit tests for router and trunk creation to include sharepoint list items

parent 3674632d
No related branches found
No related tags found
No related merge requests found
Pipeline #86732 passed
......@@ -495,7 +495,8 @@ def netbox_allocate_side_b_interfaces(subscription: IptrunkInactive) -> None:
def create_new_sharepoint_checklist(subscription: IptrunkProvisioning, tt_number: str) -> State:
"""Create a new checklist item in SharePoint for approving this IPtrunk."""
new_list_item_url = SharePointClient().add_list_item(
"ip_trunk", {"Title": subscription.iptrunk.iptrunk_description, "TT_NUMBER": tt_number}
"ip_trunk",
{"Title": subscription.iptrunk.iptrunk_description or subscription.description, "TT_NUMBER": tt_number},
)
return {"checklist_url": new_list_item_url}
......
......@@ -46,3 +46,14 @@ class MockedNetboxClient:
@staticmethod
def delete_interface():
return None
class MockedSharePointClient:
class BaseMockObject:
def __init__(self, **kwargs):
for key, value in kwargs.items():
setattr(self, key, value)
@staticmethod
def add_list_item(list_name: str, fields: dict[str, str]) -> str:
return f"http://{list_name}/{fields.popitem()}"
......@@ -8,7 +8,7 @@ from gso.products.product_blocks.iptrunk import IptrunkType, PhysicalPortCapacit
from gso.services.subscriptions import get_product_id_by_name
from gso.utils.shared_enums import Vendor
from test import USER_CONFIRM_EMPTY_FORM
from test.services.conftest import MockedNetboxClient
from test.services.conftest import MockedNetboxClient, MockedSharePointClient
from test.workflows import (
assert_complete,
assert_lso_interaction_failure,
......@@ -102,7 +102,9 @@ def input_form_wizard_data(request, juniper_router_subscription_factory, nokia_r
@patch("gso.workflows.iptrunk.create_iptrunk.infoblox.allocate_v6_network")
@patch("gso.workflows.iptrunk.create_iptrunk.infoblox.allocate_v4_network")
@patch("gso.workflows.iptrunk.create_iptrunk.infoblox.create_host_by_ip")
@patch("gso.workflows.iptrunk.create_iptrunk.SharePointClient")
def test_successful_iptrunk_creation_with_standard_lso_result(
mock_sharepoint_client,
mock_create_host,
mock_allocate_v4_network,
mock_allocate_v6_network,
......@@ -117,6 +119,8 @@ def test_successful_iptrunk_creation_with_standard_lso_result(
mock_create_host.return_value = None
mock_allocate_v4_network.return_value = faker.ipv4_network(max_subnet=31)
mock_allocate_v6_network.return_value = faker.ipv6_network(max_subnet=126)
mock_sharepoint_client.return_value = MockedSharePointClient
product_id = get_product_id_by_name(ProductName.IP_TRUNK)
initial_site_data = [{"product": product_id}, *input_form_wizard_data]
result, process_stat, step_log = run_workflow("create_iptrunk", initial_site_data)
......@@ -179,7 +183,9 @@ def test_iptrunk_creation_fails_when_lso_return_code_is_one(
@patch("gso.workflows.iptrunk.create_iptrunk.infoblox.allocate_v6_network")
@patch("gso.workflows.iptrunk.create_iptrunk.infoblox.allocate_v4_network")
@patch("gso.workflows.iptrunk.create_iptrunk.infoblox.create_host_by_ip")
@patch("gso.workflows.iptrunk.create_iptrunk.SharePointClient")
def test_successful_iptrunk_creation_with_juniper_interface_names(
mock_sharepoint_client,
mock_create_host,
mock_allocate_v4_network,
mock_allocate_v6_network,
......@@ -194,6 +200,7 @@ def test_successful_iptrunk_creation_with_juniper_interface_names(
mock_create_host.return_value = None
mock_allocate_v4_network.return_value = faker.ipv4_network(max_subnet=31)
mock_allocate_v6_network.return_value = faker.ipv6_network(max_subnet=126)
mock_sharepoint_client.return_value = MockedSharePointClient
product_id = get_product_id_by_name(ProductName.IP_TRUNK)
initial_site_data = [{"product": product_id}, *input_form_wizard_data]
result, process_stat, step_log = run_workflow("create_iptrunk", initial_site_data)
......@@ -205,3 +212,4 @@ def test_successful_iptrunk_creation_with_juniper_interface_names(
result, step_log = resume_workflow(process_stat, step_log, input_data=USER_CONFIRM_EMPTY_FORM)
assert_complete(result)
assert mock_execute_playbook.call_count == 6
......@@ -9,6 +9,7 @@ from gso.products.product_types.router import Router
from gso.services.subscriptions import get_product_id_by_name
from gso.utils.shared_enums import Vendor
from test import USER_CONFIRM_EMPTY_FORM
from test.services.conftest import MockedSharePointClient
from test.workflows import (
assert_complete,
assert_lso_interaction_failure,
......@@ -63,6 +64,7 @@ def test_create_nokia_router_success(
)
mock_hostname_available.return_value = True
mock_allocate_host.return_value = str(mock_v4), str(mock_v6)
mock_sharepoint_client.return_value = MockedSharePointClient
# Run workflow
initial_router_data = [{"product": product_id}, router_creation_input_form_data]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment