Пример #1
0
def deleted_record(app):
    snippet = (
        '<record>'
        '  <controlfield tag="001">111</controlfield>'
        '  <datafield tag="245" ind1=" " ind2=" ">'
        '    <subfield code="a">deleted</subfield>'
        '  </datafield>'
        '  <datafield tag="980" ind1=" " ind2=" ">'
        '    <subfield code="c">DELETED</subfield>'
        '  </datafield>'
        '</record>'
    )

    with app.app_context():
        record = hep.do(create_record(snippet))
        record['$schema'] = 'http://localhost:5000/schemas/records/hep.json'

        with db.session.begin_nested():
            record_upsert(record)
        db.session.commit()

    yield

    with app.app_context():
        _delete_record('lit', 111)
Пример #2
0
def not_yet_merged_records(app):
    merged_record = {
        '$schema': 'http://localhost:5000/schemas/records/hep.json',
        'control_number': 111,
        'self': {
            '$ref': 'http://localhost:5000/api/literature/111',
        },
    }

    deleted_record = {
        '$schema': 'http://localhost:5000/schemas/records/hep.json',
        'control_number': 222,
        'self': {
            '$ref': 'http://localhost:5000/api/literature/222',
        },
    }

    with app.app_context():
        with db.session.begin_nested():
            merged_uuid = record_upsert(merged_record).id
            deleted_uuid = record_upsert(deleted_record).id
        db.session.commit()

    yield

    with app.app_context():
        _delete_merged_records('lit', 111, 222, merged_uuid, deleted_uuid)
Пример #3
0
def record_not_yet_deleted(app):
    snippet = (
        '<record>'
        '  <controlfield tag="001">333</controlfield>'
        '  <controlfield tag="005">20160913214552.0</controlfield>'
        '  <datafield tag="980" ind1=" " ind2=" ">'
        '    <subfield code="a">HEP</subfield>'
        '  </datafield>'
        '</record>'
    )

    with app.app_context():
        json_record = hep.do(create_record(snippet))
        json_record['$schema'] = 'http://localhost:5000/schemas/records/hep.json'

        with db.session.begin_nested():
            record = record_upsert(json_record)
            if record:
                ri = RecordIndexer()
                ri.index(record)

        db.session.commit()

    yield

    with app.app_context():
        _delete_record_from_everywhere('literature', 333)
Пример #4
0
def records_to_be_merged(app):
    merged_record = {
        '$schema': 'http://localhost:5000/schemas/records/hep.json',
        'control_number': 111,
        'self': {
            '$ref': 'http://localhost:5000/api/literature/111',
        },
    }

    deleted_record = {
        '$schema': 'http://localhost:5000/schemas/records/hep.json',
        'control_number': 222,
        'self': {
            '$ref': 'http://localhost:5000/api/literature/222',
        },
    }

    pointing_record = {
        '$schema':
        'http://localhost:5000/schemas/records/hep.json',
        'accelerator_experiments': [
            {
                'record': {
                    '$ref': 'http://localhost:5000/api/literature/222',
                },
            },
        ],
        'control_number':
        333,
        'self': {
            '$ref': 'http://localhost:5000/api/literature/333',
        },
    }

    with app.app_context():
        with db.session.begin_nested():
            merged_uuid = record_upsert(merged_record).id
            deleted_uuid = record_upsert(deleted_record).id
            record_upsert(pointing_record)
        db.session.commit()
    es.indices.refresh('records-hep')

    yield

    with app.app_context():
        _delete_merged_records('lit', 111, 222, merged_uuid, deleted_uuid)
        _delete_record('lit', 333)
Пример #5
0
def not_yet_deleted_record(app):
    record = {
        '$schema': 'http://localhost:5000/schemas/records/hep.json',
        'control_number': 111,
        'self': {
            '$ref': 'http://localhost:5000/schemas/records/hep.json',
        }
    }

    with app.app_context():
        with db.session.begin_nested():
            record_upsert(record)
        db.session.commit()

    yield

    with app.app_context():
        _delete_record('lit', 111)
Пример #6
0
def merged_records(app):
    merged_snippet = (
        '<record>'
        '  <controlfield tag="001">111</controlfield>'
        '  <datafield tag="245" ind1=" " ind2=" ">'
        '    <subfield code="a">merged</subfield>'
        '  </datafield>'
        '  <datafield tag="981" ind1=" " ind2=" ">'
        '    <subfield code="a">222</subfield>'
        '  </datafield>'
        '</record>'
    )

    deleted_snippet = (
        '<record>'
        '  <controlfield tag="001">222</controlfield>'
        '  <datafield tag="245" ind1=" " ind2=" ">'
        '    <subfield code="a">deleted</subfield>'
        '  </datafield>'
        '  <datafield tag="970" ind1=" " ind2=" ">'
        '    <subfield code="d">111</subfield>'
        '  </datafield>'
        '  <datafield tag="980" ind1=" " ind2=" ">'
        '    <subfield code="c">DELETED</subfield>'
        '  </datafield>'
        '</record>'
    )

    with app.app_context():
        merged_record = hep.do(create_record(merged_snippet))
        merged_record['$schema'] = 'http://localhost:5000/schemas/records/hep.json'

        deleted_record = hep.do(create_record(deleted_snippet))
        deleted_record['$schema'] = 'http://localhost:5000/schemas/records/hep.json'

        with db.session.begin_nested():
            merged_uuid = record_upsert(merged_record).id
            deleted_uuid = record_upsert(deleted_record).id
        db.session.commit()

    yield

    with app.app_context():
        _delete_merged_records('lit', 111, 222, merged_uuid, deleted_uuid)
Пример #7
0
def deleted_record(app):
    snippet = ('<record>'
               '  <controlfield tag="001">111</controlfield>'
               '  <datafield tag="980" ind1=" " ind2=" ">'
               '    <subfield code="c">DELETED</subfield>'
               '  </datafield>'
               '</record>')

    with app.app_context():
        record = hep.do(create_record(snippet))
        record['$schema'] = 'http://localhost:5000/schemas/records/hep.json'

        with db.session.begin_nested():
            record_upsert(record)
        db.session.commit()

    yield

    with app.app_context():
        _delete_record('lit', 111)
Пример #8
0
def not_yet_merged_records(app):
    merged_record = {
        '$schema': 'http://localhost:5000/schemas/records/hep.json',
        'control_number': 111,
        'document_type': [
            'article',
        ],
        'titles': [
            {'title': 'merged'},
        ],
        'self': {
            '$ref': 'http://localhost:5000/api/literature/111',
        },
    }

    deleted_record = {
        '$schema': 'http://localhost:5000/schemas/records/hep.json',
        'control_number': 222,
        'document_type': [
            'article',
        ],
        'titles': [
            {'title': 'deleted'},
        ],
        'self': {
            '$ref': 'http://localhost:5000/api/literature/222',
        },
    }

    with app.app_context():
        with db.session.begin_nested():
            merged_uuid = record_upsert(merged_record).id
            deleted_uuid = record_upsert(deleted_record).id
        db.session.commit()

    yield

    with app.app_context():
        _delete_merged_records('lit', 111, 222, merged_uuid, deleted_uuid)
Пример #9
0
def merged_records(app):
    merged_snippet = ('<record>'
                      '  <controlfield tag="001">111</controlfield>'
                      '  <datafield tag="981" ind1=" " ind2=" ">'
                      '    <subfield code="a">222</subfield>'
                      '  </datafield>'
                      '</record>')

    deleted_snippet = ('<record>'
                       '  <controlfield tag="001">222</controlfield>'
                       '  <datafield tag="970" ind1=" " ind2=" ">'
                       '    <subfield code="d">111</subfield>'
                       '  </datafield>'
                       '  <datafield tag="980" ind1=" " ind2=" ">'
                       '    <subfield code="c">DELETED</subfield>'
                       '  </datafield>'
                       '</record>')

    with app.app_context():
        merged_record = hep.do(create_record(merged_snippet))
        merged_record[
            '$schema'] = 'http://localhost:5000/schemas/records/hep.json'

        deleted_record = hep.do(create_record(deleted_snippet))
        deleted_record[
            '$schema'] = 'http://localhost:5000/schemas/records/hep.json'

        with db.session.begin_nested():
            merged_uuid = record_upsert(merged_record).id
            deleted_uuid = record_upsert(deleted_record).id
        db.session.commit()

    yield

    with app.app_context():
        _delete_merged_records('lit', 111, 222, merged_uuid, deleted_uuid)
Пример #10
0
def not_yet_deleted_record(app):
    record = {
        '$schema': 'http://localhost:5000/schemas/records/hep.json',
        'control_number': 111,
        'document_type': [
            'article',
        ],
        'titles': [
            {'title': 'deleted'},
        ],
        'self': {
            '$ref': 'http://localhost:5000/schemas/records/hep.json',
        }
    }

    with app.app_context():
        with db.session.begin_nested():
            record_upsert(record)
        db.session.commit()

    yield

    with app.app_context():
        _delete_record('lit', 111)
Пример #11
0
def records_not_merged_in_marcxml(app):
    snippet_merged = (
        '<record>'
        '  <controlfield tag="001">111</controlfield>'
        '  <controlfield tag="005">20160922232729.0</controlfield>'
        '  <datafield tag="024" ind1="7" ind2=" ">'
        '    <subfield code="2">DOI</subfield>'
        '    <subfield code="a">10.11588/heidok.00021652</subfield>'
        '  </datafield>'
        '  <datafield tag="100" ind1=" " ind2=" ">'
        '    <subfield code="a">Humbert, Pascal</subfield>'
        '    <subfield code="u">Inst. Appl. Math., Heidelberg</subfield>'
        '  </datafield>'
        '  <datafield tag="980" ind1=" " ind2=" ">'
        '    <subfield code="a">HEP</subfield>'
        '  </datafield>'
        '  <datafield tag="980" ind1=" " ind2=" ">'
        '    <subfield code="a">THESIS</subfield>'
        '  </datafield>'
        '  <datafield tag="980" ind1=" " ind2=" ">'
        '    <subfield code="a">CORE</subfield>'
        '  </datafield>'
        '  <datafield tag="981" ind1=" " ind2=" ">'
        '    <subfield code="a">222</subfield>'
        '  </datafield>'
        '</record>'
    )

    snippet_deleted = (
        '<record>'
        '  <controlfield tag="001">222</controlfield>'
        '  <controlfield tag="005">20160922232729.0</controlfield>'
        '  <datafield tag="024" ind1="7" ind2=" ">'
        '    <subfield code="2">DOI</subfield>'
        '    <subfield code="a">10.11588/heidok.00021652</subfield>'
        '  </datafield>'
        '  <datafield tag="100" ind1=" " ind2=" ">'
        '    <subfield code="a">Humbert, Pascal</subfield>'
        '    <subfield code="u">Inst. Appl. Math., Heidelberg</subfield>'
        '  </datafield>'
        '  <datafield tag="701" ind1=" " ind2=" ">'
        '    <subfield code="a">Lindner, Manfred</subfield>'
        '  </datafield>'
        '  <datafield tag="856" ind1="4" ind2=" ">'
        '    <subfield code="u">http://www.ub.uni-heidelberg.de/archiv/21652</subfield>'
        '    <subfield code="y">U. Heidelberg</subfield>'
        '  </datafield>'
        '  <datafield tag="909" ind1="C" ind2="O">'
        '    <subfield code="o">oai:inspirehep.net:222</subfield>'
        '    <subfield code="p">INSPIRE:HEP</subfield>'
        '  </datafield>'
        '  <datafield tag="980" ind1=" " ind2=" ">'
        '    <subfield code="a">HEP</subfield>'
        '  </datafield>'
        '  <datafield tag="981" ind1=" " ind2=" ">'
        '    <subfield code="a">222</subfield>'
        '  </datafield>'
        '</record>'
    )

    with app.app_context():
        json_record_merged = hep.do(create_record(snippet_merged))
        json_record_merged['$schema'] = 'http://localhost:5000/schemas/records/hep.json'

        json_record_deleted = hep.do(create_record(snippet_deleted))
        json_record_deleted['$schema'] = 'http://localhost:5000/schemas/records/hep.json'

        with db.session.begin_nested():
            record_merged = record_upsert(json_record_merged)
            record_deleted = record_upsert(json_record_deleted)
            if record_deleted:
                if record_merged:
                    r = RecordIndexer()
                    r.index(record_merged)
                    r.index(record_deleted)
                    es.indices.refresh('records-hep')
        db.session.commit()

    yield

    with app.app_context():
        _delete_merged_records_from_everywhere('literature', 111, 222)
Пример #12
0
def records_already_merged_in_marcxml(app):
    snippet_merged = (
        '<record>'
        '  <controlfield tag="001">111</controlfield>'
        '  <controlfield tag="005">20160922232729.0</controlfield>'
        '  <datafield tag="024" ind1="7" ind2=" ">'
        '    <subfield code="2">DOI</subfield>'
        '    <subfield code="a">10.11588/heidok.00021652</subfield>'
        '  </datafield>'
        '  <datafield tag="100" ind1=" " ind2=" ">'
        '    <subfield code="a">Humbert, Pascal</subfield>'
        '    <subfield code="u">Inst. Appl. Math., Heidelberg</subfield>'
        '  </datafield>'
        '  <datafield tag="980" ind1=" " ind2=" ">'
        '    <subfield code="a">HEP</subfield>'
        '  </datafield>'
        '  <datafield tag="980" ind1=" " ind2=" ">'
        '    <subfield code="a">THESIS</subfield>'
        '  </datafield>'
        '  <datafield tag="980" ind1=" " ind2=" ">'
        '    <subfield code="a">CORE</subfield>'
        '  </datafield>'
        '  <datafield tag="981" ind1=" " ind2=" ">'
        '    <subfield code="a">222</subfield>'
        '  </datafield>'
        '</record>'
    )

    snippet_deleted = (
        '<record>'
        '  <controlfield tag="001">222</controlfield>'
        '  <controlfield tag="005">20160914115512.0</controlfield>'
        '  <datafield tag="100" ind1=" " ind2=" ">'
        '    <subfield code="a">Humbert, Pascal</subfield>'
        '  </datafield>'
        '  <datafield tag="970" ind1=" " ind2=" ">'
        '    <subfield code="d">111</subfield>'
        '  </datafield>'
        '  <datafield tag="980" ind1=" " ind2=" ">'
        '    <subfield code="a">HEP</subfield>'
        '  </datafield>'
        '  <datafield tag="980" ind1=" " ind2=" ">'
        '    <subfield code="a">THESIS</subfield>'
        '  </datafield>'
        '  <datafield tag="980" ind1=" " ind2=" ">'
        '    <subfield code="a">CORE</subfield>'
        '  </datafield>'
        '  <datafield tag="980" ind1=" " ind2=" ">'
        '    <subfield code="c">DELETED</subfield>'
        '  </datafield>'
        '</record>'
    )

    with app.app_context():
        json_record_merged = hep.do(create_record(snippet_merged))
        json_record_merged['$schema'] = 'http://localhost:5000/schemas/records/hep.json'

        json_record_deleted = hep.do(create_record(snippet_deleted))
        json_record_deleted['$schema'] = 'http://localhost:5000/schemas/records/hep.json'

        with db.session.begin_nested():
            record_merged = record_upsert(json_record_merged)
            record_deleted = record_upsert(json_record_deleted)
            if record_deleted:
                if record_merged:
                    r = RecordIndexer()
                    r.index(record_merged)
                    r.index(record_deleted)
                    es.indices.refresh('records-hep')
        db.session.commit()

    yield

    with app.app_context():
        _delete_merged_records_from_everywhere('literature', 111, 222)
Пример #13
0
def records_to_be_merged(app):
    merged_record = {
        '$schema': 'http://localhost:5000/schemas/records/hep.json',
        'control_number': 111,
        'document_type': [
            'article',
        ],
        'titles': [
            {'title': 'merged'},
        ],
        'self': {
            '$ref': 'http://localhost:5000/api/literature/111',
        },
    }

    deleted_record = {
        '$schema': 'http://localhost:5000/schemas/records/hep.json',
        'control_number': 222,
        'document_type': [
            'article',
        ],
        'titles': [
            {'title': 'deleted'},
        ],
        'self': {
            '$ref': 'http://localhost:5000/api/literature/222',
        },
    }

    pointing_record = {
        '$schema': 'http://localhost:5000/schemas/records/hep.json',
        'accelerator_experiments': [
            {
                'record': {
                    '$ref': 'http://localhost:5000/api/literature/222',
                },
            },
        ],
        'control_number': 333,
        'document_type': [
            'article',
        ],
        'titles': [
            {'title': 'pointing'},
        ],
        'self': {
            '$ref': 'http://localhost:5000/api/literature/333',
        },
    }

    with app.app_context():
        with db.session.begin_nested():
            merged_uuid = record_upsert(merged_record).id
            deleted_uuid = record_upsert(deleted_record).id
            record_upsert(pointing_record)
        db.session.commit()
    es.indices.refresh('records-hep')

    yield

    with app.app_context():
        _delete_merged_records('lit', 111, 222, merged_uuid, deleted_uuid)
        _delete_record('lit', 333)