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 ...@@ -3,7 +3,7 @@ from unittest.mock import patch
import pytest import pytest
from gso.products import Iptrunk 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 @pytest.mark.workflow
......
...@@ -9,13 +9,11 @@ from gso.products.product_types.router import Router ...@@ -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.crm import customer_selector, get_customer_by_name
from gso.services.subscriptions import get_product_id_by_name from gso.services.subscriptions import get_product_id_by_name
from test.workflows import ( from test.workflows import (
assert_aborted,
assert_complete, assert_complete,
assert_suspended, assert_pp_interaction_failure,
assert_pp_interaction_success,
extract_state, extract_state,
resume_workflow,
run_workflow, run_workflow,
user_accept_and_assert_suspended,
) )
...@@ -55,6 +53,7 @@ def test_create_router_success( ...@@ -55,6 +53,7 @@ def test_create_router_success(
mock_provision_router, mock_provision_router,
router_creation_input_form_data, router_creation_input_form_data,
faker, faker,
data_config_filename,
): ):
# Set up mock return values # Set up mock return values
product_id = get_product_id_by_name(ProductType.ROUTER) product_id = get_product_id_by_name(ProductType.ROUTER)
...@@ -74,7 +73,6 @@ def test_create_router_success( ...@@ -74,7 +73,6 @@ def test_create_router_success(
# Run workflow # Run workflow
initial_router_data = [{"product": product_id}, router_creation_input_form_data] initial_router_data = [{"product": product_id}, router_creation_input_form_data]
result, process_stat, step_log = run_workflow("create_router", initial_router_data) result, process_stat, step_log = run_workflow("create_router", initial_router_data)
assert_suspended(result)
state = extract_state(result) state = extract_state(result)
subscription_id = state["subscription_id"] subscription_id = state["subscription_id"]
...@@ -101,20 +99,8 @@ def test_create_router_success( ...@@ -101,20 +99,8 @@ def test_create_router_success(
cidr=str(mock_v4_net), cidr=str(mock_v4_net),
) )
lso_return = { for _ in range(2):
"pp_run_results": { result, step_log = assert_pp_interaction_success(result, process_stat, step_log)
"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, [{}, {}])
assert_complete(result) assert_complete(result)
...@@ -193,36 +179,19 @@ def test_create_router_lso_failure( ...@@ -193,36 +179,19 @@ def test_create_router_lso_failure(
product_id = get_product_id_by_name(ProductType.ROUTER) product_id = get_product_id_by_name(ProductType.ROUTER)
initial_router_data = [{"product": product_id}, router_creation_input_form_data] initial_router_data = [{"product": product_id}, router_creation_input_form_data]
result, process_stat, step_log = run_workflow("create_router", initial_router_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 = assert_pp_interaction_success(result, process_stat, step_log)
result, step_log = resume_workflow(process_stat, step_log, [{}, {}])
assert_aborted(result)
state = extract_state(result) state = extract_state(result)
subscription_id = state["subscription_id"] subscription_id = state["subscription_id"]
subscription = Router.from_subscription(subscription_id) subscription = Router.from_subscription(subscription_id)
assert_pp_interaction_failure(result, process_stat, step_log)
assert "provisioning" == subscription.status assert "provisioning" == subscription.status
assert subscription.description == f"Router {mock_fqdn}" 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_netbox_create_device.call_count == 0
assert mock_find_host_by_fqdn.call_count == 0 assert mock_find_host_by_fqdn.call_count == 0
assert mock_find_network_by_cidr.call_count == 0 assert mock_find_network_by_cidr.call_count == 0
...@@ -22,6 +22,7 @@ def test_terminate_router_success( ...@@ -22,6 +22,7 @@ def test_terminate_router_success(
router_termination_input_form_data, router_termination_input_form_data,
router_subscription_factory, router_subscription_factory,
faker, faker,
data_config_filename,
): ):
# Set up active subscription in database # Set up active subscription in database
product_id = router_subscription_factory() 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