New ?_json=colname argument for returning unescaped JSON

Also extracted docs for special JSON arguments into a new section.

Closes #31
This commit is contained in:
Simon Willison 2018-05-28 11:08:39 -07:00
commit 76d11eb768
No known key found for this signature in database
GPG key ID: 17E2DEA2588B7F52
3 changed files with 91 additions and 10 deletions

View file

@ -1151,3 +1151,39 @@ def test_suggest_facets_off():
def test_ttl_parameter(app_client, path, expected_cache_control):
response = app_client.get(path, gather_request=False)
assert expected_cache_control == response.headers['Cache-Control']
test_json_columns_default_expected = [{
"intval": 1,
"strval": "s",
"floatval": 0.5,
"jsonval": "{\"foo\": \"bar\"}"
}]
@pytest.mark.parametrize("extra_args,expected", [
("", test_json_columns_default_expected),
("&_json=intval", test_json_columns_default_expected),
("&_json=strval", test_json_columns_default_expected),
("&_json=floatval", test_json_columns_default_expected),
("&_json=jsonval", [{
"intval": 1,
"strval": "s",
"floatval": 0.5,
"jsonval": {
"foo": "bar"
}
}])
])
def test_json_columns(app_client, extra_args, expected):
sql = '''
select 1 as intval, "s" as strval, 0.5 as floatval,
'{"foo": "bar"}' as jsonval
'''
path = "/test_tables.json?" + urllib.parse.urlencode({
"sql": sql,
"_shape": "array"
})
path += extra_args
response = app_client.get(path, gather_request=False)
assert expected == response.json