diff --git a/tests/test_facets.py b/tests/test_facets.py index cbee23b0..cecaa305 100644 --- a/tests/test_facets.py +++ b/tests/test_facets.py @@ -3,15 +3,16 @@ from datasette.database import Database from datasette.facets import ColumnFacet, ArrayFacet, DateFacet from datasette.utils.asgi import Request from datasette.utils import detect_json1 -from .fixtures import app_client, make_app_client # noqa +from .fixtures import make_app_client import json import pytest +@pytest.mark.ds_client @pytest.mark.asyncio -async def test_column_facet_suggest(app_client): +async def test_column_facet_suggest(ds_client): facet = ColumnFacet( - app_client.ds, + ds_client.ds, Request.fake("/"), database="fixtures", sql="select * from facetable", @@ -36,10 +37,11 @@ async def test_column_facet_suggest(app_client): ] == suggestions +@pytest.mark.ds_client @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( - app_client.ds, + ds_client.ds, Request.fake("/?_facet=planet_int&_facet=on_earth"), database="fixtures", sql="select * from facetable", @@ -74,10 +76,11 @@ async def test_column_facet_suggest_skip_if_already_selected(app_client): ] == suggestions +@pytest.mark.ds_client @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( - app_client.ds, + ds_client.ds, Request.fake("/"), database="fixtures", sql="select * from facetable", @@ -96,10 +99,11 @@ async def test_column_facet_suggest_skip_if_enabled_by_metadata(app_client): ] == suggestions +@pytest.mark.ds_client @pytest.mark.asyncio -async def test_column_facet_results(app_client): +async def test_column_facet_results(ds_client): facet = ColumnFacet( - app_client.ds, + ds_client.ds, Request.fake("/?_facet=_city_id"), database="fixtures", sql="select * from facetable", @@ -148,10 +152,11 @@ async def test_column_facet_results(app_client): ] == buckets +@pytest.mark.ds_client @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( - app_client.ds, + ds_client.ds, Request.fake("/?_facet=_neighborhood"), database="fixtures", 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 -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( - app_client.ds, + ds_client.ds, Request.fake("/"), database="fixtures", sql="select * from facetable", @@ -323,11 +329,12 @@ async def test_column_facet_from_metadata_cannot_be_hidden(app_client): ] == buckets +@pytest.mark.ds_client @pytest.mark.asyncio @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( - app_client.ds, + ds_client.ds, Request.fake("/"), database="fixtures", sql="select * from facetable", @@ -343,11 +350,12 @@ async def test_array_facet_suggest(app_client): ] == suggestions +@pytest.mark.ds_client @pytest.mark.asyncio @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( - app_client.ds, + ds_client.ds, Request.fake("/"), database="fixtures", 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 +@pytest.mark.ds_client @pytest.mark.asyncio @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( - app_client.ds, + ds_client.ds, Request.fake("/?_facet_array=tags"), database="fixtures", sql="select * from facetable", @@ -403,6 +412,7 @@ async def test_array_facet_results(app_client): ] == buckets +@pytest.mark.ds_client @pytest.mark.asyncio @pytest.mark.skipif(not detect_json1(), reason="Requires the SQLite json1 module") 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 -async def test_date_facet_results(app_client): +async def test_date_facet_results(ds_client): facet = DateFacet( - app_client.ds, + ds_client.ds, Request.fake("/?_facet_date=created"), database="fixtures", sql="select * from facetable", @@ -623,12 +634,15 @@ def test_other_types_of_facet_in_metadata(): assert fragment in response.text -def test_conflicting_facet_names_json(app_client): - response = app_client.get( +@pytest.mark.ds_client +@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" "&_facet=tags&_facet_array=tags" ) - assert set(response.json["facet_results"].keys()) == { + assert set(response.json()["facet_results"].keys()) == { "created", "tags", "created_2",