Experimental new table / encoding schema

See https://github.com/django/asgiref/issues/51#issuecomment-450603464
This commit is contained in:
Simon Willison 2018-12-30 21:00:54 -08:00
commit 0f3b35d4e8
11 changed files with 53 additions and 18 deletions

View file

@ -597,7 +597,7 @@ def test_table_shape_object_compound_primary_Key(app_client):
def test_table_with_slashes_in_name(app_client):
response = app_client.get('/fixtures/table%2Fwith%2Fslashes.csv?_shape=objects&_format=json')
response = app_client.get('/fixtures/tableU+002FwithU+002Fslashes.csv?_shape=objects&_format=json')
assert response.status == 200
data = response.json
assert data['rows'] == [{
@ -897,7 +897,7 @@ def test_row(app_client):
def test_row_strange_table_name(app_client):
response = app_client.get('/fixtures/table%2Fwith%2Fslashes.csv/3.json?_shape=objects')
response = app_client.get('/fixtures/tableU+002FwithU+002Fslashes.csv/3.json?_shape=objects')
assert response.status == 200
assert [{'pk': '3', 'content': 'hey'}] == response.json['rows']

View file

@ -54,14 +54,14 @@ def test_row(app_client):
def test_row_strange_table_name(app_client):
response = app_client.get(
'/fixtures/table%2Fwith%2Fslashes.csv/3',
'/fixtures/tableU+002FwithU+002Fslashes.csv/3',
allow_redirects=False
)
assert response.status == 302
assert response.headers['Location'].endswith(
'/table%2Fwith%2Fslashes.csv/3'
'/tableU+002FwithU+002Fslashes.csv/3'
)
response = app_client.get('/fixtures/table%2Fwith%2Fslashes.csv/3')
response = app_client.get('/fixtures/tableU+002FwithU+002Fslashes.csv/3')
assert response.status == 200
@ -358,7 +358,7 @@ def test_facets_persist_through_filter_form(app_client):
('/fixtures/simple_primary_key', [
'table', 'db-fixtures', 'table-simple_primary_key'
]),
('/fixtures/table%2Fwith%2Fslashes.csv', [
('/fixtures/tableU+002FwithU+002Fslashes.csv', [
'table', 'db-fixtures', 'table-tablewithslashescsv-fa7563'
]),
('/fixtures/simple_primary_key/1', [

View file

@ -374,3 +374,16 @@ def test_path_with_format(path, format, extra_qs, expected):
)
actual = utils.path_with_format(request, format, extra_qs)
assert expected == actual
@pytest.mark.parametrize("name,expected", [
("table", "table"),
("table/and/slashes", "tableU+002FandU+002Fslashes"),
("~table", "U+007Etable"),
("+bobcats!", "U+002Bbobcats!"),
("U+007Etable", "UU+002B007Etable"),
])
def test_encode_decode_table_name(name, expected):
encoded = utils.encode_table_name(name)
assert encoded == expected
assert name == utils.decode_table_name(encoded)