Export option: _shape=array&_nl=on for newline-delimited JSON

This commit is contained in:
Simon Willison 2019-01-27 17:40:23 -08:00
commit b5dd83981a
6 changed files with 58 additions and 11 deletions

View file

@ -9,6 +9,7 @@ from .fixtures import ( # noqa
make_app_client,
METADATA,
)
import json
import pytest
import urllib
@ -547,6 +548,27 @@ def test_table_shape_array(app_client):
}] == response.json
def test_table_shape_array_nl(app_client):
response = app_client.get(
'/fixtures/simple_primary_key.json?_shape=array&_nl=on'
)
lines = response.text.split("\n")
results = [json.loads(line) for line in lines]
assert [{
'id': '1',
'content': 'hello',
}, {
'id': '2',
'content': 'world',
}, {
'id': '3',
'content': '',
}, {
'id': '4',
'content': 'RENDER_CELL_DEMO',
}] == results
def test_table_shape_invalid(app_client):
response = app_client.get(
'/fixtures/simple_primary_key.json?_shape=invalid'

View file

@ -422,6 +422,7 @@ def test_table_csv_json_export_interface(app_client):
assert [
"simple_primary_key.json?id__gt=2",
"simple_primary_key.json?id__gt=2&_shape=array",
"simple_primary_key.json?id__gt=2&_shape=array&_nl=on",
"simple_primary_key.json?id__gt=2&_shape=object"
] == json_links
# And the CSV form
@ -796,7 +797,7 @@ def test_advanced_export_box(app_client, path, has_object, has_stream, has_expan
assert response.status == 200
soup = Soup(response.body, "html.parser")
# JSON shape options
expected_json_shapes = ["default", "array"]
expected_json_shapes = ["default", "array", "newline-delimited"]
if has_object:
expected_json_shapes.append("object")
div = soup.find("div", {"class": "advanced-export"})