Exemple #1
0
    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)
Exemple #2
0
    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
Exemple #3
0
    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)
Exemple #4
0
    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
Exemple #5
0
    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
Exemple #6
0
    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
Exemple #7
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
Exemple #8
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
Exemple #9
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
Exemple #10
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
Exemple #11
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()
Exemple #12
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()
Exemple #13
0
    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
Exemple #14
0
    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