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_expand_uri_document_uris(self, db_session): document = Document(document_uris=[ DocumentURI(uri='http://foo.com/', claimant='http://bar.com'), DocumentURI(uri='http://bar.com/', claimant='http://bar.com'), ]) db_session.add(document) db_session.flush() assert storage.expand_uri(db_session, 'http://foo.com/') == [ 'http://foo.com/', 'http://bar.com/' ]
def test_expand_uri_document_doesnt_expand_canonical_uris(self, db_session): document = Document(document_uris=[ DocumentURI(uri='http://foo.com/', claimant='http://example.com'), DocumentURI(uri='http://bar.com/', claimant='http://example.com'), DocumentURI(uri='http://example.com/', type='rel-canonical', claimant='http://example.com'), ]) db_session.add(document) db_session.flush() assert storage.expand_uri(db_session, "http://example.com/") == [ "http://example.com/"]
def test_document_not_found(annotation, db_session): document = Document(document_uris=[ DocumentURI(claimant='something-else', uri='something-else') ]) db_session.add(document) db_session.flush() assert annotation.document is None
def test_document(annotation, db_session): document = Document(document_uris=[ DocumentURI(claimant=annotation.target_uri, uri=annotation.target_uri) ]) db_session.add(document) db_session.flush() assert annotation.document == document