"""Test to validate action status.""" from abacus_state.constants.constants import ( STATEMENT_PERIOD_ADJUSTMENT_FILE_ACTION_NAMES, ) from abacus_state.utils.validate_action_status import are_previous_actions_completed from tests.utils.factories import AbacusStateFactory def test_are_previous_actions_completed_returns_true(): """Test are_previous_actions_completed function. returns true when all previous actions are in complete state. """ parent_table_id = 124 ordered_actions = list(STATEMENT_PERIOD_ADJUSTMENT_FILE_ACTION_NAMES[0:3]) action_state_1 = AbacusStateFactory.create( action_name=STATEMENT_PERIOD_ADJUSTMENT_FILE_ACTION_NAMES.UPLOAD_FILE, action_status='complete', parent_table_name='statement_period_adjustment_file', parent_table_id=parent_table_id, ) action_state_2 = AbacusStateFactory.create( action_name=STATEMENT_PERIOD_ADJUSTMENT_FILE_ACTION_NAMES.IMPORT_FILE, action_status='complete', parent_table_name='statement_period_adjustment_file', parent_table_id=parent_table_id, ) action_state_3 = AbacusStateFactory.create( action_name=STATEMENT_PERIOD_ADJUSTMENT_FILE_ACTION_NAMES.APPROVE_FILE, action_status='init', parent_table_name='statement_period_adjustment_file', parent_table_id=parent_table_id, ) actions = { action.action_name: action.action_status for action in [action_state_1, action_state_2, action_state_3] } result = are_previous_actions_completed( actions, action_state_3.action_name, ordered_actions ) assert result is True def test_are_previous_actions_completed_returns_false(): """Test are_previous_actions_completed function. returns false when all previous actions are not in complete state. """ parent_table_id = 125 ordered_actions = list(STATEMENT_PERIOD_ADJUSTMENT_FILE_ACTION_NAMES) action_states = [ AbacusStateFactory.create( action_name=action_name, action_status='init', parent_table_name='statement_period_adjustment_file', parent_table_id=parent_table_id, ) for action_name in ordered_actions ] actions = {action.action_name: action.action_status for action in action_states} result = are_previous_actions_completed( actions, action_states[2].action_name, ordered_actions ) assert result is False