mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Faceting no longer breaks pagination, fixes #282
This commit is contained in:
parent
49f317752c
commit
2bfd111d65
2 changed files with 8 additions and 3 deletions
|
|
@ -556,7 +556,7 @@ class TableView(RowTableShared):
|
||||||
""".format(
|
""".format(
|
||||||
col=escape_sqlite(column),
|
col=escape_sqlite(column),
|
||||||
from_sql=from_sql,
|
from_sql=from_sql,
|
||||||
and_or_where='and' if where_clause else 'where',
|
and_or_where='and' if from_sql_where_clauses else 'where',
|
||||||
limit=facet_size+1,
|
limit=facet_size+1,
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ from .fixtures import (
|
||||||
METADATA,
|
METADATA,
|
||||||
)
|
)
|
||||||
import pytest
|
import pytest
|
||||||
|
import urllib
|
||||||
|
|
||||||
pytest.fixture(scope='module')(app_client)
|
pytest.fixture(scope='module')(app_client)
|
||||||
pytest.fixture(scope='module')(app_client_shorter_time_limit)
|
pytest.fixture(scope='module')(app_client_shorter_time_limit)
|
||||||
|
|
@ -533,6 +534,8 @@ def test_table_with_reserved_word_name(app_client):
|
||||||
('/test_tables/paginated_view.json?_size=25', 201, 9),
|
('/test_tables/paginated_view.json?_size=25', 201, 9),
|
||||||
('/test_tables/paginated_view.json?_size=max', 201, 3),
|
('/test_tables/paginated_view.json?_size=max', 201, 3),
|
||||||
('/test_tables/123_starts_with_digits.json', 0, 1),
|
('/test_tables/123_starts_with_digits.json', 0, 1),
|
||||||
|
# Ensure faceting doesn't break pagination:
|
||||||
|
('/test_tables/compound_three_primary_keys.json?_facet=pk1', 1001, 21),
|
||||||
])
|
])
|
||||||
def test_paginate_tables_and_views(app_client, path, expected_rows, expected_pages):
|
def test_paginate_tables_and_views(app_client, path, expected_rows, expected_pages):
|
||||||
fetched = []
|
fetched = []
|
||||||
|
|
@ -545,8 +548,10 @@ def test_paginate_tables_and_views(app_client, path, expected_rows, expected_pag
|
||||||
path = response.json['next_url']
|
path = response.json['next_url']
|
||||||
if path:
|
if path:
|
||||||
assert response.json['next']
|
assert response.json['next']
|
||||||
assert '_next={}'.format(response.json['next']) in path
|
assert urllib.parse.urlencode({
|
||||||
assert count < 10, 'Possible infinite loop detected'
|
'_next': response.json['next']
|
||||||
|
}) in path
|
||||||
|
assert count < 30, 'Possible infinite loop detected'
|
||||||
|
|
||||||
assert expected_rows == len(fetched)
|
assert expected_rows == len(fetched)
|
||||||
assert expected_pages == count
|
assert expected_pages == count
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue