def session(self, db_session, added_ann_id, changed_ann_id, deleted_ann_id): # Populate the DB session with different types of change relative to the # last-committed state. We could use any model object for this purpose # but annotations are the primary object in the system. doc = Document(web_uri="https://example.org") changed = Annotation(id=changed_ann_id, userid="foo", groupid="wibble", document=doc) deleted = Annotation(id=deleted_ann_id, userid="foo", groupid="wibble", document=doc) db_session.add(changed) db_session.add(deleted) db_session.commit() changed.text = "changed text" db_session.delete(deleted) added = Annotation(id=added_ann_id, userid="foo", groupid="wibble", document=doc) db_session.add(added) return db_session
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
def meta_attrs(self): return { "claimant": "http://example.com/claimant", "type": "title", "value": "the title", "document": Document(), "created": datetime.now() - timedelta(days=1), "updated": datetime.now(), }
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
def test_it_denormalizes_title_to_document_when_falsy( self, db_session, meta_attrs, doc_title, final_title ): meta_attrs["value"] = ["attr_title"] meta_attrs["document"] = document = Document(title=doc_title) db_session.add(document) create_or_update_document_meta(session=db_session, **meta_attrs) document = db_session.query(Document).get(document.id) assert document.title == final_title
def group_with_two_users(db_session, factories): """ Create a group with two members and an annotation created by each. """ creator = factories.User() member = factories.User() group = Group(authority=creator.authority, creator=creator, members=[creator, member], name='test', pubid='group_with_two_users') db_session.add(group) doc = Document(web_uri='https://example.org') creator_ann = Annotation(userid=creator.userid, groupid=group.pubid, document=doc) member_ann = Annotation(userid=member.userid, groupid=group.pubid, document=doc) db_session.add(creator_ann) db_session.add(member_ann) db_session.flush() return (group, creator, member, creator_ann, member_ann)
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"
def document(self, db_session): doc = Document(title="My fascinating page") db_session.add(doc) db_session.flush() return doc