Consistent treatment of format in route capturing, refs #1667

Also refs #1660
This commit is contained in:
Simon Willison 2022-03-19 13:29:10 -07:00
commit b9c2b1cfc8
3 changed files with 36 additions and 30 deletions

View file

@ -629,8 +629,8 @@ def test_old_memory_urls_redirect(app_client_no_files, path, expected_redirect):
def test_database_page_for_database_with_dot_in_name(app_client_with_dot):
response = app_client_with_dot.get("/fixtures.dot.json")
assert 200 == response.status
response = app_client_with_dot.get("/fixtures~2Edot.json")
assert response.status == 200
def test_custom_sql(app_client):

View file

@ -12,14 +12,26 @@ def routes():
@pytest.mark.parametrize(
"path,expected_class,expected_matches",
(
("/", "IndexView", {"format": ""}),
("/", "IndexView", {"format": None}),
("/foo", "DatabaseView", {"format": None, "database": "foo"}),
("/foo.csv", "DatabaseView", {"format": ".csv", "database": "foo"}),
("/foo.json", "DatabaseView", {"format": ".json", "database": "foo"}),
("/foo.humbug", "DatabaseView", {"format": None, "database": "foo.humbug"}),
("/foo/humbug", "TableView", {"database": "foo", "table": "humbug"}),
("/foo/humbug.json", "TableView", {"database": "foo", "table": "humbug"}),
("/foo/humbug.blah", "TableView", {"database": "foo", "table": "humbug"}),
("/foo.csv", "DatabaseView", {"format": "csv", "database": "foo"}),
("/foo.json", "DatabaseView", {"format": "json", "database": "foo"}),
("/foo.humbug", "DatabaseView", {"format": "humbug", "database": "foo"}),
(
"/foo/humbug",
"TableView",
{"database": "foo", "table": "humbug", "format": None},
),
(
"/foo/humbug.json",
"TableView",
{"database": "foo", "table": "humbug", "format": "json"},
),
(
"/foo/humbug.blah",
"TableView",
{"database": "foo", "table": "humbug", "format": "blah"},
),
(
"/foo/humbug/1",
"RowView",
@ -28,10 +40,10 @@ def routes():
(
"/foo/humbug/1.json",
"RowView",
{"format": ".json", "database": "foo", "pks": "1", "table": "humbug"},
{"format": "json", "database": "foo", "pks": "1", "table": "humbug"},
),
("/-/metadata.json", "JsonDataView", {"format": ".json"}),
("/-/metadata", "JsonDataView", {"format": ""}),
("/-/metadata.json", "JsonDataView", {"format": "json"}),
("/-/metadata", "JsonDataView", {"format": None}),
),
)
def test_routes(routes, path, expected_class, expected_matches):