def test_populate_bookautocomplete_does_nothing_if_record_is_not_a_book():
    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': 'Mohayai, Tanaz Angelina'},
        ],
        'document_type': [
            'article',
        ],
        'self': {
            '$ref': 'http://localhost:5000/api/literature/1520027',
        }
    }
    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(None, record)

    assert 'bookautocomplete' not in record
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',
        },
    }
    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(None, 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',
        },
    }
    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(None, record)

    expected = {
        'input': [
            '0201021153',
        ],
    }
    result = record['bookautocomplete']

    assert expected == result
def test_populate_bookautocomplete_from_titles():
    schema = load_schema('hep')
    document_type_schema = schema['properties']['document_type']
    self_schema = schema['properties']['self']
    titles_schema = schema['properties']['titles']

    record = {
        '$schema': 'http://localhost:5000/records/schemas/hep.json',
        'document_type': [
            'book',
        ],
        'self': {
            '$ref': 'http://localhost:5000/api/literature/1519486',
        },
        'titles': [
            {'title': 'Relativity Matters'},
        ],
    }
    assert validate(record['document_type'], document_type_schema) is None
    assert validate(record['self'], self_schema) is None
    assert validate(record['titles'], titles_schema) is None

    populate_bookautocomplete(None, record)

    expected = {
        'input': [
            'Relativity Matters',
        ],
    }
    result = record['bookautocomplete']

    assert expected == result
def test_populate_bookautocomplete_does_nothing_if_record_is_not_a_book():
    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': 'Mohayai, Tanaz Angelina'},
        ],
        'document_type': [
            'article',
        ],
        'self': {
            '$ref': 'http://localhost:5000/api/literature/1520027',
        }
    }
    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(None, record)

    assert 'bookautocomplete' not in record
def test_populate_bookautocomplete_from_titles():
    schema = load_schema('hep')
    document_type_schema = schema['properties']['document_type']
    self_schema = schema['properties']['self']
    titles_schema = schema['properties']['titles']

    record = {
        '$schema': 'http://localhost:5000/records/schemas/hep.json',
        'document_type': [
            'book',
        ],
        'self': {
            '$ref': 'http://localhost:5000/api/literature/1519486',
        },
        'titles': [
            {'title': 'Relativity Matters'},
        ],
    }
    assert validate(record['document_type'], document_type_schema) is None
    assert validate(record['self'], self_schema) is None
    assert validate(record['titles'], titles_schema) is None

    populate_bookautocomplete(None, record)

    expected = {
        'input': [
            'Relativity Matters',
        ],
        'payload': {
            'authors': [],
            'id': 'http://localhost:5000/api/literature/1519486',
            'title': [
                'Relativity Matters',
            ],
        },
    }
    result = record['bookautocomplete']

    assert expected == result
Exemple #7
0
def test_populate_bookautocomplete_from_imprints_publishers():
    schema = load_schema('hep')
    document_type_schema = schema['properties']['document_type']
    self_schema = schema['properties']['self']
    imprints_schema = schema['properties']['imprints']

    record = {
        '$schema': 'http://localhost:5000/records/schemas/hep.json',
        'document_type': [
            'book',
        ],
        'imprints': [
            {'publisher': 'Springer'},
        ],
        'self': {
            '$ref': 'http://localhost:5000/api/literature/1519486',
        },
    }
    assert validate(record['document_type'], document_type_schema) is None
    assert validate(record['imprints'], imprints_schema) is None
    assert validate(record['self'], self_schema) is None

    populate_bookautocomplete(None, record)

    expected = {
        'input': [
            'Springer',
        ],
        'payload': {
            'authors': [],
            'id': 'http://localhost:5000/api/literature/1519486',
            'title': [],
        },
    }
    result = record['bookautocomplete']

    assert expected == result
def test_populate_bookautocomplete_does_nothing_if_record_is_not_literature():
    record = {'$schema': 'http://localhost:5000/schemas/records/other.json'}

    populate_bookautocomplete(None, record)

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

    populate_bookautocomplete(None, record)

    assert 'bookautocomplete' not in record