Ejemplo n.º 1
0
    def test_repr(self):
        meta = DocumentMeta(id=1234)

        repr_string = repr(meta)

        assert "DocumentMet" in repr_string
        assert "1234" in repr_string
Ejemplo n.º 2
0
 def document(self, storage_driver):
     title = 'My fascinating page'
     if storage_driver == 'elastic':
         return elastic.Document(title=[title])
     else:
         doc = Document()
         doc.meta.append(DocumentMeta(type='title', value=[title]))
         return doc
Ejemplo n.º 3
0
 def document(self, db_session):
     doc = Document()
     doc.meta.append(
         DocumentMeta(type='title',
                      value=['My fascinating page'],
                      claimant='http://example.org'))
     db_session.add(doc)
     db_session.flush()
     return doc
Ejemplo n.º 4
0
    def test_it_creates_a_new_DocumentMeta_if_there_is_no_existing_one(
        self, db_session, meta_attrs
    ):
        # Add one non-matching DocumentMeta to the database to be ignored.
        db_session.add(DocumentMeta(**dict(meta_attrs, type="noise")))

        create_or_update_document_meta(session=db_session, **meta_attrs)

        document_meta = db_session.query(DocumentMeta).all()[-1]
        assert document_meta == Any.object.with_attrs(meta_attrs)
Ejemplo n.º 5
0
 def reply(self, annotations, parent):
     # We need to create a document object to provide the title, and
     # ensure it is associated with the annotation through the
     # annotation's `target_uri`
     doc = Document.find_or_create_by_uris(db.Session,
                                           claimant_uri='http://example.net/foo',
                                           uris=[]).one()
     doc.meta.append(DocumentMeta(type='title',
                                  value=['Some document'],
                                  claimant='http://example.com/foo'))
     reply = Annotation(**FIXTURE_DATA['reply'])
     reply.target_uri = 'http://example.net/foo'
     reply.references = [parent.id]
     db.Session.add(reply)
     db.Session.flush()
     annotations[reply.id] = reply
     return reply
Ejemplo n.º 6
0
    def test_it_updates_an_existing_DocumentMeta_if_there_is_one(
        self, db_session, meta_attrs, correct_document
    ):
        original_attrs = meta_attrs
        updated_attrs = dict(
            original_attrs,
            value="new value",
            # This should be ignored either way.
            document=meta_attrs["document"] if correct_document else Document(),
            created=datetime.now(),  # This should be ignored.
            updated=datetime.now(),
        )
        document_meta = DocumentMeta(**original_attrs)
        db_session.add(document_meta)

        create_or_update_document_meta(session=db_session, **updated_attrs)

        assert document_meta.value == updated_attrs["value"]
        assert document_meta.updated == updated_attrs["updated"]
        assert document_meta.created == original_attrs["created"]
        assert document_meta.document == original_attrs["document"]
        assert (
            len(db_session.query(DocumentMeta).all()) == 1
        ), "It shouldn't have added any new objects to the db"