예제 #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'],
    }
    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(None, record)

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

    result = record['title_suggest']

    assert expected == result
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'],
    }
    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(None, record)

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

    result = record['title_suggest']

    assert expected == result
예제 #3
0
def test_populate_title_suggest_without_full_title():
    schema = load_schema('journals')
    subschema_journal_title = schema['properties']['journal_title']
    subschema_short_title = schema['properties']['short_title']
    subschema_title_variants = schema['properties']['title_variants']

    record = {
        '$schema': 'http://localhost:5000/schemas/records/journals.json',
        'journal_title': {},
        'short_title': 'JHEP',
        'title_variants': ['JOURNAL OF HIGH ENERGY PHYSICS'],
    }
    assert validate(record['journal_title'], subschema_journal_title) is None
    assert validate(record['short_title'], subschema_short_title) is None
    assert validate(record['title_variants'], subschema_title_variants) is None

    populate_title_suggest(None, record)

    expected = {
        'input': ["JHEP", "JOURNAL OF HIGH ENERGY PHYSICS"],
        'output': 'JHEP',
        'payload': {
            'full_title': ''
        }
    }

    result = record['title_suggest']

    assert expected == result
예제 #4
0
def test_populate_title_suggest_without_title_variants():
    schema = load_schema('journals')
    subschema_journal_title = schema['properties']['journal_title']
    subschema_short_title = schema['properties']['short_title']
    subschema_title_variants = 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': [],
    }
    assert validate(record['journal_title'], subschema_journal_title) is None
    assert validate(record['short_title'], subschema_short_title) is None
    assert validate(record['title_variants'], subschema_title_variants) is None

    populate_title_suggest(None, record)

    expected = {
        'input': ['The Journal of High Energy Physics (JHEP)', 'JHEP'],
        'output': 'JHEP',
        'payload': {
            'full_title': 'The Journal of High Energy Physics (JHEP)'
        }
    }

    result = record['title_suggest']

    assert expected == result
예제 #5
0
def test_populate_title_suggest_does_nothing_if_record_is_not_journal():
    record = {'$schema': 'http://localhost:5000/schemas/records/other.json'}

    populate_title_suggest(None, record)

    assert 'title_suggest' not in record
def test_populate_title_suggest_does_nothing_if_record_is_not_journal():
    record = {'$schema': 'http://localhost:5000/schemas/records/other.json'}

    populate_title_suggest(None, record)

    assert 'title_suggest' not in record