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

update router workflow unit tests

parent 29d62b1f
No related branches found
No related tags found
1 merge request!96Make use of new callback step for external provisioning
Pipeline #84352 passed
......@@ -3,7 +3,7 @@ from unittest.mock import patch
import pytest
from gso.products import Iptrunk
from test.workflows import assert_complete, assert_pp_interaction_success, assert_suspended, extract_state, run_workflow
from test.workflows import assert_complete, assert_pp_interaction_success, extract_state, run_workflow
@pytest.mark.workflow
......
......@@ -9,13 +9,11 @@ from gso.products.product_types.router import Router
from gso.services.crm import customer_selector, get_customer_by_name
from gso.services.subscriptions import get_product_id_by_name
from test.workflows import (
assert_aborted,
assert_complete,
assert_suspended,
assert_pp_interaction_failure,
assert_pp_interaction_success,
extract_state,
resume_workflow,
run_workflow,
user_accept_and_assert_suspended,
)
......@@ -55,6 +53,7 @@ def test_create_router_success(
mock_provision_router,
router_creation_input_form_data,
faker,
data_config_filename,
):
# Set up mock return values
product_id = get_product_id_by_name(ProductType.ROUTER)
......@@ -74,7 +73,6 @@ def test_create_router_success(
# Run workflow
initial_router_data = [{"product": product_id}, router_creation_input_form_data]
result, process_stat, step_log = run_workflow("create_router", initial_router_data)
assert_suspended(result)
state = extract_state(result)
subscription_id = state["subscription_id"]
......@@ -101,20 +99,8 @@ def test_create_router_success(
cidr=str(mock_v4_net),
)
lso_return = {
"pp_run_results": {
"status": "ok",
"job_id": faker.uuid4(),
"output": "parsed_output",
"return_code": 0,
},
"confirm": "ACCEPTED",
}
result, step_log = user_accept_and_assert_suspended(process_stat, step_log, lso_return)
result, step_log = user_accept_and_assert_suspended(process_stat, step_log, [{}, {}])
result, step_log = user_accept_and_assert_suspended(process_stat, step_log, lso_return)
result, step_log = resume_workflow(process_stat, step_log, [{}, {}])
for _ in range(2):
result, step_log = assert_pp_interaction_success(result, process_stat, step_log)
assert_complete(result)
......@@ -193,36 +179,19 @@ def test_create_router_lso_failure(
product_id = get_product_id_by_name(ProductType.ROUTER)
initial_router_data = [{"product": product_id}, router_creation_input_form_data]
result, process_stat, step_log = run_workflow("create_router", initial_router_data)
assert_suspended(result)
lso_return = {
"pp_run_results": {
"status": "failure",
"job_id": faker.uuid4(),
"output": "parsed_output",
"return_code": 1,
},
"confirm": "ACCEPTED",
}
attempts = 3
for _ in range(attempts - 1):
result, step_log = user_accept_and_assert_suspended(process_stat, step_log, lso_return)
result, step_log = user_accept_and_assert_suspended(process_stat, step_log, [{}, {}])
result, step_log = user_accept_and_assert_suspended(process_stat, step_log, lso_return)
result, step_log = resume_workflow(process_stat, step_log, [{}, {}])
assert_aborted(result)
result, step_log = assert_pp_interaction_success(result, process_stat, step_log)
state = extract_state(result)
subscription_id = state["subscription_id"]
subscription = Router.from_subscription(subscription_id)
assert_pp_interaction_failure(result, process_stat, step_log)
assert "provisioning" == subscription.status
assert subscription.description == f"Router {mock_fqdn}"
assert mock_provision_router.call_count == attempts
assert mock_provision_router.call_count == 2
assert mock_netbox_create_device.call_count == 0
assert mock_find_host_by_fqdn.call_count == 0
assert mock_find_network_by_cidr.call_count == 0
......@@ -22,6 +22,7 @@ def test_terminate_router_success(
router_termination_input_form_data,
router_subscription_factory,
faker,
data_config_filename,
):
# Set up active subscription in database
product_id = router_subscription_factory()
......
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