Пример #1
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'}
Пример #2
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
Пример #3
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
Пример #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_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
Пример #6
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
Пример #7
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
Пример #8
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
Пример #9
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
Пример #10
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
Пример #11
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
Пример #12
0
def test_og_no_document(render_app_html):
    annotation = Annotation(id='123', userid='foo', target_uri='http://example.com')

    render_app_html.return_value = '<html></html>'
    request = _dummy_request()
    main.annotation_page(annotation, 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'])
Пример #13
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
Пример #14
0
    def test_postgres(self, postgres_enabled):
        request = DummyRequest(db=db.Session)
        postgres_enabled.return_value = True

        annotation = Annotation(userid='luke')
        db.Session.add(annotation)
        db.Session.flush()

        actual = storage.fetch_annotation(request, annotation.id)
        assert annotation == actual
Пример #15
0
def test_og_document(render_app_html, annotation_document, document_title):
    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>'
    request = _dummy_request()
    main.annotation_page(annotation, 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'])
Пример #16
0
    def test_it_uses_postgres_if_postgres_arg_is_True(self, postgres_enabled):
        """If postgres=True it uses postgres even if feature flag is off."""
        request = DummyRequest(db=db.Session)
        postgres_enabled.return_value = False  # The feature flag is off.
        annotation = Annotation(userid='luke')
        db.Session.add(annotation)
        db.Session.flush()

        actual = storage.fetch_annotation(
            request, annotation.id, _postgres=True)

        assert annotation == actual
Пример #17
0
def annotation():
    ann = Annotation(userid="testuser", target_uri="http://example.com")

    db.Session.add(ann)
    db.Session.flush()
    return ann
Пример #18
0
def annotation_from_data(es_ann):
    # No joke. This is a thing.
    if es_ann.id == '_query':
        raise Skip("not an annotation (id=_query)")

    ann = Annotation.query.get(es_ann.id)
    if ann is None:
        ann = Annotation(id=es_ann.id)

    if es_ann.target_uri is None:
        raise Skip("annotation is missing a target source and uri")

    ann.created = es_ann.created
    ann.updated = es_ann.updated
    ann.userid = es_ann.userid
    ann.groupid = es_ann.groupid
    ann.text = es_ann.text
    ann.tags = es_ann.tags
    ann.references = es_ann.references
    ann.shared = es_ann.shared
    ann.target_uri = es_ann.target_uri
    ann.target_selectors = es_ann.target_selectors
    ann.extra = es_ann.extra

    return ann
Пример #19
0
def test_parent_id_of_annotation():
    ann = Annotation()

    assert ann.parent_id is None
Пример #20
0
def test_parent_id_of_reply_to_reply():
    ann = Annotation(references=['reply1', 'reply2', 'parent_id'])

    assert ann.parent_id == 'parent_id'
Пример #21
0
def test_parent_id_of_direct_reply():
    ann = Annotation(references=['parent_id'])

    assert ann.parent_id == 'parent_id'
Пример #22
0
def annotation_from_data(es_ann):
    # No joke. This is a thing.
    if es_ann.id == '_query':
        raise Skip("not an annotation (id=_query)")

    ann = Annotation.query.get(es_ann.id)
    if ann is None:
        ann = Annotation(id=es_ann.id)

    if es_ann.target_uri is None:
        raise Skip("annotation is missing a target source and uri")

    ann.created = es_ann.created
    ann.updated = es_ann.updated
    ann.userid = es_ann.userid
    ann.groupid = es_ann.groupid
    ann.text = es_ann.text
    ann.tags = es_ann.tags
    ann.references = es_ann.references
    ann.shared = es_ann.shared
    ann.target_uri = es_ann.target_uri
    ann.target_selectors = es_ann.target_selectors
    ann.extra = es_ann.extra

    return ann