Пример #1
0
def test_update_links_handles_lists():
    config = {
        'INSPIRE_REF_UPDATER_WHITELISTS': {
            'literature': [
                'foos.record',
            ],
        },
    }

    with patch.dict(current_app.config, config):
        record = {
            '$schema': 'http://localhost:5000/schemas/record/hep.json',
            'foos': [
                {'record': {'$ref': 'http://localhost:5000/record/1'}},
                {'record': {'$ref': 'http://localhost:5000/record/2'}},
            ],
        }

        update_links(record, 'http://localhost:5000/record/1', 'http://localhost:5000/record/2')

        assert record == {
            '$schema': 'http://localhost:5000/schemas/record/hep.json',
            'foos': [
                {'record': {'$ref': 'http://localhost:5000/record/2'}},
                {'record': {'$ref': 'http://localhost:5000/record/2'}},
            ],
        }
Пример #2
0
def test_update_links_ignores_non_whitelisted_paths():
    config = {
        'INSPIRE_REF_UPDATER_WHITELISTS': {
            'literature': [
                'foo.record',
            ],
        },
    }

    with patch.dict(current_app.config, config):
        record = {
            '$schema': 'http://localhost:5000/schemas/record/hep.json',
            'foo': {
                'record': {'$ref': 'http://localhost:5000/record/1'},
            },
            'bar': {
                'record': {'$ref': 'http://localhost:5000/record/1'},
            }
        }

        update_links(record, 'http://localhost:5000/record/1', 'http://localhost:5000/record/2')

        assert record == {
            '$schema': 'http://localhost:5000/schemas/record/hep.json',
            'foo': {
                'record': {'$ref': 'http://localhost:5000/record/2'},
            },
            'bar': {
                'record': {'$ref': 'http://localhost:5000/record/1'},
            }
        }