예제 #1
0
def test_check_format(headers):
    args = {'f': 'html'}

    headers_ = headers.copy()

    assert check_format({}, headers_) is None

    assert check_format(args, headers_) == 'html'

    args['f'] = 'json'
    assert check_format(args, headers_) == 'json'

    headers_['Accept'] = 'text/html'
    assert check_format({}, headers_) == 'html'

    headers_['Accept'] = 'application/json'
    assert check_format({}, headers_) == 'json'

    headers_['accept'] = 'text/html'
    assert check_format({}, headers_) == 'html'

    hh = 'text/html,application/xhtml+xml,application/xml;q=0.9,'

    headers_['Accept'] = hh
    assert check_format({}, headers_) == 'html'

    headers_['accept'] = hh
    assert check_format({}, headers_) == 'html'
예제 #2
0
def test_check_format():
    args = {'f': 'html'}

    req_headers = {}

    assert check_format({}, req_headers) is None

    assert check_format(args, req_headers) == 'html'

    args['f'] = 'json'
    assert check_format(args, req_headers) == 'json'

    args['f'] = 'jsonld'
    assert check_format(args, req_headers) == 'jsonld'

    args['f'] = 'html'
    assert check_format(args, req_headers) == 'html'

    req_headers['Accept'] = 'text/html'
    assert check_format({}, req_headers) == 'html'

    req_headers['Accept'] = 'application/json'
    assert check_format({}, req_headers) == 'json'

    req_headers['Accept'] = 'application/ld+json'
    assert check_format({}, req_headers) == 'jsonld'

    req_headers['accept'] = 'text/html'
    assert check_format({}, req_headers) == 'html'

    hh = 'text/html,application/xhtml+xml,application/xml;q=0.9,'

    req_headers['Accept'] = hh
    assert check_format({}, req_headers) == 'html'

    req_headers['accept'] = hh
    assert check_format({}, req_headers) == 'html'

    req_headers = make_req_headers(HTTP_ACCEPT=hh)
    assert check_format({}, req_headers) == 'html'

    req_headers = make_req_headers(HTTP_ACCEPT='text/html')
    assert check_format({}, req_headers) == 'html'

    req_headers = make_req_headers(HTTP_ACCEPT='application/json')
    assert check_format({}, req_headers) == 'json'

    req_headers = make_req_headers(HTTP_ACCEPT='application/ld+json')
    assert check_format({}, req_headers) == 'jsonld'

    # Overrule HTTP content negotiation
    args['f'] = 'html'
    assert check_format(args, req_headers) == 'html'

    req_headers = make_req_headers(HTTP_ACCEPT='text/html')
    args['f'] = 'json'
    assert check_format(args, req_headers) == 'json'