def test_create_action_validator_error(): action_resource = ActionsResource() action_resource.get_all_actions_db = actions_db action_resource.get_all_dag_runs_db = dag_runs_db action_resource.get_all_tasks_db = tasks_db action_resource.invoke_airflow_dag = airflow_stub action_resource.insert_action = insert_action_stub action_resource.audit_control_command_db = audit_control_command_db action_resource.get_committed_design_version = lambda: DESIGN_VERSION action_resource.check_intermediate_commit_revision = ( CHECK_INTERMEDIATE_COMMIT) # with valid input and some parameters with mock.patch('shipyard_airflow.control.action.action_validators' '.validate_site_action', side_effect=ApiError(title='bad')): with pytest.raises(ApiError) as apie: action = action_resource.create_action( action={'name': 'deploy_site', 'parameters': { 'a': 'aaa' }}, context=context, allow_intermediate_commits=False) assert action['timestamp'] assert action['id'] assert len(action['id']) == 26 assert action['dag_execution_date'] == '2017-09-06 14:10:08.528402' assert action['dag_status'] == 'SCHEDULED' assert action['committed_rev_id'] == 1 assert apie.value.title == 'bad'
def _gen_action_resource_stubbed(): # TODO(bryan-strassner): mabye subclass this instead? action_resource = ActionsResource() action_resource.get_all_actions_db = actions_db action_resource.get_all_dag_runs_db = dag_runs_db action_resource.get_all_tasks_db = tasks_db action_resource.invoke_airflow_dag = airflow_stub action_resource.insert_action = insert_action_stub action_resource.audit_control_command_db = audit_control_command_db action_resource.get_committed_design_version = lambda: DESIGN_VERSION return action_resource
def test_get_all_actions(*args): """ Tests the main response from get all actions """ action_resource = ActionsResource() action_resource.get_all_actions_db = actions_db action_resource.get_all_dag_runs_db = dag_runs_db action_resource.get_all_tasks_db = tasks_db result = action_resource.get_all_actions(verbosity=1) assert len(result) == len(actions_db()) for action in result: if action['name'] == 'dag_it': assert len(action['steps']) == 1 assert action['dag_status'] == 'FAILED' if action['name'] == 'dag2': assert len(action['steps']) == 3 assert action['dag_status'] == 'SUCCESS'
def test_get_all_actions(): """ Tests the main response from get all actions """ action_resource = ActionsResource() action_resource.get_all_actions_db = actions_db action_resource.get_all_dag_runs_db = dag_runs_db action_resource.get_all_tasks_db = tasks_db os.environ['DB_CONN_AIRFLOW'] = 'nothing' os.environ['DB_CONN_SHIPYARD'] = 'nothing' result = action_resource.get_all_actions() assert len(result) == len(actions_db()) for action in result: if action['name'] == 'dag_it': assert len(action['steps']) == 1 assert action['dag_status'] == 'FAILED' if action['name'] == 'dag2': assert len(action['steps']) == 3 assert action['dag_status'] == 'SUCCESS'
def test_get_all_actions_notes(*args): """ Tests the main response from get all actions """ action_resource = ActionsResource() action_resource.get_all_actions_db = actions_db action_resource.get_all_dag_runs_db = dag_runs_db action_resource.get_all_tasks_db = tasks_db # inject some notes nh.make_action_note('aaaaaa', "hello from aaaaaa1") nh.make_action_note('aaaaaa', "hello from aaaaaa2") nh.make_action_note('bbbbbb', "hello from bbbbbb") result = action_resource.get_all_actions(verbosity=1) assert len(result) == len(actions_db()) for action in result: if action['id'] == 'aaaaaa': assert len(action['notes']) == 2 if action['id'] == 'bbbbbb': assert len(action['notes']) == 1 assert action['notes'][0]['note_val'] == 'hello from bbbbbb'
def test_get_all_tasks_db(mock_get_all_tasks): act_resource = ActionsResource() act_resource.get_all_tasks_db() assert mock_get_all_tasks.called
def test_create_action(): action_resource = ActionsResource() action_resource.get_all_actions_db = actions_db action_resource.get_all_dag_runs_db = dag_runs_db action_resource.get_all_tasks_db = tasks_db action_resource.invoke_airflow_dag = airflow_stub action_resource.insert_action = insert_action_stub action_resource.audit_control_command_db = audit_control_command_db action_resource.get_committed_design_version = lambda: DESIGN_VERSION action_resource.check_intermediate_commit_revision = ( CHECK_INTERMEDIATE_COMMIT) # with invalid input. fail. with mock.patch('shipyard_airflow.control.action.action_validators' '.validate_site_action') as validator: try: action = action_resource.create_action( action={'name': 'broken', 'parameters': { 'a': 'aaa' }}, context=context, allow_intermediate_commits=False) assert False, 'Should throw an ApiError' except ApiError: # expected pass assert not validator.called # with valid input and some parameters with mock.patch('shipyard_airflow.control.action.action_validators' '.validate_site_action') as validator: try: action = action_resource.create_action( action={'name': 'deploy_site', 'parameters': { 'a': 'aaa' }}, context=context, allow_intermediate_commits=False) assert action['timestamp'] assert action['id'] assert len(action['id']) == 26 assert action['dag_execution_date'] == '2017-09-06 14:10:08.528402' assert action['dag_status'] == 'SCHEDULED' assert action['committed_rev_id'] == 1 except ApiError: assert False, 'Should not raise an ApiError' validator.assert_called_once_with(action) # with valid input and no parameters with mock.patch('shipyard_airflow.control.action.action_validators' '.validate_site_action') as validator: try: action = action_resource.create_action( action={'name': 'deploy_site'}, context=context, allow_intermediate_commits=False) assert action['timestamp'] assert action['id'] assert len(action['id']) == 26 assert action['dag_execution_date'] == '2017-09-06 14:10:08.528402' assert action['dag_status'] == 'SCHEDULED' assert action['committed_rev_id'] == 1 except ApiError: assert False, 'Should not raise an ApiError' validator.assert_called_once_with(action)