コード例 #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)
コード例 #2
0
ファイル: annotation_test.py プロジェクト: pombredanne/h
def test_setting_extras_inline_is_persisted(db_session):
    """
    In-place changes to Annotation.extra should be persisted.

    Setting an Annotation.extra value in-place:

        my_annotation.extra['foo'] = 'bar'

    should be persisted to the database.

    """
    annotation = Annotation(userid='fred')
    db_session.add(annotation)

    # We need to flush the db here so that the default value for
    # annotation.extra gets persisted and out mutation of annotation.extra
    # below happens when the previous value is already persisted, otherwise
    # this test would never fail.
    db_session.flush()

    annotation.extra['foo'] = 'bar'

    # We need to commit the db session here so that the in-place change to
    # annotation.extra above would be lost if annotation.extra was a normal
    # dict. Without this commit() this test would never fail.
    db_session.commit()

    annotation = db_session.query(Annotation).get(annotation.id)

    assert annotation.extra == {'foo': 'bar'}
コード例 #3
0
def test_setting_extras_inline_is_persisted(db_session):
    """
    In-place changes to Annotation.extra should be persisted.

    Setting an Annotation.extra value in-place:

        my_annotation.extra['foo'] = 'bar'

    should be persisted to the database.

    """
    annotation = Annotation(userid='fred')
    db_session.add(annotation)

    # We need to flush the db here so that the default value for
    # annotation.extra gets persisted and out mutation of annotation.extra
    # below happens when the previous value is already persisted, otherwise
    # this test would never fail.
    db_session.flush()

    annotation.extra['foo'] = 'bar'

    # We need to commit the db session here so that the in-place change to
    # annotation.extra above would be lost if annotation.extra was a normal
    # dict. Without this commit() this test would never fail.
    db_session.commit()

    annotation = db_session.query(Annotation).get(annotation.id)

    assert annotation.extra == {'foo': 'bar'}
コード例 #4
0
def test_acl_group_shared():
    ann = Annotation(shared=True, userid='saoirse', groupid='lulapalooza')
    actual = ann.__acl__()
    expect = [(security.Allow, 'group:lulapalooza', 'read'),
              (security.Allow, 'saoirse', 'admin'),
              (security.Allow, 'saoirse', 'update'),
              (security.Allow, 'saoirse', 'delete'), security.DENY_ALL]
    assert actual == expect
コード例 #5
0
def test_acl_world_shared():
    ann = Annotation(shared=True, userid='saoirse', groupid='__world__')
    actual = ann.__acl__()
    expect = [(security.Allow, security.Everyone, 'read'),
              (security.Allow, 'saoirse', 'admin'),
              (security.Allow, 'saoirse', 'update'),
              (security.Allow, 'saoirse', 'delete'), security.DENY_ALL]
    assert actual == expect
コード例 #6
0
def test_acl_private():
    ann = Annotation(shared=False, userid='saoirse')
    actual = ann.__acl__()
    expect = [(security.Allow, 'saoirse', 'read'),
              (security.Allow, 'saoirse', 'admin'),
              (security.Allow, 'saoirse', 'update'),
              (security.Allow, 'saoirse', 'delete'), security.DENY_ALL]
    assert actual == expect
コード例 #7
0
ファイル: annotation_test.py プロジェクト: pombredanne/h
def test_acl_world_shared():
    ann = Annotation(shared=True, userid='saoirse', groupid='__world__')
    actual = ann.__acl__()
    expect = [(security.Allow, security.Everyone, 'read'),
              (security.Allow, 'saoirse', 'admin'),
              (security.Allow, 'saoirse', 'update'),
              (security.Allow, 'saoirse', 'delete'),
              security.DENY_ALL]
    assert actual == expect
コード例 #8
0
ファイル: annotation_test.py プロジェクト: pombredanne/h
def test_acl_group_shared():
    ann = Annotation(shared=True, userid='saoirse', groupid='lulapalooza')
    actual = ann.__acl__()
    expect = [(security.Allow, 'group:lulapalooza', 'read'),
              (security.Allow, 'saoirse', 'admin'),
              (security.Allow, 'saoirse', 'update'),
              (security.Allow, 'saoirse', 'delete'),
              security.DENY_ALL]
    assert actual == expect
コード例 #9
0
ファイル: annotation_test.py プロジェクト: pombredanne/h
def test_text_setter_renders_markdown(markdown):
    markdown.render.return_value = '<p>foobar</p>'

    annotation = Annotation()
    annotation.text = 'foobar'

    markdown.render.assert_called_once_with('foobar')

    annotation.text_rendered == markdown.render.return_value
コード例 #10
0
ファイル: annotation_test.py プロジェクト: pombredanne/h
def test_acl_private():
    ann = Annotation(shared=False, userid='saoirse')
    actual = ann.__acl__()
    expect = [(security.Allow, 'saoirse', 'read'),
              (security.Allow, 'saoirse', 'admin'),
              (security.Allow, 'saoirse', 'update'),
              (security.Allow, 'saoirse', 'delete'),
              security.DENY_ALL]
    assert actual == expect
コード例 #11
0
ファイル: annotation_test.py プロジェクト: nlisgo/h
def test_text_setter_renders_markdown(markdown):
    markdown.render.return_value = "<p>foobar</p>"

    annotation = Annotation()
    annotation.text = "foobar"

    markdown.render.assert_called_once_with("foobar")

    annotation.text_rendered == markdown.render.return_value
コード例 #12
0
def test_text_setter_renders_markdown(markdown):
    markdown.render.return_value = '<p>foobar</p>'

    annotation = Annotation()
    annotation.text = 'foobar'

    markdown.render.assert_called_once_with('foobar')

    annotation.text_rendered == markdown.render.return_value
コード例 #13
0
    def test_it_deletes_the_annotation(self, db_session):
        ann_1 = Annotation(userid='luke')
        ann_2 = Annotation(userid='leia')
        db_session.add_all([ann_1, ann_2])
        db_session.flush()

        storage.delete_annotation(db_session, ann_1.id)
        db_session.commit()

        assert db_session.query(Annotation).get(ann_1.id) is None
        assert db_session.query(Annotation).get(ann_2.id) == ann_2
コード例 #14
0
ファイル: annotation_test.py プロジェクト: nlisgo/h
def test_acl_group_shared():
    ann = Annotation(shared=True, userid="saoirse", groupid="lulapalooza")
    actual = ann.__acl__()
    expect = [
        (security.Allow, "group:lulapalooza", "read"),
        (security.Allow, "saoirse", "admin"),
        (security.Allow, "saoirse", "update"),
        (security.Allow, "saoirse", "delete"),
        security.DENY_ALL,
    ]
    assert actual == expect
コード例 #15
0
ファイル: annotation_test.py プロジェクト: nlisgo/h
def test_acl_world_shared():
    ann = Annotation(shared=True, userid="saoirse", groupid="__world__")
    actual = ann.__acl__()
    expect = [
        (security.Allow, security.Everyone, "read"),
        (security.Allow, "saoirse", "admin"),
        (security.Allow, "saoirse", "update"),
        (security.Allow, "saoirse", "delete"),
        security.DENY_ALL,
    ]
    assert actual == expect
コード例 #16
0
ファイル: annotation_test.py プロジェクト: nlisgo/h
def test_acl_private():
    ann = Annotation(shared=False, userid="saoirse")
    actual = ann.__acl__()
    expect = [
        (security.Allow, "saoirse", "read"),
        (security.Allow, "saoirse", "admin"),
        (security.Allow, "saoirse", "update"),
        (security.Allow, "saoirse", "delete"),
        security.DENY_ALL,
    ]
    assert actual == expect
コード例 #17
0
ファイル: annotation_test.py プロジェクト: pombredanne/h
def test_deleting_tags_inline_is_persisted(db_session):
    """In-place deletions of annotation tags should be persisted."""
    annotation = Annotation(userid='fred')
    annotation.tags = ['foo']
    db_session.add(annotation)
    db_session.flush()

    del annotation.tags[0]
    db_session.commit()
    annotation = db_session.query(Annotation).get(annotation.id)

    assert 'foo' not in annotation.tags
コード例 #18
0
def test_deleting_tags_inline_is_persisted(db_session):
    """In-place deletions of annotation tags should be persisted."""
    annotation = Annotation(userid='fred')
    annotation.tags = ['foo']
    db_session.add(annotation)
    db_session.flush()

    del annotation.tags[0]
    db_session.commit()
    annotation = db_session.query(Annotation).get(annotation.id)

    assert 'foo' not in annotation.tags
コード例 #19
0
    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])
コード例 #20
0
    def test_it_fetches_and_returns_the_annotation(self, db_session):
        annotation = Annotation(userid='luke')
        db_session.add(annotation)
        db_session.flush()

        actual = storage.fetch_annotation(db_session, annotation.id)
        assert annotation == actual
コード例 #21
0
def test_og_no_document(render_app_html, pyramid_request):
    annotation = Annotation(id='123', userid='foo', target_uri='http://example.com')

    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']
    assert any(test(d) for d in kwargs['extra']['meta_attrs'])
コード例 #22
0
def test_deleting_extras_inline_is_persisted(db_session):
    """
    In-place changes to Annotation.extra should be persisted.

    Deleting an Annotation.extra value in-place should be persisted to the
    database.

    """
    annotation = Annotation(userid='fred')
    annotation.extra = {'foo': 'bar'}
    db_session.add(annotation)
    db_session.flush()

    del annotation.extra['foo']
    db_session.commit()
    annotation = db_session.query(Annotation).get(annotation.id)

    assert 'foo' not in annotation.extra
コード例 #23
0
def test_appending_tags_inline_is_persisted(db_session):
    """
    In-place changes to Annotation.tags should be persisted.

    Changes made by Annotation.tags.append() should be persisted to the
    database.

    """
    annotation = Annotation(userid='fred')
    annotation.tags = []  # FIXME: Annotation should have a default value here.
    db_session.add(annotation)
    db_session.flush()

    annotation.tags.append('foo')
    db_session.commit()
    annotation = db_session.query(Annotation).get(annotation.id)

    assert 'foo' in annotation.tags
コード例 #24
0
def test_thread_root_id_returns_first_reference_if_many_references():
    annotation = Annotation(id='uK9yVjoHEea6hsewWuiKtQ',
                            references=[
                                '1Ife3DoHEea6hpv8vWujdQ',
                                'uVuItjoHEea6hiNgv1wvmg',
                                'Qe7fpc5ZRgWy0RSHEP9UNg'
                            ])

    assert annotation.thread_root_id == '1Ife3DoHEea6hpv8vWujdQ'
コード例 #25
0
ファイル: annotation_test.py プロジェクト: pombredanne/h
def test_appending_tags_inline_is_persisted(db_session):
    """
    In-place changes to Annotation.tags should be persisted.

    Changes made by Annotation.tags.append() should be persisted to the
    database.

    """
    annotation = Annotation(userid='fred')
    annotation.tags = []  # FIXME: Annotation should have a default value here.
    db_session.add(annotation)
    db_session.flush()

    annotation.tags.append('foo')
    db_session.commit()
    annotation = db_session.query(Annotation).get(annotation.id)

    assert 'foo' in annotation.tags
コード例 #26
0
ファイル: annotation_test.py プロジェクト: pombredanne/h
def test_deleting_extras_inline_is_persisted(db_session):
    """
    In-place changes to Annotation.extra should be persisted.

    Deleting an Annotation.extra value in-place should be persisted to the
    database.

    """
    annotation = Annotation(userid='fred')
    annotation.extra = {'foo': 'bar'}
    db_session.add(annotation)
    db_session.flush()

    del annotation.extra['foo']
    db_session.commit()
    annotation = db_session.query(Annotation).get(annotation.id)

    assert 'foo' not in annotation.extra
コード例 #27
0
def test_og_no_document(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)
    sidebar_app.side_effect = _fake_sidebar_app

    ctx = main.annotation_page(context, pyramid_request)

    def test(d):
        return 'foo' in d['content']
    assert any(test(d) for d in ctx['meta_attrs'])
コード例 #28
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'])
コード例 #29
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'])
コード例 #30
0
def test_parent_id_of_reply_to_reply():
    ann = Annotation(references=['reply1', 'reply2', 'parent_id'])

    assert ann.parent_id == 'parent_id'
コード例 #31
0
def test_thread_root_id_returns_reference_if_only_one_reference():
    annotation = Annotation(id='qvJnIjoHEea6hiv0nJK7gw',
                            references=['yiSVIDoHEea6hjcSFuROLw'])

    assert annotation.thread_root_id == 'yiSVIDoHEea6hjcSFuROLw'
コード例 #32
0
def annotation(db_session):
    ann = Annotation(userid="testuser", target_uri="http://example.com")

    db_session.add(ann)
    db_session.flush()
    return ann
コード例 #33
0
def test_thread_root_id_returns_id_if_references_empty():
    annotation = Annotation(id='jANlljoHEea6hsv8FY7ipw', references=[])

    assert annotation.thread_root_id == 'jANlljoHEea6hsv8FY7ipw'
コード例 #34
0
def test_parent_id_of_annotation():
    ann = Annotation()

    assert ann.parent_id is None
コード例 #35
0
def test_parent_id_of_direct_reply():
    ann = Annotation(references=['parent_id'])

    assert ann.parent_id == 'parent_id'
コード例 #36
0
def test_thread_root_id_returns_id_if_no_references():
    annotation = Annotation(id='GBhy1DoHEea6htPothzqZQ')

    assert annotation.thread_root_id == 'GBhy1DoHEea6htPothzqZQ'