def test_get_dag_run_by_id_empty(mock_get_dag_run_db):
    '''test that an empty dag_run_list will return None'''
    action_resource = ActionsIdResource()
    context.policy_engine = ShipyardPolicy()
    dag_id = 'test_dag_id'
    execution_date = 'test_execution_date'
    result = action_resource.get_dag_run_by_id(dag_id, execution_date)
    mock_get_dag_run_db.assert_called_once_with(dag_id, execution_date)
    assert result is None
def test_on_get(mock_get_all_actions, mock_authorize):
    act_resource = ActionsResource()
    context.policy_engine = ShipyardPolicy()
    req = create_req(context, None)
    resp = create_resp()
    act_resource.on_get(req, resp)
    mock_authorize.assert_called_once_with(
        'workflow_orchestrator:list_actions', context)
    assert mock_get_all_actions.call_count == 1
    assert resp.body is not None
    assert resp.status == '200 OK'
def test_on_get(mock_authorize, mock_get_action):
    action_resource = ActionsIdResource()
    context.policy_engine = ShipyardPolicy()
    kwargs = {'action_id': None}
    req = create_req(context, None)
    resp = create_resp()
    action_resource.on_get(req, resp, **kwargs)
    mock_authorize.assert_called_once_with('workflow_orchestrator:get_action',
                                           context)
    mock_get_action.assert_called_once_with(kwargs['action_id'])
    assert resp.body == '"action_returned"'
    assert resp.status == '200 OK'
def test_on_post(mock_info, mock_create_action, mock_authorize, *args):
    act_resource = ActionsResource()
    context.policy_engine = ShipyardPolicy()
    json_body = json.dumps({
        'user': "******",
        'req_id': "test_req_id",
        'external_ctx': "test_ext_ctx",
        'name': "test_name"
    }).encode('utf-8')
    req = create_req(context, json_body)
    resp = create_resp()
    act_resource.on_post(req, resp)
    mock_authorize.assert_called_once_with(
        'workflow_orchestrator:create_action', context)
    mock_create_action.assert_called_once_with(action=json.loads(
        json_body.decode('utf-8')),
                                               context=context,
                                               allow_intermediate_commits=None)
    mock_info.assert_called_with("Id %s generated for action %s", 'test_id',
                                 'test_name')
    assert resp.status == '201 Created'
    assert resp.body is not None
    assert '/api/v1.0/actions/' in resp.location