Example #1
0
    def test_merge_documents_deletes_duplicate_documents(self, merge_data):
        _, duplicate = merge_data

        document.merge_documents(db.Session, merge_data)
        db.Session.flush()

        assert document.Document.query.get(duplicate.id) is None
Example #2
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)
Example #3
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
Example #4
0
def test_merge_documents_deletes_duplicate_documents(merge_data):
    master, duplicate = merge_data

    merge_documents(db.Session, merge_data)
    db.Session.flush()

    assert Document.query.get(duplicate.id) is None
Example #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
Example #6
0
def test_merge_documents_rewires_document_meta(merge_data):
    master, duplicate = merge_data

    merge_documents(db.Session, merge_data)
    db.Session.flush()

    assert len(master.meta) == 2
    assert len(duplicate.meta) == 0
Example #7
0
def test_merge_documents_rewires_document_uris(merge_data):
    master, duplicate = merge_data

    merge_documents(db.Session, merge_data)
    db.Session.flush()

    assert len(master.document_uris) == 2
    assert len(duplicate.document_uris) == 0
Example #8
0
    def test_merge_documents_rewires_document_uris(self, merge_data):
        master, duplicate = merge_data

        document.merge_documents(db.Session, merge_data)
        db.Session.flush()

        assert len(master.document_uris) == 2
        assert len(duplicate.document_uris) == 0
Example #9
0
def create_or_update_document_objects(es_ann):
    es_doc = es_ann.document

    if not es_doc:
        return

    uris = [u.uri for u in es_doc.document_uris]
    documents = Document.find_or_create_by_uris(Session,
                                                es_ann.target_uri,
                                                uris,
                                                created=es_doc.created,
                                                updated=es_doc.updated)

    if documents.count() > 1:
        document = merge_documents(Session, documents, updated=es_doc.updated)
    else:
        document = documents.first()

    document.updated = es_doc.updated

    for uri_ in es_doc.document_uris:
        create_or_update_document_uri(uri_, document)

    for meta in es_doc.meta:
        create_or_update_document_meta(meta, document)
Example #10
0
File: migrate.py Project: hashin/h
def create_or_update_document_objects(es_ann):
    es_doc = es_ann.document

    if not es_doc:
        return

    uris = [u.uri for u in es_doc.document_uris]
    documents = Document.find_or_create_by_uris(Session, es_ann.target_uri, uris,
                                                created=es_doc.created,
                                                updated=es_doc.updated)

    if documents.count() > 1:
        document = merge_documents(Session, documents, updated=es_doc.updated)
    else:
        document = documents.first()

    document.updated = es_doc.updated

    for uri_ in es_doc.document_uris:
        create_or_update_document_uri(uri_, document)

    for meta in es_doc.meta:
        create_or_update_document_meta(meta, document)
Example #11
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
Example #12
0
def test_merge_documents_returns_master(merge_data):
    master, duplicate = merge_data

    merged_master = merge_documents(db.Session, merge_data)
    assert merged_master == master
Example #13
0
    def test_merge_documents_returns_master(self, merge_data):
        master, _ = merge_data

        merged_master = document.merge_documents(db.Session, merge_data)

        assert merged_master == master