kopia lustrzana https://github.com/simonw/datasette
test_facets.py using ds_client, refs #1959
rodzic
bc88491cb7
commit
b998c2793f
|
@ -3,15 +3,16 @@ from datasette.database import Database
|
||||||
from datasette.facets import ColumnFacet, ArrayFacet, DateFacet
|
from datasette.facets import ColumnFacet, ArrayFacet, DateFacet
|
||||||
from datasette.utils.asgi import Request
|
from datasette.utils.asgi import Request
|
||||||
from datasette.utils import detect_json1
|
from datasette.utils import detect_json1
|
||||||
from .fixtures import app_client, make_app_client # noqa
|
from .fixtures import make_app_client
|
||||||
import json
|
import json
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.ds_client
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_column_facet_suggest(app_client):
|
async def test_column_facet_suggest(ds_client):
|
||||||
facet = ColumnFacet(
|
facet = ColumnFacet(
|
||||||
app_client.ds,
|
ds_client.ds,
|
||||||
Request.fake("/"),
|
Request.fake("/"),
|
||||||
database="fixtures",
|
database="fixtures",
|
||||||
sql="select * from facetable",
|
sql="select * from facetable",
|
||||||
|
@ -36,10 +37,11 @@ async def test_column_facet_suggest(app_client):
|
||||||
] == suggestions
|
] == suggestions
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.ds_client
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_column_facet_suggest_skip_if_already_selected(app_client):
|
async def test_column_facet_suggest_skip_if_already_selected(ds_client):
|
||||||
facet = ColumnFacet(
|
facet = ColumnFacet(
|
||||||
app_client.ds,
|
ds_client.ds,
|
||||||
Request.fake("/?_facet=planet_int&_facet=on_earth"),
|
Request.fake("/?_facet=planet_int&_facet=on_earth"),
|
||||||
database="fixtures",
|
database="fixtures",
|
||||||
sql="select * from facetable",
|
sql="select * from facetable",
|
||||||
|
@ -74,10 +76,11 @@ async def test_column_facet_suggest_skip_if_already_selected(app_client):
|
||||||
] == suggestions
|
] == suggestions
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.ds_client
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_column_facet_suggest_skip_if_enabled_by_metadata(app_client):
|
async def test_column_facet_suggest_skip_if_enabled_by_metadata(ds_client):
|
||||||
facet = ColumnFacet(
|
facet = ColumnFacet(
|
||||||
app_client.ds,
|
ds_client.ds,
|
||||||
Request.fake("/"),
|
Request.fake("/"),
|
||||||
database="fixtures",
|
database="fixtures",
|
||||||
sql="select * from facetable",
|
sql="select * from facetable",
|
||||||
|
@ -96,10 +99,11 @@ async def test_column_facet_suggest_skip_if_enabled_by_metadata(app_client):
|
||||||
] == suggestions
|
] == suggestions
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.ds_client
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_column_facet_results(app_client):
|
async def test_column_facet_results(ds_client):
|
||||||
facet = ColumnFacet(
|
facet = ColumnFacet(
|
||||||
app_client.ds,
|
ds_client.ds,
|
||||||
Request.fake("/?_facet=_city_id"),
|
Request.fake("/?_facet=_city_id"),
|
||||||
database="fixtures",
|
database="fixtures",
|
||||||
sql="select * from facetable",
|
sql="select * from facetable",
|
||||||
|
@ -148,10 +152,11 @@ async def test_column_facet_results(app_client):
|
||||||
] == buckets
|
] == buckets
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.ds_client
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_column_facet_results_column_starts_with_underscore(app_client):
|
async def test_column_facet_results_column_starts_with_underscore(ds_client):
|
||||||
facet = ColumnFacet(
|
facet = ColumnFacet(
|
||||||
app_client.ds,
|
ds_client.ds,
|
||||||
Request.fake("/?_facet=_neighborhood"),
|
Request.fake("/?_facet=_neighborhood"),
|
||||||
database="fixtures",
|
database="fixtures",
|
||||||
sql="select * from facetable",
|
sql="select * from facetable",
|
||||||
|
@ -270,10 +275,11 @@ async def test_column_facet_results_column_starts_with_underscore(app_client):
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.ds_client
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_column_facet_from_metadata_cannot_be_hidden(app_client):
|
async def test_column_facet_from_metadata_cannot_be_hidden(ds_client):
|
||||||
facet = ColumnFacet(
|
facet = ColumnFacet(
|
||||||
app_client.ds,
|
ds_client.ds,
|
||||||
Request.fake("/"),
|
Request.fake("/"),
|
||||||
database="fixtures",
|
database="fixtures",
|
||||||
sql="select * from facetable",
|
sql="select * from facetable",
|
||||||
|
@ -323,11 +329,12 @@ async def test_column_facet_from_metadata_cannot_be_hidden(app_client):
|
||||||
] == buckets
|
] == buckets
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.ds_client
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@pytest.mark.skipif(not detect_json1(), reason="Requires the SQLite json1 module")
|
@pytest.mark.skipif(not detect_json1(), reason="Requires the SQLite json1 module")
|
||||||
async def test_array_facet_suggest(app_client):
|
async def test_array_facet_suggest(ds_client):
|
||||||
facet = ArrayFacet(
|
facet = ArrayFacet(
|
||||||
app_client.ds,
|
ds_client.ds,
|
||||||
Request.fake("/"),
|
Request.fake("/"),
|
||||||
database="fixtures",
|
database="fixtures",
|
||||||
sql="select * from facetable",
|
sql="select * from facetable",
|
||||||
|
@ -343,11 +350,12 @@ async def test_array_facet_suggest(app_client):
|
||||||
] == suggestions
|
] == suggestions
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.ds_client
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@pytest.mark.skipif(not detect_json1(), reason="Requires the SQLite json1 module")
|
@pytest.mark.skipif(not detect_json1(), reason="Requires the SQLite json1 module")
|
||||||
async def test_array_facet_suggest_not_if_all_empty_arrays(app_client):
|
async def test_array_facet_suggest_not_if_all_empty_arrays(ds_client):
|
||||||
facet = ArrayFacet(
|
facet = ArrayFacet(
|
||||||
app_client.ds,
|
ds_client.ds,
|
||||||
Request.fake("/"),
|
Request.fake("/"),
|
||||||
database="fixtures",
|
database="fixtures",
|
||||||
sql="select * from facetable where tags = '[]'",
|
sql="select * from facetable where tags = '[]'",
|
||||||
|
@ -357,11 +365,12 @@ async def test_array_facet_suggest_not_if_all_empty_arrays(app_client):
|
||||||
assert [] == suggestions
|
assert [] == suggestions
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.ds_client
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@pytest.mark.skipif(not detect_json1(), reason="Requires the SQLite json1 module")
|
@pytest.mark.skipif(not detect_json1(), reason="Requires the SQLite json1 module")
|
||||||
async def test_array_facet_results(app_client):
|
async def test_array_facet_results(ds_client):
|
||||||
facet = ArrayFacet(
|
facet = ArrayFacet(
|
||||||
app_client.ds,
|
ds_client.ds,
|
||||||
Request.fake("/?_facet_array=tags"),
|
Request.fake("/?_facet_array=tags"),
|
||||||
database="fixtures",
|
database="fixtures",
|
||||||
sql="select * from facetable",
|
sql="select * from facetable",
|
||||||
|
@ -403,6 +412,7 @@ async def test_array_facet_results(app_client):
|
||||||
] == buckets
|
] == buckets
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.ds_client
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@pytest.mark.skipif(not detect_json1(), reason="Requires the SQLite json1 module")
|
@pytest.mark.skipif(not detect_json1(), reason="Requires the SQLite json1 module")
|
||||||
async def test_array_facet_handle_duplicate_tags():
|
async def test_array_facet_handle_duplicate_tags():
|
||||||
|
@ -458,10 +468,11 @@ async def test_array_facet_handle_duplicate_tags():
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.ds_client
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_date_facet_results(app_client):
|
async def test_date_facet_results(ds_client):
|
||||||
facet = DateFacet(
|
facet = DateFacet(
|
||||||
app_client.ds,
|
ds_client.ds,
|
||||||
Request.fake("/?_facet_date=created"),
|
Request.fake("/?_facet_date=created"),
|
||||||
database="fixtures",
|
database="fixtures",
|
||||||
sql="select * from facetable",
|
sql="select * from facetable",
|
||||||
|
@ -623,12 +634,15 @@ def test_other_types_of_facet_in_metadata():
|
||||||
assert fragment in response.text
|
assert fragment in response.text
|
||||||
|
|
||||||
|
|
||||||
def test_conflicting_facet_names_json(app_client):
|
@pytest.mark.ds_client
|
||||||
response = app_client.get(
|
@pytest.mark.ds_client
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_conflicting_facet_names_json(ds_client):
|
||||||
|
response = await ds_client.get(
|
||||||
"/fixtures/facetable.json?_facet=created&_facet_date=created"
|
"/fixtures/facetable.json?_facet=created&_facet_date=created"
|
||||||
"&_facet=tags&_facet_array=tags"
|
"&_facet=tags&_facet_array=tags"
|
||||||
)
|
)
|
||||||
assert set(response.json["facet_results"].keys()) == {
|
assert set(response.json()["facet_results"].keys()) == {
|
||||||
"created",
|
"created",
|
||||||
"tags",
|
"tags",
|
||||||
"created_2",
|
"created_2",
|
||||||
|
|
Ładowanie…
Reference in New Issue