From 45690660244cd0e4ed9265786222ca3dba8764c0 Mon Sep 17 00:00:00 2001 From: Philip Kalinsky Date: Wed, 12 Feb 2020 09:31:52 -0500 Subject: [PATCH] state machine last CREATED state transition to COMPLETED --- atst/models/mixins/state_machines.py | 12 ++++++++++++ atst/models/portfolio_state_machine.py | 9 +++++++++ tests/domain/test_portfolio_state_machine.py | 3 ++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/atst/models/mixins/state_machines.py b/atst/models/mixins/state_machines.py index a01771b5..41af66ba 100644 --- a/atst/models/mixins/state_machines.py +++ b/atst/models/mixins/state_machines.py @@ -58,6 +58,18 @@ def _build_transitions(csp_stages): transitions = [] states = [] for stage_i, csp_stage in enumerate(csp_stages): + # the last CREATED stage has a transition to COMPLETED + if stage_i == len(csp_stages) - 1: + transitions.append( + dict( + trigger="complete", + source=compose_state( + list(csp_stages)[stage_i], StageStates.CREATED + ), + dest=FSMStates.COMPLETED, + ) + ) + for state in StageStates: states.append( dict( diff --git a/atst/models/portfolio_state_machine.py b/atst/models/portfolio_state_machine.py index 24a3fefc..595fb8fe 100644 --- a/atst/models/portfolio_state_machine.py +++ b/atst/models/portfolio_state_machine.py @@ -125,6 +125,15 @@ class PortfolioStateMachine( self.fail_stage(stage) elif state_obj.is_CREATED: + # if last CREATED state then transition to COMPLETED + if list(AzureStages)[-1].name == state_obj.name.split("_CREATED")[ + 0 + ] and "complete" in self.machine.get_triggers(state_obj.name): + app.logger.info( + "last stage completed. transitioning to COMPLETED state" + ) + self.trigger("complete", **kwargs) + # the create trigger for the next stage should be in the available # triggers for the current state create_trigger = next( diff --git a/tests/domain/test_portfolio_state_machine.py b/tests/domain/test_portfolio_state_machine.py index 46e37f4e..dac3bf2e 100644 --- a/tests/domain/test_portfolio_state_machine.py +++ b/tests/domain/test_portfolio_state_machine.py @@ -116,6 +116,7 @@ def test_fsm_transition_start(mock_cloud_provider, portfolio: Portfolio): FSMStates.TENANT_ADMIN_OWNERSHIP_CREATED, FSMStates.TENANT_PRINCIPAL_OWNERSHIP_CREATED, FSMStates.BILLING_OWNER_CREATED, + FSMStates.COMPLETED, ] if portfolio.csp_data is not None: @@ -139,7 +140,7 @@ def test_fsm_transition_start(mock_cloud_provider, portfolio: Portfolio): "first_name": ppoc.first_name, "last_name": ppoc.last_name, "country_code": "US", - "password_recovery_email_address": "email@example.com", # ppoc.email, + "password_recovery_email_address": ppoc.email, "address": { # TODO: TBD if we're sourcing this from data or config "company_name": "", "address_line_1": "",