Error handling for ?_sort and ?_sort_desc

Verifies that they match an existing column, and only one or the other option
is provided - refs #189

Eses a new DatasetteError exception that closes #193
This commit is contained in:
Simon Willison 2018-04-08 21:07:31 -07:00 committed by Simon Willison
commit a87df963a0
2 changed files with 37 additions and 6 deletions

View file

@ -400,6 +400,24 @@ def test_sortable_and_filtered(app_client):
]
def test_sortable_argument_errors(app_client):
response = app_client.get(
'/test_tables/sortable.json?_sort=badcolumn',
gather_request=False
)
assert 'Cannot sort table by badcolumn' == response.json['error']
response = app_client.get(
'/test_tables/sortable.json?_sort_desc=badcolumn2',
gather_request=False
)
assert 'Cannot sort table by badcolumn2' == response.json['error']
response = app_client.get(
'/test_tables/sortable.json?_sort=content&_sort_desc=pk2',
gather_request=False
)
assert 'Cannot use _sort and _sort_desc at the same time' == response.json['error']
@pytest.mark.parametrize('path,expected_rows', [
('/test_tables/simple_primary_key.json?content=hello', [
['1', 'hello'],