mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
?_fts_table= and ?_fts_pk= arguments, closes #428
This commit is contained in:
parent
9cd3b44277
commit
db74cf0144
6 changed files with 60 additions and 4 deletions
|
|
@ -209,6 +209,10 @@ METADATA = {
|
|||
},
|
||||
'simple_view': {
|
||||
'sortable_columns': ['content'],
|
||||
},
|
||||
'searchable_view_configured_by_metadata': {
|
||||
'fts_table': 'searchable_fts',
|
||||
'fts_pk': 'pk'
|
||||
}
|
||||
},
|
||||
'queries': {
|
||||
|
|
@ -564,6 +568,12 @@ INSERT INTO [table/with/slashes.csv] VALUES (3, 'hey');
|
|||
CREATE VIEW simple_view AS
|
||||
SELECT content, upper(content) AS upper_content FROM simple_primary_key;
|
||||
|
||||
CREATE VIEW searchable_view AS
|
||||
SELECT * from searchable;
|
||||
|
||||
CREATE VIEW searchable_view_configured_by_metadata AS
|
||||
SELECT * from searchable;
|
||||
|
||||
''' + '\n'.join([
|
||||
'INSERT INTO no_primary_key VALUES ({i}, "a{i}", "b{i}", "c{i}");'.format(i=i + 1)
|
||||
for i in range(201)
|
||||
|
|
|
|||
|
|
@ -847,6 +847,24 @@ def test_searchable(app_client, path, expected_rows):
|
|||
assert expected_rows == response.json['rows']
|
||||
|
||||
|
||||
@pytest.mark.parametrize('path,expected_rows', [
|
||||
('/fixtures/searchable_view_configured_by_metadata.json?_search=weasel', [
|
||||
[2, 'terry dog', 'sara weasel', 'puma'],
|
||||
]),
|
||||
# This should return all results because search is not configured:
|
||||
('/fixtures/searchable_view.json?_search=weasel', [
|
||||
[1, 'barry cat', 'terry dog', 'panther'],
|
||||
[2, 'terry dog', 'sara weasel', 'puma'],
|
||||
]),
|
||||
('/fixtures/searchable_view.json?_search=weasel&_fts_table=searchable_fts&_fts_pk=pk', [
|
||||
[2, 'terry dog', 'sara weasel', 'puma'],
|
||||
]),
|
||||
])
|
||||
def test_searchable_views(app_client, path, expected_rows):
|
||||
response = app_client.get(path)
|
||||
assert expected_rows == response.json['rows']
|
||||
|
||||
|
||||
def test_searchable_invalid_column(app_client):
|
||||
response = app_client.get(
|
||||
'/fixtures/searchable.json?_search_invalid=x'
|
||||
|
|
|
|||
|
|
@ -185,6 +185,20 @@ def test_empty_search_parameter_gets_removed(app_client):
|
|||
)
|
||||
|
||||
|
||||
def test_searchable_view_persists_fts_table(app_client):
|
||||
# The search form should persist ?_fts_table as a hidden field
|
||||
response = app_client.get(
|
||||
"/fixtures/searchable_view?_fts_table=searchable_fts&_fts_pk=pk"
|
||||
)
|
||||
inputs = Soup(response.body, "html.parser").find("form").findAll("input")
|
||||
hiddens = [i for i in inputs if i["type"] == "hidden"]
|
||||
assert [
|
||||
('_fts_table', 'searchable_fts'), ('_fts_pk', 'pk')
|
||||
] == [
|
||||
(hidden['name'], hidden['value']) for hidden in hiddens
|
||||
]
|
||||
|
||||
|
||||
def test_sort_by_desc_redirects(app_client):
|
||||
path_base = '/fixtures/sortable'
|
||||
path = path_base + '?' + urllib.parse.urlencode({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue