mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
?_filter_column=col&_filter_op=op&_filter_value=value redirect
Part of implementing the filters UI (refs #86) - the following: /trees/Trees?_filter_column=SiteOrder&_filter_op=gt&_filter_value=2 Now redirects to this; /trees/Trees?SiteOrder__gt=2
This commit is contained in:
parent
ddc808f387
commit
386fb11d42
3 changed files with 53 additions and 6 deletions
|
|
@ -4,6 +4,7 @@ import pytest
|
|||
import sqlite3
|
||||
import tempfile
|
||||
import time
|
||||
import urllib.parse
|
||||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
|
|
@ -227,6 +228,28 @@ def test_row(app_client):
|
|||
assert [{'pk': '1', 'content': 'hello'}] == response.json['rows']
|
||||
|
||||
|
||||
def test_add_filter_redirects(app_client):
|
||||
filter_args = urllib.parse.urlencode({
|
||||
'_filter_column': 'content',
|
||||
'_filter_op': 'startswith',
|
||||
'_filter_value': 'x'
|
||||
})
|
||||
# First we need to resolve the correct path before testing more redirects
|
||||
path_base = app_client.get(
|
||||
'/test_tables/simple_primary_key', allow_redirects=False, gather_request=False
|
||||
).headers['Location']
|
||||
path = path_base + '?' + filter_args
|
||||
response = app_client.get(path, allow_redirects=False, gather_request=False)
|
||||
assert response.status == 302
|
||||
assert response.headers['Location'].endswith('?content__startswith=x')
|
||||
|
||||
# Adding a redirect to an existing querystring:
|
||||
path = path_base + '?foo=bar&' + filter_args
|
||||
response = app_client.get(path, allow_redirects=False, gather_request=False)
|
||||
assert response.status == 302
|
||||
assert response.headers['Location'].endswith('?content__startswith=x&foo=bar')
|
||||
|
||||
|
||||
TABLES = '''
|
||||
CREATE TABLE simple_primary_key (
|
||||
pk varchar(30) primary key,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue