def test_it_returns_annotations_for_ids_in_the_same_order(self, db_session, factories): ann_1 = factories.Annotation(userid='luke') ann_2 = factories.Annotation(userid='luke') assert [ann_2, ann_1] == storage.fetch_ordered_annotations(db_session, [ann_2.id, ann_1.id]) assert [ann_1, ann_2] == storage.fetch_ordered_annotations(db_session, [ann_1.id, ann_2.id])
def fetch_annotations(session, ids, reply_ids): def load_documents(query): return query.options(subqueryload(Annotation.document)) annotations = storage.fetch_ordered_annotations( session, ids, query_processor=load_documents) replies = storage.fetch_ordered_annotations(session, reply_ids) return (annotations, replies)
def test_it_returns_annotations_for_ids_in_the_same_order(self, db_session): ann_1 = Annotation(userid='luke') ann_2 = Annotation(userid='luke') db_session.add_all([ann_1, ann_2]) db_session.flush() assert [ann_2, ann_1] == storage.fetch_ordered_annotations(db_session, [ann_2.id, ann_1.id]) assert [ann_1, ann_2] == storage.fetch_ordered_annotations(db_session, [ann_1.id, ann_2.id])
def test_it_returns_annotations_for_ids_in_the_same_order( self, db_session): ann_1 = Annotation(userid='luke') ann_2 = Annotation(userid='luke') db_session.add_all([ann_1, ann_2]) db_session.flush() assert [ann_2, ann_1 ] == storage.fetch_ordered_annotations(db_session, [ann_2.id, ann_1.id]) assert [ann_1, ann_2 ] == storage.fetch_ordered_annotations(db_session, [ann_1.id, ann_2.id])
def test_it_allows_to_change_the_query(self, db_session): ann_1 = Annotation(userid='luke', target_uri='http://example.com') ann_2 = Annotation(userid='maria', target_uri='http://example.com') db_session.add_all([ann_1, ann_2]) doc = Document(document_uris=[ DocumentURI(uri='http://bar.com/', claimant='http://example.com'), DocumentURI(uri='http://example.com/', type='rel-canonical', claimant='http://example.com') ], meta=[ DocumentMeta(claimant='http://example.com', type='title', value='Example') ]) db_session.add(doc) db_session.flush() def only_maria(query): return query.filter(Annotation.userid == 'maria') assert [ann_2] == storage.fetch_ordered_annotations( db_session, [ann_2.id, ann_1.id], query_processor=only_maria)
def test_it_allows_to_change_the_query(self, db_session, factories): ann_1 = factories.Annotation(userid='luke') ann_2 = factories.Annotation(userid='maria') def only_maria(query): return query.filter(Annotation.userid == 'maria') assert [ann_2] == storage.fetch_ordered_annotations( db_session, [ann_2.id, ann_1.id], query_processor=only_maria)
def test_it_allows_to_change_the_query(self, db_session, factories): ann_1 = factories.Annotation(userid='luke') ann_2 = factories.Annotation(userid='maria') def only_maria(query): return query.filter(Annotation.userid == 'maria') assert [ann_2] == storage.fetch_ordered_annotations(db_session, [ann_2.id, ann_1.id], query_processor=only_maria)
def _present_annotations(request, ids): """Load annotations by id from the database and present them.""" def eager_load_documents(query): return query.options( subqueryload(models.Annotation.document)) annotations = storage.fetch_ordered_annotations(request.db, ids, query_processor=eager_load_documents) links_service = request.find_service(name='links') return [AnnotationJSONPresenter(ann, links_service).asdict() for ann in annotations]
def _present_annotations(request, ids): """Load annotations by id from the database and present them.""" def eager_load_documents(query): return query.options(subqueryload(models.Annotation.document)) annotations = storage.fetch_ordered_annotations( request.db, ids, query_processor=eager_load_documents) links_service = request.find_service(name='links') return [ AnnotationJSONPresenter(ann, links_service).asdict() for ann in annotations ]
def test_it_allows_to_change_the_query(self, db_session): ann_1 = Annotation(userid='luke', target_uri='http://example.com') ann_2 = Annotation(userid='maria', target_uri='http://example.com') db_session.add_all([ann_1, ann_2]) doc = Document( document_uris=[DocumentURI(uri='http://bar.com/', claimant='http://example.com'), DocumentURI(uri='http://example.com/', type='rel-canonical', claimant='http://example.com')], meta=[DocumentMeta(claimant='http://example.com', type='title', value='Example')]) db_session.add(doc) db_session.flush() def only_maria(query): return query.filter(Annotation.userid == 'maria') assert [ann_2] == storage.fetch_ordered_annotations(db_session, [ann_2.id, ann_1.id], query_processor=only_maria)
def _annotations(request): """Return the annotations from the search API.""" result = search.Search(request, stats=request.stats).run(request.params) return fetch_ordered_annotations(request.db, result.annotation_ids)
def _annotations(request): """Return the annotations from the search API.""" result = search.Search(request).run(request.params) return storage.fetch_ordered_annotations(request.db, result.annotation_ids)