def test_raises_retryable_error_when_flush_fails(self, db_session, merge_data, monkeypatch): def err(): raise sa.exc.IntegrityError(None, None, None) monkeypatch.setattr(db_session, 'flush', err) with pytest.raises(transaction.interfaces.TransientError): document.merge_documents(db_session, merge_data)
def test_merge_documents_deletes_duplicate_documents(self, db_session, merge_data): _, duplicate = merge_data document.merge_documents(db_session, merge_data) db_session.flush() assert db_session.query(document.Document).get(duplicate.id) is None
def test_merge_documents_rewires_document_meta(self, db_session, merge_data): master, duplicate = merge_data document.merge_documents(db_session, merge_data) db_session.flush() assert len(master.meta) == 2 assert len(duplicate.meta) == 0
def test_merge_documents_rewires_document_uris(self, db_session, merge_data): master, duplicate_1, duplicate_2 = merge_data document.merge_documents(db_session, merge_data) db_session.flush() assert len(master.document_uris) == 3 assert len(duplicate_1.document_uris) == 0 assert len(duplicate_2.document_uris) == 0
def test_merge_documents_deletes_duplicate_documents(self, db_session, merge_data): _, duplicate_1, duplicate_2 = merge_data document.merge_documents(db_session, merge_data) db_session.flush() count = db_session.query(document.Document) \ .filter(document.Document.id.in_([duplicate_1.id, duplicate_2.id])) \ .count() assert count == 0
def test_merge_documents_rewires_annotations(self, db_session, merge_data): master, duplicate_1, duplicate_2 = merge_data document.merge_documents(db_session, merge_data) db_session.flush() assert 6 == \ db_session.query(models.Annotation).filter_by(document_id=master.id).count() assert 0 == \ db_session.query(models.Annotation).filter_by(document_id=duplicate_1.id).count() assert 0 == \ db_session.query(models.Annotation).filter_by(document_id=duplicate_2.id).count()
def test_merge_documents_returns_master(self, db_session, merge_data): master, _ = merge_data merged_master = document.merge_documents(db_session, merge_data) assert merged_master == master
def test_merge_documents_returns_master(self, db_session, merge_data): master, _, _ = merge_data merged_master = document.merge_documents(db_session, merge_data) assert merged_master == master