Ejemplo n.º 1
0
def test_get_endpoint_from_record_supports_relative_urls():
    expected = 'authors'
    record = {
        '$schema': 'schemas/records/authors.json'
    }
    result = get_endpoint_from_record(record)

    assert expected == result
Ejemplo n.º 2
0
def test_get_endpoint_from_record():
    expected = 'literature'
    record = {
        '$schema': 'http://localhost:5000/schemas/records/hep.json'
    }
    result = get_endpoint_from_record(record)

    assert expected == result
Ejemplo n.º 3
0
def update_links(record, old_ref, new_ref):
    def _update_links(record, parts, old_ref, new_ref):
        for i, part in enumerate(parts):
            if isinstance(record, dict):
                try:
                    record = record[part]
                except KeyError:
                    return
            elif isinstance(record, list):
                for el in record:
                    _update_links(el, parts[i:], old_ref, new_ref)
                return

        if record['$ref'] == old_ref:
            record['$ref'] = new_ref

    endpoint = get_endpoint_from_record(record)
    whitelist = current_app.config['INSPIRE_REF_UPDATER_WHITELISTS'][endpoint]

    for path in whitelist:
        _update_links(record, path.split('.'), old_ref, new_ref)
Ejemplo n.º 4
0
def update_links(record, old_ref, new_ref):
    def _update_links(record, parts, old_ref, new_ref):
        for i, part in enumerate(parts):
            if isinstance(record, dict):
                try:
                    record = record[part]
                except KeyError:
                    return
            elif isinstance(record, list):
                for el in record:
                    _update_links(el, parts[i:], old_ref, new_ref)
                return

        if record['$ref'] == old_ref:
            record['$ref'] = new_ref

    endpoint = get_endpoint_from_record(record)
    whitelist = current_app.config['INSPIRE_REF_UPDATER_WHITELISTS'][endpoint]

    for path in whitelist:
        _update_links(record, path.split('.'), old_ref, new_ref)
Ejemplo n.º 5
0
def preview():
    """Preview the record being edited."""
    record = request.get_json()
    endpoint = get_endpoint_from_record(record)
    template = current_app.config['RECORDS_UI_ENDPOINTS'][endpoint]['template']
    return render_template(template, record=record)
Ejemplo n.º 6
0
def preview():
    """Preview the record being edited."""
    record = request.get_json()
    endpoint = get_endpoint_from_record(record)
    template = current_app.config['RECORDS_UI_ENDPOINTS'][endpoint]['template']
    return render_template(template, record=record)