Exemplo n.º 1
0
def test_populate_recid_from_ref():
    json_dict = {
        'simple_key': {
            '$ref': 'http://x/y/1'
        },
        'key_with_record': {
            '$ref': 'http://x/y/2'
        },
        'record': {
            '$ref': 'http://x/y/3'
        },
        'embedded_list': [{
            'record': {
                '$ref': 'http://x/y/4'
            }
        }],
        'embedded_record': {
            'record': {
                '$ref': 'http://x/y/5'
            }
        }
    }
    record = InspireRecord(json_dict, model=RecordMetadata)

    populate_recid_from_ref(record)

    assert record['simple_key_recid'] == 1
    assert record['key_with_recid'] == 2
    assert record['recid'] == 3
    assert record['embedded_list'][0]['recid'] == 4
    assert record['embedded_record']['recid'] == 5
def test_populate_recid_from_ref_handles_deleted_records():
    json_dict = {
        'deleted_records': [
            {'$ref': 'http://x/y/1'},
            {'$ref': 'http://x/y/2'},
        ],
    }
    record = InspireRecord(json_dict, model=RecordMetadata)
    populate_recid_from_ref(record)

    assert record['deleted_recids'] == [1, 2]
Exemplo n.º 3
0
def test_populate_recid_from_ref():
    json_dict = {
        'simple_key': {'$ref': 'http://x/y/1'},
        'key_with_record': {'$ref': 'http://x/y/2'},
        'record': {'$ref': 'http://x/y/3'},
        'embedded_list': [{'record': {'$ref': 'http://x/y/4'}}],
        'embedded_record': {'record': {'$ref': 'http://x/y/5'}}
    }
    record = InspireRecord(json_dict, model=RecordMetadata)

    populate_recid_from_ref(record)

    assert record['simple_key_recid'] == 1
    assert record['key_with_recid'] == 2
    assert record['recid'] == 3
    assert record['embedded_list'][0]['recid'] == 4
    assert record['embedded_record']['recid'] == 5
Exemplo n.º 4
0
def enhance_before_index(record):
    """Run all the receivers that enhance the record for ES in the right order.

    .. note::

       ``populate_recid_from_ref`` **MUST** come before ``populate_bookautocomplete``
       because the latter puts a JSON reference in a completion _source, which
       would be expanded to an incorrect ``_source_recid`` by the former.

    """
    populate_recid_from_ref(record)

    if is_hep(record):
        populate_abstract_source_suggest(record)
        populate_earliest_date(record)
        populate_author_count(record)
        populate_authors_full_name_unicode_normalized(record)
        populate_inspire_document_type(record)
        populate_name_variations(record)
        populate_number_of_references(record)
        populate_citations_count(record)
        populate_facet_author_name(record)
        populate_ui_display(record, RecordMetadataSchemaV1)

        if is_book(record):
            populate_bookautocomplete(record)

    elif is_author(record):
        populate_authors_name_variations(record)
        populate_author_suggest(record)

    elif is_institution(record):
        populate_affiliation_suggest(record)

    elif is_experiment(record):
        populate_experiment_suggest(record)

    elif is_journal(record):
        populate_title_suggest(record)

    elif is_data(record):
        populate_citations_count(record)