kopia lustrzana https://github.com/simonw/datasette
Fix bug with ?_nl=on and binary data, closes #914
rodzic
3a4c8ed36a
commit
8e7e6458a6
|
@ -84,7 +84,7 @@ def json_renderer(args, data, view_name):
|
|||
# Handle _nl option for _shape=array
|
||||
nl = args.get("_nl", "")
|
||||
if nl and shape == "array":
|
||||
body = "\n".join(json.dumps(item) for item in data)
|
||||
body = "\n".join(json.dumps(item, cls=CustomJSONEncoder) for item in data)
|
||||
content_type = "text/plain"
|
||||
else:
|
||||
body = json.dumps(data, cls=CustomJSONEncoder)
|
||||
|
|
|
@ -663,7 +663,8 @@ CREATE VIEW searchable_view_configured_by_metadata AS
|
|||
)
|
||||
)
|
||||
TABLE_PARAMETERIZED_SQL = [
|
||||
("insert into binary_data (data) values (?);", [b"this is binary data"])
|
||||
("insert into binary_data (data) values (?);", [b"\x15\x1c\x02\xc7\xad\x05\xfe"]),
|
||||
("insert into binary_data (data) values (?);", [b"\x15\x1c\x03\xc7\xad\x05\xfe"]),
|
||||
]
|
||||
|
||||
EXTRA_DATABASE_SQL = """
|
||||
|
|
|
@ -105,7 +105,7 @@ def test_database_page(app_client):
|
|||
"name": "binary_data",
|
||||
"columns": ["data"],
|
||||
"primary_keys": [],
|
||||
"count": 1,
|
||||
"count": 2,
|
||||
"hidden": False,
|
||||
"fts_table": None,
|
||||
"foreign_keys": {"incoming": [], "outgoing": []},
|
||||
|
@ -1793,3 +1793,32 @@ def test_null_foreign_keys_are_not_expanded(app_client):
|
|||
def test_inspect_file_used_for_count(app_client_immutable_and_inspect_file):
|
||||
response = app_client_immutable_and_inspect_file.get("/fixtures/sortable.json")
|
||||
assert response.json["filtered_table_rows_count"] == 100
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"path,expected_json,expected_text",
|
||||
[
|
||||
(
|
||||
"/fixtures/binary_data.json?_shape=array",
|
||||
[
|
||||
{"rowid": 1, "data": {"$base64": True, "encoded": "FRwCx60F/g=="}},
|
||||
{"rowid": 2, "data": {"$base64": True, "encoded": "FRwDx60F/g=="}},
|
||||
],
|
||||
None,
|
||||
),
|
||||
(
|
||||
"/fixtures/binary_data.json?_shape=array&_nl=on",
|
||||
None,
|
||||
(
|
||||
'{"rowid": 1, "data": {"$base64": true, "encoded": "FRwCx60F/g=="}}\n'
|
||||
'{"rowid": 2, "data": {"$base64": true, "encoded": "FRwDx60F/g=="}}'
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_binary_data_in_json(app_client, path, expected_json, expected_text):
|
||||
response = app_client.get(path)
|
||||
if expected_json:
|
||||
assert response.json == expected_json
|
||||
else:
|
||||
assert response.text == expected_text
|
||||
|
|
|
@ -1134,8 +1134,13 @@ def test_binary_data_display(app_client):
|
|||
[
|
||||
'<td class="col-Link type-pk"><a href="/fixtures/binary_data/1">1</a></td>',
|
||||
'<td class="col-rowid type-int">1</td>',
|
||||
'<td class="col-data type-bytes"><Binary\xa0data:\xa019\xa0bytes></td>',
|
||||
]
|
||||
'<td class="col-data type-bytes"><Binary\xa0data:\xa07\xa0bytes></td>',
|
||||
],
|
||||
[
|
||||
'<td class="col-Link type-pk"><a href="/fixtures/binary_data/2">2</a></td>',
|
||||
'<td class="col-rowid type-int">2</td>',
|
||||
'<td class="col-data type-bytes"><Binary\xa0data:\xa07\xa0bytes></td>',
|
||||
],
|
||||
]
|
||||
assert expected_tds == [
|
||||
[str(td) for td in tr.select("td")] for tr in table.select("tbody tr")
|
||||
|
|
Ładowanie…
Reference in New Issue