def test_populate_bookautocomplete_from_isbns_values(): schema = load_schema('hep') document_type_schema = schema['properties']['document_type'] self_schema = schema['properties']['self'] isbns_schema = schema['properties']['isbns'] record = { '$schema': 'http://localhost:5000/records/schemas/hep.json', 'document_type': [ 'book', ], 'isbns': [ { 'value': '0201021153' }, ], 'self': { '$ref': 'http://localhost:5000/api/literature/1519486', }, } record = InspireRecord(record, model=RecordMetadata) assert validate(record['document_type'], document_type_schema) is None assert validate(record['isbns'], isbns_schema) is None assert validate(record['self'], self_schema) is None populate_bookautocomplete(record) expected = { 'input': [ '0201021153', ], } result = record['bookautocomplete'] assert expected == result
def test_populate_bookautocomplete_from_authors(): schema = load_schema('hep') authors_schema = schema['properties']['authors'] document_type_schema = schema['properties']['document_type'] self_schema = schema['properties']['self'] record = { '$schema': 'http://localhost:5000/records/schemas/hep.json', 'authors': [ { 'full_name': 'Rafelski, Johann' }, ], 'document_type': [ 'book', ], 'self': { '$ref': 'http://localhost:5000/api/literature/1519486', }, } record = InspireRecord(record, model=RecordMetadata) assert validate(record['authors'], authors_schema) is None assert validate(record['document_type'], document_type_schema) is None assert validate(record['self'], self_schema) is None populate_bookautocomplete(record) expected = { 'input': [ 'Rafelski, Johann', ], } result = record['bookautocomplete'] assert expected == result
def test_populate_bookautocomplete_from_isbns_values(): schema = load_schema('hep') document_type_schema = schema['properties']['document_type'] self_schema = schema['properties']['self'] isbns_schema = schema['properties']['isbns'] record = { '$schema': 'http://localhost:5000/records/schemas/hep.json', 'document_type': [ 'book', ], 'isbns': [ {'value': '0201021153'}, ], 'self': { '$ref': 'http://localhost:5000/api/literature/1519486', }, } record = InspireRecord(record, model=RecordMetadata) assert validate(record['document_type'], document_type_schema) is None assert validate(record['isbns'], isbns_schema) is None assert validate(record['self'], self_schema) is None populate_bookautocomplete(record) expected = { 'input': [ '0201021153', ], } result = record['bookautocomplete'] assert expected == result
def test_populate_bookautocomplete_from_authors(): schema = load_schema('hep') authors_schema = schema['properties']['authors'] document_type_schema = schema['properties']['document_type'] self_schema = schema['properties']['self'] record = { '$schema': 'http://localhost:5000/records/schemas/hep.json', 'authors': [ {'full_name': 'Rafelski, Johann'}, ], 'document_type': [ 'book', ], 'self': { '$ref': 'http://localhost:5000/api/literature/1519486', }, } record = InspireRecord(record, model=RecordMetadata) assert validate(record['authors'], authors_schema) is None assert validate(record['document_type'], document_type_schema) is None assert validate(record['self'], self_schema) is None populate_bookautocomplete(record) expected = { 'input': [ 'Rafelski, Johann', ], } result = record['bookautocomplete'] assert expected == result
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)