mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
test_routes also now asserts matches, refs #1666
This commit is contained in:
parent
711767bcd3
commit
764738dfcb
1 changed files with 25 additions and 16 deletions
|
|
@ -10,25 +10,34 @@ def routes():
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path,expected",
|
"path,expected_class,expected_matches",
|
||||||
(
|
(
|
||||||
("/", "IndexView"),
|
("/", "IndexView", {"as_format": ""}),
|
||||||
("/foo", "DatabaseView"),
|
("/foo", "DatabaseView", {"as_format": None, "db_name": "foo"}),
|
||||||
("/foo.csv", "DatabaseView"),
|
("/foo.csv", "DatabaseView", {"as_format": ".csv", "db_name": "foo"}),
|
||||||
("/foo.json", "DatabaseView"),
|
("/foo.json", "DatabaseView", {"as_format": ".json", "db_name": "foo"}),
|
||||||
("/foo.humbug", "DatabaseView"),
|
("/foo.humbug", "DatabaseView", {"as_format": None, "db_name": "foo.humbug"}),
|
||||||
("/foo/humbug", "TableView"),
|
("/foo/humbug", "TableView", {"db_name": "foo", "table": "humbug"}),
|
||||||
("/foo/humbug.json", "TableView"),
|
("/foo/humbug.json", "TableView", {"db_name": "foo", "table": "humbug"}),
|
||||||
("/foo/humbug.blah", "TableView"),
|
("/foo/humbug.blah", "TableView", {"db_name": "foo", "table": "humbug"}),
|
||||||
("/foo/humbug/1", "RowView"),
|
(
|
||||||
("/foo/humbug/1.json", "RowView"),
|
"/foo/humbug/1",
|
||||||
("/-/metadata.json", "JsonDataView"),
|
"RowView",
|
||||||
("/-/metadata", "JsonDataView"),
|
{"as_format": None, "db_name": "foo", "pk_path": "1", "table": "humbug"},
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"/foo/humbug/1.json",
|
||||||
|
"RowView",
|
||||||
|
{"as_format": ".json", "db_name": "foo", "pk_path": "1", "table": "humbug"},
|
||||||
|
),
|
||||||
|
("/-/metadata.json", "JsonDataView", {"as_format": ".json"}),
|
||||||
|
("/-/metadata", "JsonDataView", {"as_format": ""}),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
def test_routes(routes, path, expected):
|
def test_routes(routes, path, expected_class, expected_matches):
|
||||||
match, view = resolve_routes(routes, path)
|
match, view = resolve_routes(routes, path)
|
||||||
if expected is None:
|
if expected_class is None:
|
||||||
assert match is None
|
assert match is None
|
||||||
else:
|
else:
|
||||||
assert view.view_class.__name__ == expected
|
assert view.view_class.__name__ == expected_class
|
||||||
|
assert match.groupdict() == expected_matches
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue