def test_get_dag_run_by_id_notempty():
    '''test that a nonempty dag_run_list will return the 1st dag in the list'''
    action_resource = ActionsIdResource()
    action_resource.get_dag_run_db = dag_runs_db
    dag_id = 'test_dag_id'
    execution_date = 'test_execution_date'
    result = action_resource.get_dag_run_by_id(dag_id, execution_date)
    assert result == {
        'dag_id': 'did2',
        'execution_date': DATE_ONE,
        'state': 'FAILED',
        'run_id': '99',
        'external_trigger': 'something',
        'start_date': DATE_ONE,
        'end_date': DATE_ONE
    }
def test_get_action_success():
    """
    Tests the main response from get all actions
    """
    action_resource = ActionsIdResource()
    # stubs for db
    action_resource.get_action_db = actions_db
    action_resource.get_dag_run_db = dag_runs_db
    action_resource.get_tasks_db = tasks_db
    action_resource.get_validations_db = get_validations
    action_resource.get_action_command_audit_db = get_ac_audit

    action = action_resource.get_action('12345678901234567890123456')
    if action['name'] == 'dag_it':
        assert len(action['steps']) == 3
        assert action['dag_status'] == 'FAILED'
        assert len(action['command_audit']) == 2
def test_get_dag_run_db(mock_get_dag_runs_by_id):
    expected = {
        'dag_id': 'did2',
        'execution_date': DATE_ONE,
        'state': 'FAILED',
        'run_id': '99',
        'external_trigger': 'something',
        'start_date': DATE_ONE,
        'end_date': DATE_ONE
    }
    mock_get_dag_runs_by_id.return_value = expected
    action_resource = ActionsIdResource()
    dag_id = 'test_dag_id'
    execution_date = 'test_execution_date'

    result = action_resource.get_dag_run_db(dag_id, execution_date)
    mock_get_dag_runs_by_id.assert_called_once_with(
        dag_id=dag_id, execution_date=execution_date)
    assert result == expected