Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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
Exemplo n.º 4
0
    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/'
        ]
Exemplo n.º 5
0
def test_og_document(render_app_html, annotation_document, document_title, pyramid_request):
    annotation = Annotation(id='123', userid='foo', target_uri='http://example.com')
    document = Document()
    annotation_document.return_value = document
    document_title.return_value = 'WikiHow — How to Make a ☆Starmap☆'

    render_app_html.return_value = '<html></html>'
    main.annotation_page(annotation, pyramid_request)
    args, kwargs = render_app_html.call_args
    test = lambda d: 'foo' in d['content'] and 'Starmap' in d['content']
    assert any(test(d) for d in kwargs['extra']['meta_attrs'])
Exemplo n.º 6
0
    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/"]
Exemplo n.º 7
0
def test_og_document(annotation_document, document_title, pyramid_request,
                     group_service, links_service, sidebar_app):
    annotation = Annotation(id='123', userid='foo', target_uri='http://example.com')
    context = AnnotationResource(annotation, group_service, links_service)
    document = Document()
    annotation_document.return_value = document
    document_title.return_value = 'WikiHow — How to Make a ☆Starmap☆'
    sidebar_app.side_effect = _fake_sidebar_app

    ctx = main.annotation_page(context, pyramid_request)

    def test(d):
        return 'foo' in d['content'] and 'Starmap' in d['content']
    assert any(test(d) for d in ctx['meta_attrs'])