From 69244a617b1118dcbd04a8f102173f04680cf08c Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Mon, 29 Nov 2021 22:17:27 -0800 Subject: [PATCH] Rename city_id to _city_id in fixtures, refs #1525 --- tests/fixtures.py | 8 ++--- tests/test_api.py | 50 ++++++++++++++++---------------- tests/test_facets.py | 36 +++++++++++------------ tests/test_html.py | 34 +++++++++++----------- tests/test_internals_database.py | 4 +-- tests/test_plugins.py | 8 ++--- 6 files changed, 70 insertions(+), 70 deletions(-) diff --git a/tests/fixtures.py b/tests/fixtures.py index 1a879126..37399da0 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -358,7 +358,7 @@ METADATA = { select _neighborhood, facet_cities.name, state from facetable join facet_cities - on facetable.city_id = facet_cities.id + on facetable._city_id = facet_cities.id where _neighborhood like '%' || :text || '%' order by _neighborhood; """ @@ -558,15 +558,15 @@ CREATE TABLE facetable ( planet_int integer, on_earth integer, state text, - city_id integer, + _city_id integer, _neighborhood text, tags text, complex_array text, distinct_some_null, - FOREIGN KEY ("city_id") REFERENCES [facet_cities](id) + FOREIGN KEY ("_city_id") REFERENCES [facet_cities](id) ); INSERT INTO facetable - (created, planet_int, on_earth, state, city_id, _neighborhood, tags, complex_array, distinct_some_null) + (created, planet_int, on_earth, state, _city_id, _neighborhood, tags, complex_array, distinct_some_null) VALUES ("2019-01-14 08:00:00", 1, 1, 'CA', 1, 'Mission', '["tag1", "tag2"]', '[{"foo": "bar"}]', 'one'), ("2019-01-14 08:00:00", 1, 1, 'CA', 1, 'Dogpatch', '["tag1", "tag3"]', '[]', 'two'), diff --git a/tests/test_api.py b/tests/test_api.py index 43b52175..8b3fcd75 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -197,7 +197,7 @@ def test_database_page(app_client): { "other_table": "facetable", "column": "id", - "other_column": "city_id", + "other_column": "_city_id", } ], "outgoing": [], @@ -212,7 +212,7 @@ def test_database_page(app_client): "planet_int", "on_earth", "state", - "city_id", + "_city_id", "_neighborhood", "tags", "complex_array", @@ -227,7 +227,7 @@ def test_database_page(app_client): "outgoing": [ { "other_table": "facet_cities", - "column": "city_id", + "column": "_city_id", "other_column": "id", } ], @@ -1512,40 +1512,40 @@ def test_page_size_matching_max_returned_rows( "path,expected_facet_results", [ ( - "/fixtures/facetable.json?_facet=state&_facet=city_id", + "/fixtures/facetable.json?_facet=state&_facet=_city_id", { "state": { "name": "state", "hideable": True, "type": "column", - "toggle_url": "/fixtures/facetable.json?_facet=city_id", + "toggle_url": "/fixtures/facetable.json?_facet=_city_id", "results": [ { "value": "CA", "label": "CA", "count": 10, - "toggle_url": "_facet=state&_facet=city_id&state=CA", + "toggle_url": "_facet=state&_facet=_city_id&state=CA", "selected": False, }, { "value": "MI", "label": "MI", "count": 4, - "toggle_url": "_facet=state&_facet=city_id&state=MI", + "toggle_url": "_facet=state&_facet=_city_id&state=MI", "selected": False, }, { "value": "MC", "label": "MC", "count": 1, - "toggle_url": "_facet=state&_facet=city_id&state=MC", + "toggle_url": "_facet=state&_facet=_city_id&state=MC", "selected": False, }, ], "truncated": False, }, - "city_id": { - "name": "city_id", + "_city_id": { + "name": "_city_id", "hideable": True, "type": "column", "toggle_url": "/fixtures/facetable.json?_facet=state", @@ -1554,28 +1554,28 @@ def test_page_size_matching_max_returned_rows( "value": 1, "label": "San Francisco", "count": 6, - "toggle_url": "_facet=state&_facet=city_id&city_id=1", + "toggle_url": "_facet=state&_facet=_city_id&_city_id__exact=1", "selected": False, }, { "value": 2, "label": "Los Angeles", "count": 4, - "toggle_url": "_facet=state&_facet=city_id&city_id=2", + "toggle_url": "_facet=state&_facet=_city_id&_city_id__exact=2", "selected": False, }, { "value": 3, "label": "Detroit", "count": 4, - "toggle_url": "_facet=state&_facet=city_id&city_id=3", + "toggle_url": "_facet=state&_facet=_city_id&_city_id__exact=3", "selected": False, }, { "value": 4, "label": "Memnonia", "count": 1, - "toggle_url": "_facet=state&_facet=city_id&city_id=4", + "toggle_url": "_facet=state&_facet=_city_id&_city_id__exact=4", "selected": False, }, ], @@ -1584,26 +1584,26 @@ def test_page_size_matching_max_returned_rows( }, ), ( - "/fixtures/facetable.json?_facet=state&_facet=city_id&state=MI", + "/fixtures/facetable.json?_facet=state&_facet=_city_id&state=MI", { "state": { "name": "state", "hideable": True, "type": "column", - "toggle_url": "/fixtures/facetable.json?_facet=city_id&state=MI", + "toggle_url": "/fixtures/facetable.json?_facet=_city_id&state=MI", "results": [ { "value": "MI", "label": "MI", "count": 4, "selected": True, - "toggle_url": "_facet=state&_facet=city_id", + "toggle_url": "_facet=state&_facet=_city_id", } ], "truncated": False, }, - "city_id": { - "name": "city_id", + "_city_id": { + "name": "_city_id", "hideable": True, "type": "column", "toggle_url": "/fixtures/facetable.json?_facet=state&state=MI", @@ -1613,7 +1613,7 @@ def test_page_size_matching_max_returned_rows( "label": "Detroit", "count": 4, "selected": False, - "toggle_url": "_facet=state&_facet=city_id&state=MI&city_id=3", + "toggle_url": "_facet=state&_facet=_city_id&state=MI&_city_id__exact=3", } ], "truncated": False, @@ -1699,7 +1699,7 @@ def test_suggested_facets(app_client): {"name": "planet_int", "querystring": "_facet=planet_int"}, {"name": "on_earth", "querystring": "_facet=on_earth"}, {"name": "state", "querystring": "_facet=state"}, - {"name": "city_id", "querystring": "_facet=city_id"}, + {"name": "_city_id", "querystring": "_facet=_city_id"}, {"name": "_neighborhood", "querystring": "_facet=_neighborhood"}, {"name": "tags", "querystring": "_facet=tags"}, {"name": "complex_array", "querystring": "_facet=complex_array"}, @@ -1765,7 +1765,7 @@ def test_expand_labels(app_client): "planet_int": 1, "on_earth": 1, "state": "CA", - "city_id": {"value": 1, "label": "San Francisco"}, + "_city_id": {"value": 1, "label": "San Francisco"}, "_neighborhood": "Dogpatch", "tags": '["tag1", "tag3"]', "complex_array": "[]", @@ -1777,7 +1777,7 @@ def test_expand_labels(app_client): "planet_int": 1, "on_earth": 1, "state": "MI", - "city_id": {"value": 3, "label": "Detroit"}, + "_city_id": {"value": 3, "label": "Detroit"}, "_neighborhood": "Corktown", "tags": "[]", "complex_array": "[]", @@ -2128,7 +2128,7 @@ def test_http_options_request(app_client): "planet_int", "on_earth", "state", - "city_id", + "_city_id", "_neighborhood", "tags", "complex_array", @@ -2155,7 +2155,7 @@ def test_http_options_request(app_client): "created", "planet_int", "on_earth", - "city_id", + "_city_id", "_neighborhood", "tags", "complex_array", diff --git a/tests/test_facets.py b/tests/test_facets.py index a20c79c4..429117cb 100644 --- a/tests/test_facets.py +++ b/tests/test_facets.py @@ -23,7 +23,7 @@ async def test_column_facet_suggest(app_client): {"name": "planet_int", "toggle_url": "http://localhost/?_facet=planet_int"}, {"name": "on_earth", "toggle_url": "http://localhost/?_facet=on_earth"}, {"name": "state", "toggle_url": "http://localhost/?_facet=state"}, - {"name": "city_id", "toggle_url": "http://localhost/?_facet=city_id"}, + {"name": "_city_id", "toggle_url": "http://localhost/?_facet=_city_id"}, { "name": "_neighborhood", "toggle_url": "http://localhost/?_facet=_neighborhood", @@ -56,8 +56,8 @@ async def test_column_facet_suggest_skip_if_already_selected(app_client): "toggle_url": "http://localhost/?_facet=planet_int&_facet=on_earth&_facet=state", }, { - "name": "city_id", - "toggle_url": "http://localhost/?_facet=planet_int&_facet=on_earth&_facet=city_id", + "name": "_city_id", + "toggle_url": "http://localhost/?_facet=planet_int&_facet=on_earth&_facet=_city_id", }, { "name": "_neighborhood", @@ -82,7 +82,7 @@ async def test_column_facet_suggest_skip_if_enabled_by_metadata(app_client): database="fixtures", sql="select * from facetable", table="facetable", - metadata={"facets": ["city_id"]}, + metadata={"facets": ["_city_id"]}, ) suggestions = [s["name"] for s in await facet.suggest()] assert [ @@ -100,7 +100,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, - Request.fake("/?_facet=city_id"), + Request.fake("/?_facet=_city_id"), database="fixtures", sql="select * from facetable", table="facetable", @@ -108,8 +108,8 @@ async def test_column_facet_results(app_client): buckets, timed_out = await facet.facet_results() assert [] == timed_out assert { - "city_id": { - "name": "city_id", + "_city_id": { + "name": "_city_id", "type": "column", "hideable": True, "toggle_url": "/", @@ -118,28 +118,28 @@ async def test_column_facet_results(app_client): "value": 1, "label": "San Francisco", "count": 6, - "toggle_url": "http://localhost/?_facet=city_id&city_id=1", + "toggle_url": "http://localhost/?_facet=_city_id&_city_id__exact=1", "selected": False, }, { "value": 2, "label": "Los Angeles", "count": 4, - "toggle_url": "http://localhost/?_facet=city_id&city_id=2", + "toggle_url": "http://localhost/?_facet=_city_id&_city_id__exact=2", "selected": False, }, { "value": 3, "label": "Detroit", "count": 4, - "toggle_url": "http://localhost/?_facet=city_id&city_id=3", + "toggle_url": "http://localhost/?_facet=_city_id&_city_id__exact=3", "selected": False, }, { "value": 4, "label": "Memnonia", "count": 1, - "toggle_url": "http://localhost/?_facet=city_id&city_id=4", + "toggle_url": "http://localhost/?_facet=_city_id&_city_id__exact=4", "selected": False, }, ], @@ -278,13 +278,13 @@ async def test_column_facet_from_metadata_cannot_be_hidden(app_client): database="fixtures", sql="select * from facetable", table="facetable", - metadata={"facets": ["city_id"]}, + metadata={"facets": ["_city_id"]}, ) buckets, timed_out = await facet.facet_results() assert [] == timed_out assert { - "city_id": { - "name": "city_id", + "_city_id": { + "name": "_city_id", "type": "column", "hideable": False, "toggle_url": "/", @@ -293,28 +293,28 @@ async def test_column_facet_from_metadata_cannot_be_hidden(app_client): "value": 1, "label": "San Francisco", "count": 6, - "toggle_url": "http://localhost/?city_id=1", + "toggle_url": "http://localhost/?_city_id__exact=1", "selected": False, }, { "value": 2, "label": "Los Angeles", "count": 4, - "toggle_url": "http://localhost/?city_id=2", + "toggle_url": "http://localhost/?_city_id__exact=2", "selected": False, }, { "value": 3, "label": "Detroit", "count": 4, - "toggle_url": "http://localhost/?city_id=3", + "toggle_url": "http://localhost/?_city_id__exact=3", "selected": False, }, { "value": 4, "label": "Memnonia", "count": 1, - "toggle_url": "http://localhost/?city_id=4", + "toggle_url": "http://localhost/?_city_id__exact=4", "selected": False, }, ], diff --git a/tests/test_html.py b/tests/test_html.py index 179c3f09..aaf7da09 100644 --- a/tests/test_html.py +++ b/tests/test_html.py @@ -487,7 +487,7 @@ def test_sort_links(app_client): def test_facet_display(app_client): response = app_client.get( - "/fixtures/facetable?_facet=planet_int&_facet=city_id&_facet=on_earth" + "/fixtures/facetable?_facet=planet_int&_facet=_city_id&_facet=on_earth" ) assert response.status == 200 soup = Soup(response.body, "html.parser") @@ -509,26 +509,26 @@ def test_facet_display(app_client): ) assert actual == [ { - "name": "city_id", + "name": "_city_id", "items": [ { "name": "San Francisco", - "qs": "_facet=planet_int&_facet=city_id&_facet=on_earth&city_id=1", + "qs": "_facet=planet_int&_facet=_city_id&_facet=on_earth&_city_id__exact=1", "count": 6, }, { "name": "Los Angeles", - "qs": "_facet=planet_int&_facet=city_id&_facet=on_earth&city_id=2", + "qs": "_facet=planet_int&_facet=_city_id&_facet=on_earth&_city_id__exact=2", "count": 4, }, { "name": "Detroit", - "qs": "_facet=planet_int&_facet=city_id&_facet=on_earth&city_id=3", + "qs": "_facet=planet_int&_facet=_city_id&_facet=on_earth&_city_id__exact=3", "count": 4, }, { "name": "Memnonia", - "qs": "_facet=planet_int&_facet=city_id&_facet=on_earth&city_id=4", + "qs": "_facet=planet_int&_facet=_city_id&_facet=on_earth&_city_id__exact=4", "count": 1, }, ], @@ -538,12 +538,12 @@ def test_facet_display(app_client): "items": [ { "name": "1", - "qs": "_facet=planet_int&_facet=city_id&_facet=on_earth&planet_int=1", + "qs": "_facet=planet_int&_facet=_city_id&_facet=on_earth&planet_int=1", "count": 14, }, { "name": "2", - "qs": "_facet=planet_int&_facet=city_id&_facet=on_earth&planet_int=2", + "qs": "_facet=planet_int&_facet=_city_id&_facet=on_earth&planet_int=2", "count": 1, }, ], @@ -553,12 +553,12 @@ def test_facet_display(app_client): "items": [ { "name": "1", - "qs": "_facet=planet_int&_facet=city_id&_facet=on_earth&on_earth=1", + "qs": "_facet=planet_int&_facet=_city_id&_facet=on_earth&on_earth=1", "count": 14, }, { "name": "0", - "qs": "_facet=planet_int&_facet=city_id&_facet=on_earth&on_earth=0", + "qs": "_facet=planet_int&_facet=_city_id&_facet=on_earth&on_earth=0", "count": 1, }, ], @@ -568,14 +568,14 @@ def test_facet_display(app_client): def test_facets_persist_through_filter_form(app_client): response = app_client.get( - "/fixtures/facetable?_facet=planet_int&_facet=city_id&_facet_array=tags" + "/fixtures/facetable?_facet=planet_int&_facet=_city_id&_facet_array=tags" ) assert response.status == 200 inputs = Soup(response.body, "html.parser").find("form").findAll("input") hiddens = [i for i in inputs if i["type"] == "hidden"] assert [(hidden["name"], hidden["value"]) for hidden in hiddens] == [ ("_facet", "planet_int"), - ("_facet", "city_id"), + ("_facet", "_city_id"), ("_facet_array", "tags"), ] @@ -1350,20 +1350,20 @@ def test_canned_query_show_hide_metadata_option( def test_extra_where_clauses(app_client): response = app_client.get( - "/fixtures/facetable?_where=_neighborhood='Dogpatch'&_where=city_id=1" + "/fixtures/facetable?_where=_neighborhood='Dogpatch'&_where=_city_id=1" ) soup = Soup(response.body, "html.parser") div = soup.select(".extra-wheres")[0] assert "2 extra where clauses" == div.find("h3").text hrefs = [a["href"] for a in div.findAll("a")] assert [ - "/fixtures/facetable?_where=city_id%3D1", + "/fixtures/facetable?_where=_city_id%3D1", "/fixtures/facetable?_where=_neighborhood%3D%27Dogpatch%27", ] == hrefs # These should also be persisted as hidden fields inputs = soup.find("form").findAll("input") hiddens = [i for i in inputs if i["type"] == "hidden"] - assert [("_where", "_neighborhood='Dogpatch'"), ("_where", "city_id=1")] == [ + assert [("_where", "_neighborhood='Dogpatch'"), ("_where", "_city_id=1")] == [ (hidden["name"], hidden["value"]) for hidden in hiddens ] @@ -1683,11 +1683,11 @@ def test_base_url_affects_metadata_extra_css_urls(app_client_base_url_prefix): [ ( "/fixtures/neighborhood_search", - "/fixtures?sql=%0Aselect+_neighborhood%2C+facet_cities.name%2C+state%0Afrom+facetable%0A++++join+facet_cities%0A++++++++on+facetable.city_id+%3D+facet_cities.id%0Awhere+_neighborhood+like+%27%25%27+%7C%7C+%3Atext+%7C%7C+%27%25%27%0Aorder+by+_neighborhood%3B%0A&text=", + "/fixtures?sql=%0Aselect+_neighborhood%2C+facet_cities.name%2C+state%0Afrom+facetable%0A++++join+facet_cities%0A++++++++on+facetable._city_id+%3D+facet_cities.id%0Awhere+_neighborhood+like+%27%25%27+%7C%7C+%3Atext+%7C%7C+%27%25%27%0Aorder+by+_neighborhood%3B%0A&text=", ), ( "/fixtures/neighborhood_search?text=ber", - "/fixtures?sql=%0Aselect+_neighborhood%2C+facet_cities.name%2C+state%0Afrom+facetable%0A++++join+facet_cities%0A++++++++on+facetable.city_id+%3D+facet_cities.id%0Awhere+_neighborhood+like+%27%25%27+%7C%7C+%3Atext+%7C%7C+%27%25%27%0Aorder+by+_neighborhood%3B%0A&text=ber", + "/fixtures?sql=%0Aselect+_neighborhood%2C+facet_cities.name%2C+state%0Afrom+facetable%0A++++join+facet_cities%0A++++++++on+facetable._city_id+%3D+facet_cities.id%0Awhere+_neighborhood+like+%27%25%27+%7C%7C+%3Atext+%7C%7C+%27%25%27%0Aorder+by+_neighborhood%3B%0A&text=ber", ), ("/fixtures/pragma_cache_size", None), ( diff --git a/tests/test_internals_database.py b/tests/test_internals_database.py index 2d0cae7f..a00fe447 100644 --- a/tests/test_internals_database.py +++ b/tests/test_internals_database.py @@ -81,7 +81,7 @@ async def test_table_exists(db, tables, exists): "planet_int", "on_earth", "state", - "city_id", + "_city_id", "_neighborhood", "tags", "complex_array", @@ -161,7 +161,7 @@ async def test_table_columns(db, table, expected): ), Column( cid=5, - name="city_id", + name="_city_id", type="integer", notnull=0, default_value=None, diff --git a/tests/test_plugins.py b/tests/test_plugins.py index 697a6b32..1da28453 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -436,7 +436,7 @@ def test_hook_register_output_renderer_all_parameters(app_client): "planet_int", "on_earth", "state", - "city_id", + "_city_id", "_neighborhood", "tags", "complex_array", @@ -459,7 +459,7 @@ def test_hook_register_output_renderer_all_parameters(app_client): "", "", ], - "sql": "select pk, created, planet_int, on_earth, state, city_id, _neighborhood, tags, complex_array, distinct_some_null from facetable order by pk limit 51", + "sql": "select pk, created, planet_int, on_earth, state, _city_id, _neighborhood, tags, complex_array, distinct_some_null from facetable order by pk limit 51", "query_name": None, "database": "fixtures", "table": "facetable", @@ -525,13 +525,13 @@ def test_hook_register_output_renderer_can_render(app_client): "planet_int", "on_earth", "state", - "city_id", + "_city_id", "_neighborhood", "tags", "complex_array", "distinct_some_null", ], - "sql": "select pk, created, planet_int, on_earth, state, city_id, _neighborhood, tags, complex_array, distinct_some_null from facetable order by pk limit 51", + "sql": "select pk, created, planet_int, on_earth, state, _city_id, _neighborhood, tags, complex_array, distinct_some_null from facetable order by pk limit 51", "query_name": None, "database": "fixtures", "table": "facetable",