Esempio n. 1
0
 def test_reviewed_entities(self):
     review = db_review.create(
         user_id=self.user.id,
         entity_id="e7aad618-fa86-3983-9e77-405e21796eca",
         entity_type="release_group",
         text="Awesome",
         is_draft=False,
         license_id=self.license["id"],
     )
     reviewed_entities = db_review.reviewed_entities(
         entity_ids=["e7aad618-fa86-3983-9e77-405e21796eca", "deae6fc2-a675-4f35-9565-d2aaea4872c7"],
         entity_type="release_group",
     )
     self.assertListEqual(reviewed_entities, ["e7aad618-fa86-3983-9e77-405e21796eca"])
     db_review.delete(review["id"])
     reviewed_entities = db_review.reviewed_entities(
         entity_ids=["e7aad618-fa86-3983-9e77-405e21796eca"],
         entity_type="release_group",
     )
     self.assertListEqual(reviewed_entities, [])
Esempio n. 2
0
def get_entities_by_gids(*, query, entity_type, mbids):
    """Get entities using their MBIDs.

    An entity can have multiple MBIDs. This function may be passed another
    MBID of an entity, in which case, it is redirected to the original entity.

    Note that the query may be modified before passing it to this
    function in order to save queries made to the database.

    Args:
        query (Query): SQLAlchemy Query object.
        entity_type (str): Type of entity being queried.
        mbids (list): IDs of the target entities.

    Returns:
        Dictionary of objects of target entities keyed by their MBID.
    """
    entity_model = ENTITY_MODELS[entity_type]
    results = query.filter(entity_model.gid.in_(mbids)).all()
    remaining_gids = list(set(mbids) - {entity.gid for entity in results})
    entities = {str(entity.gid): entity for entity in results}
    if remaining_gids:
        redirect_model = REDIRECT_MODELS[entity_type]
        query = query.add_entity(redirect_model).join(redirect_model)
        results = query.filter(redirect_model.gid.in_(remaining_gids))
        for entity, redirect_obj in results:
            entities[redirect_obj.gid] = entity
        remaining_gids = list(
            set(remaining_gids) -
            {redirect_obj.gid
             for entity, redirect_obj in results})

    if remaining_gids and entity_type in CB_ENTITIES:
        reviewed_gids = reviewed_entities(
            entity_ids=remaining_gids,
            entity_type=entity_type,
        )
        for entity_id in reviewed_gids:
            entities[entity_id] = unknown_entity(entity_id, entity_type)
        remaining_gids = list(set(remaining_gids) - set(reviewed_gids))

    if remaining_gids:
        raise mb_exceptions.NoDataFoundException(
            "Couldn't find entities with IDs: {mbids}".format(
                mbids=remaining_gids))
    return entities
Esempio n. 3
0
def get_entities_by_gids(*, query, entity_type, mbids):
    """Get entities using their MBIDs.

    An entity can have multiple MBIDs. This function may be passed another
    MBID of an entity, in which case, it is redirected to the original entity.

    Note that the query may be modified before passing it to this
    function in order to save queries made to the database.

    Args:
        query (Query): SQLAlchemy Query object.
        entity_type (str): Type of entity being queried.
        mbids (list): IDs of the target entities.

    Returns:
        Dictionary of objects of target entities keyed by their MBID.
    """
    entity_model = ENTITY_MODELS[entity_type]
    results = query.filter(entity_model.gid.in_(mbids)).all()
    remaining_gids = list(set(mbids) - {entity.gid for entity in results})
    entities = {str(entity.gid): entity for entity in results}
    if remaining_gids:
        redirect_model = REDIRECT_MODELS[entity_type]
        query = query.add_entity(redirect_model).join(redirect_model)
        results = query.filter(redirect_model.gid.in_(remaining_gids))
        for entity, redirect_obj in results:
            entities[redirect_obj.gid] = entity
        remaining_gids = list(set(remaining_gids) - {redirect_obj.gid for entity, redirect_obj in results})

    if remaining_gids and entity_type in CB_ENTITIES:
        reviewed_gids = reviewed_entities(
            entity_ids=remaining_gids,
            entity_type=entity_type,
        )
        for entity_id in reviewed_gids:
            entities[entity_id] = unknown_entity(entity_id, entity_type)
        remaining_gids = list(set(remaining_gids) - set(reviewed_gids))

    if remaining_gids:
        raise mb_exceptions.NoDataFoundException("Couldn't find entities with IDs: {mbids}".format(mbids=remaining_gids))
    return entities