Пример #1
0
def get_output_contents_by_request_id_status(request_id,
                                             name,
                                             content_status,
                                             limit,
                                             transform_id=None,
                                             to_json=False,
                                             session=None):
    """
    Get output content by request_id and content name

    :param request_id: requestn id.
    :param name: the content name.
    :param content_status: The content status.
    :param limit: limit number of contents.
    :param to_json: return json format.
    :param session: The database session in use.

    :returns: content of the output collection.
    """
    transform_ids = orm_transforms.get_transform_ids(request_id,
                                                     session=session)

    found_transform_id = None
    if transform_ids:
        if len(transform_ids) == 1:
            found_transform_id = transform_ids[0]
        elif len(transform_ids) > 1 and transform_id is None:
            raise "Number of the transforms(%s) is bigger than 1 and transform id is not provided" % len(
                transform_ids)
        else:
            for tf_id in transform_ids:
                if tf_id == transform_id:
                    found_transform_id = tf_id
                    break

    coll_id = None
    if found_transform_id:
        coll_id = orm_collections.get_collection_id(
            transform_id=found_transform_id,
            relation_type=CollectionRelationType.Output,
            session=session)

    contents = []
    if coll_id:
        contents = orm_contents.get_contents(coll_id=coll_id,
                                             status=content_status,
                                             to_json=to_json,
                                             session=session)

    if name:
        new_contents = []
        for content in contents:
            if str(content['name']) == str(name):
                new_contents.append(content)
        contents = new_contents

    if contents and limit and len(contents) > limit:
        contents = contents[:limit]
    return contents
Пример #2
0
def get_output_content_by_request_id_content_name(request_id,
                                                  content_scope,
                                                  content_name,
                                                  transform_id=None,
                                                  content_type=None,
                                                  min_id=None,
                                                  max_id=None,
                                                  to_json=False,
                                                  session=None):
    """
    Get output content by request_id and content name

    :param request_id: requestn id.
    :param content_name: The name of the content.
    :param to_json: return json format.
    :param session: The database session in use.

    :returns: content of the output collection.
    """
    transform_ids = orm_transforms.get_transform_ids(request_id,
                                                     session=session)

    found_transform_id = None
    if transform_ids:
        if len(transform_ids) == 1:
            found_transform_id = transform_ids[0]
        elif len(transform_ids) > 1 and transform_id is None:
            raise "Number of the transforms(%s) is bigger than 1 and transform id is not provided" % len(
                transform_ids)
        else:
            for tf_id in transform_ids:
                if tf_id == transform_id:
                    found_transform_id = tf_id
                    break

    coll_id = None
    if found_transform_id:
        coll_id = orm_collections.get_collection_id(
            transform_id=found_transform_id,
            relation_type=CollectionRelationType.Output,
            session=session)
    content = None
    if coll_id:
        content = orm_contents.get_content(coll_id=coll_id,
                                           scope=content_scope,
                                           name=content_name,
                                           content_type=content_type,
                                           min_id=min_id,
                                           max_id=max_id,
                                           to_json=to_json,
                                           session=session)
    return content
    def test_create_and_check_for_transform_collection_content_orm(self):
        """ Transform/Collection/Content (ORM): Test the creation, query, and cancel of a Transform/Collection/Content """

        trans_properties = get_transform_properties()
        coll_properties = get_collection_properties()
        content_properties = get_content_properties()

        trans_id = add_transform(**trans_properties)

        coll_properties['transform_id'] = trans_id
        coll_id = add_collection(**coll_properties)
        coll_id_1 = get_collection_id(
            transform_id=trans_id,
            relation_type=coll_properties['relation_type'])
        assert_equal(coll_id, coll_id_1)

        coll = get_collection(coll_id=coll_id)
        for key in coll_properties:
            assert_equal(coll[key], coll_properties[key])

        update_collection(coll_id, {'status': CollectionStatus.Closed})
        coll = get_collection(coll_id=coll_id)
        assert_equal(coll['status'], CollectionStatus.Closed)

        content_properties['coll_id'] = coll_id
        content_id = add_content(**content_properties)
        content_1 = get_content(coll_id=coll_id,
                                scope=content_properties['scope'],
                                name=content_properties['name'],
                                content_type=ContentType.File)
        content_id_1 = content_1['content_id']
        assert_equal(content_id, content_id_1)

        content = get_content(content_id=content_id)
        update_content(content_id=content_id,
                       parameters={'status': ContentStatus.Lost})
        content = get_content(content_id=content_id)
        assert_equal(content['status'], ContentStatus.Lost)

        delete_content(content_id=content_id)
        c = get_content(content_id=content_id)
        assert_equal(c, None)

        delete_collection(coll_id=coll_id)
        coll = get_collection(coll_id=coll_id)
        assert_equal(coll, None)

        delete_transform(transform_id=trans_id)
        t = get_transform(transform_id=trans_id)
        assert_equal(t, None)