Fixed bug with keyset pagination over compound primary keys

Closes #190
This commit is contained in:
Simon Willison 2018-03-29 22:10:09 -07:00
commit 31f63d1672
No known key found for this signature in database
GPG key ID: 17E2DEA2588B7F52
5 changed files with 88 additions and 10 deletions

View file

@ -10,7 +10,7 @@ def test_homepage(app_client):
assert response.json.keys() == {'test_tables': 0}.keys()
d = response.json['test_tables']
assert d['name'] == 'test_tables'
assert d['tables_count'] == 7
assert d['tables_count'] == 8
def test_database_page(app_client):
@ -60,6 +60,13 @@ def test_database_page(app_client):
'hidden': False,
'foreign_keys': {'incoming': [], 'outgoing': []},
'label_column': None,
}, {
'columns': ['pk1', 'pk2', 'pk3', 'content'],
'name': 'compound_three_primary_keys',
'count': 301,
'hidden': False,
'foreign_keys': {'incoming': [], 'outgoing': []},
'label_column': None,
}, {
'columns': ['content', 'a', 'b', 'c'],
'name': 'no_primary_key',
@ -201,6 +208,19 @@ def test_paginate_tables_and_views(app_client, path, expected_rows, expected_pag
assert expected_pages == count
def test_paginate_compound_keys(app_client):
fetched = []
path = '/test_tables/compound_three_primary_keys.jsono'
while path:
response = app_client.get(path, gather_request=False)
fetched.extend(response.json['rows'])
path = response.json['next_url']
assert 301 == len(fetched)
# Should be correctly ordered
contents = [f['content'] for f in fetched]
assert list(sorted(contents)) == contents
@pytest.mark.parametrize('path,expected_rows', [
('/test_tables/simple_primary_key.json?content=hello', [
['1', 'hello'],