Пример #1
0
def test_populate_title_suggest_with_all_inputs():
    schema = load_schema('journals')
    journal_title_schema = schema['properties']['journal_title']
    short_title_schema = schema['properties']['short_title']
    title_variants_schema = schema['properties']['title_variants']

    record = {
        '$schema': 'http://localhost:5000/schemas/records/journals.json',
        'journal_title': {
            'title': 'The Journal of High Energy Physics (JHEP)'
        },
        'short_title': 'JHEP',
        'title_variants': ['JOURNAL OF HIGH ENERGY PHYSICS'],
    }
    record = InspireRecord(record, model=RecordMetadata)
    assert validate(record['journal_title'], journal_title_schema) is None
    assert validate(record['short_title'], short_title_schema) is None
    assert validate(record['title_variants'], title_variants_schema) is None

    populate_title_suggest(record)

    expected = {
        'input': [
            'The Journal of High Energy Physics (JHEP)', 'JHEP',
            'JOURNAL OF HIGH ENERGY PHYSICS'
        ],
    }

    result = record['title_suggest']

    assert expected == result
Пример #2
0
def test_populate_title_suggest_with_all_inputs():
    schema = load_schema('journals')
    journal_title_schema = schema['properties']['journal_title']
    short_title_schema = schema['properties']['short_title']
    title_variants_schema = schema['properties']['title_variants']

    record = {
        '$schema': 'http://localhost:5000/schemas/records/journals.json',
        'journal_title': {'title': 'The Journal of High Energy Physics (JHEP)'},
        'short_title': 'JHEP',
        'title_variants': ['JOURNAL OF HIGH ENERGY PHYSICS'],
    }
    record = InspireRecord(record, model=RecordMetadata)
    assert validate(record['journal_title'], journal_title_schema) is None
    assert validate(record['short_title'], short_title_schema) is None
    assert validate(record['title_variants'], title_variants_schema) is None

    populate_title_suggest(record)

    expected = {
        'input': [
            'The Journal of High Energy Physics (JHEP)',
            'JHEP',
            'JOURNAL OF HIGH ENERGY PHYSICS'
        ],
    }

    result = record['title_suggest']

    assert expected == result
Пример #3
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)