?_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:
Simon Willison 2017-11-19 12:25:29 -08:00
commit 386fb11d42
No known key found for this signature in database
GPG key ID: FBB38AFE227189DB
3 changed files with 53 additions and 6 deletions

View file

@ -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,