From 896cc2c6acfefa65c54a162831e7f09159603988 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Fri, 9 Oct 2020 09:26:17 -0700 Subject: [PATCH] Replace MockRequest with Request.fake() Close #1004 --- tests/test_facets.py | 20 ++++++++++---------- tests/utils.py | 8 -------- 2 files changed, 10 insertions(+), 18 deletions(-) delete mode 100644 tests/utils.py diff --git a/tests/test_facets.py b/tests/test_facets.py index e3dc3df3..1e19dc3a 100644 --- a/tests/test_facets.py +++ b/tests/test_facets.py @@ -1,7 +1,7 @@ from datasette.facets import ColumnFacet, ArrayFacet, DateFacet +from datasette.utils.asgi import Request from datasette.utils import detect_json1 from .fixtures import app_client # noqa -from .utils import MockRequest import pytest @@ -9,7 +9,7 @@ import pytest async def test_column_facet_suggest(app_client): facet = ColumnFacet( app_client.ds, - MockRequest("http://localhost/"), + Request.fake("/"), database="fixtures", sql="select * from facetable", table="facetable", @@ -34,7 +34,7 @@ async def test_column_facet_suggest(app_client): async def test_column_facet_suggest_skip_if_already_selected(app_client): facet = ColumnFacet( app_client.ds, - MockRequest("http://localhost/?_facet=planet_int&_facet=on_earth"), + Request.fake("/?_facet=planet_int&_facet=on_earth"), database="fixtures", sql="select * from facetable", table="facetable", @@ -72,7 +72,7 @@ async def test_column_facet_suggest_skip_if_already_selected(app_client): async def test_column_facet_suggest_skip_if_enabled_by_metadata(app_client): facet = ColumnFacet( app_client.ds, - MockRequest("http://localhost/"), + Request.fake("/"), database="fixtures", sql="select * from facetable", table="facetable", @@ -94,7 +94,7 @@ async def test_column_facet_suggest_skip_if_enabled_by_metadata(app_client): async def test_column_facet_results(app_client): facet = ColumnFacet( app_client.ds, - MockRequest("http://localhost/?_facet=city_id"), + Request.fake("/?_facet=city_id"), database="fixtures", sql="select * from facetable", table="facetable", @@ -146,7 +146,7 @@ async def test_column_facet_results(app_client): async def test_column_facet_from_metadata_cannot_be_hidden(app_client): facet = ColumnFacet( app_client.ds, - MockRequest("http://localhost/"), + Request.fake("/"), database="fixtures", sql="select * from facetable", table="facetable", @@ -200,7 +200,7 @@ async def test_column_facet_from_metadata_cannot_be_hidden(app_client): async def test_array_facet_suggest(app_client): facet = ArrayFacet( app_client.ds, - MockRequest("http://localhost/"), + Request.fake("/"), database="fixtures", sql="select * from facetable", table="facetable", @@ -220,7 +220,7 @@ async def test_array_facet_suggest(app_client): async def test_array_facet_suggest_not_if_all_empty_arrays(app_client): facet = ArrayFacet( app_client.ds, - MockRequest("http://localhost/"), + Request.fake("/"), database="fixtures", sql="select * from facetable where tags = '[]'", table="facetable", @@ -234,7 +234,7 @@ async def test_array_facet_suggest_not_if_all_empty_arrays(app_client): async def test_array_facet_results(app_client): facet = ArrayFacet( app_client.ds, - MockRequest("http://localhost/?_facet_array=tags"), + Request.fake("/?_facet_array=tags"), database="fixtures", sql="select * from facetable", table="facetable", @@ -279,7 +279,7 @@ async def test_array_facet_results(app_client): async def test_date_facet_results(app_client): facet = DateFacet( app_client.ds, - MockRequest("http://localhost/?_facet_date=created"), + Request.fake("/?_facet_date=created"), database="fixtures", sql="select * from facetable", table="facetable", diff --git a/tests/utils.py b/tests/utils.py deleted file mode 100644 index 8947956b..00000000 --- a/tests/utils.py +++ /dev/null @@ -1,8 +0,0 @@ -class MockRequest: - def __init__(self, url): - self.url = url - self.path = "/" + url.split("://")[1].split("/", 1)[1] - self.query_string = "" - if "?" in url: - self.query_string = url.split("?", 1)[1] - self.path = self.path.split("?")[0]