Exemple #1
0
def _create_contents(session, entity_type, parent, name, attributes=None):
    if attributes is None:
        attributes = {}

    if isinstance(parent, six.string_types):
        parent = session.get(session.entity_path('entities', entity_id=parent))

    attributes.update({'name': name})

    attr = {'type': entity_type,
            'attributes': attributes}

    result = session.post(parent['links']['self'], data={'entities': [attr]})
    return simplify_response(result['entities'][0])
def should_create_activity():
    label = 'activity-label'
    workflow_id = 1
    workflow = {'relationships': {label: {'self': sentinel.activity_url}}}

    s = Mock(spec=Session)
    s.entity_path.return_value = sentinel.workflow_path
    s.get.return_value = simplify_response({'workflow': workflow, 'resources': []})
    s.post.return_value = DataDict({'activity': sentinel.activity})

    activity = {}
    workflows.create_activity(s, workflow_id, label, activity=activity)

    s.entity_path.assert_called_with('workflows', workflow_id)
    s.get.assert_called_with(sentinel.workflow_path)
    s.post.assert_called_with(sentinel.activity_url, data={'activity': activity})
def should_create_activity_with_resources(upload):
    label = 'activity-label'
    workflow_id = 1
    workflow = {'relationships': {label: {'self': sentinel.activity_url}}}

    s = Mock(spec=Session)
    s.entity_path.return_value = sentinel.workflow_path
    s.get.return_value = simplify_response({'workflow': workflow, 'resources': []})
    uuid = 'activity-uuid'
    s.post.return_value = DataDict({'activity': {'uuid': uuid}})

    activity = {}
    workflows.create_activity(s, workflow_id, label, activity=activity, resources={'foo': ['foo.txt']})

    s.entity_path.assert_called_with('workflows', workflow_id)
    s.get.assert_called_with(sentinel.workflow_path)
    s.post.assert_called_with(sentinel.activity_url, data={'activity': {'complete': False}})
    upload.assert_called_with(s, uuid, 'foo.txt', label='foo', progress=tqdm)