Fixed test_routes tests

pull/1999/head
Simon Willison 2023-03-20 13:03:56 -07:00
rodzic 32fd20b150
commit 395bd6bb6b
1 zmienionych plików z 9 dodań i 7 usunięć

Wyświetl plik

@ -11,7 +11,7 @@ def routes():
@pytest.mark.parametrize( @pytest.mark.parametrize(
"path,expected_class,expected_matches", "path,expected_name,expected_matches",
( (
("/", "IndexView", {"format": None}), ("/", "IndexView", {"format": None}),
("/foo", "DatabaseView", {"format": None, "database": "foo"}), ("/foo", "DatabaseView", {"format": None, "database": "foo"}),
@ -20,17 +20,17 @@ def routes():
("/foo.humbug", "DatabaseView", {"format": "humbug", "database": "foo"}), ("/foo.humbug", "DatabaseView", {"format": "humbug", "database": "foo"}),
( (
"/foo/humbug", "/foo/humbug",
"TableView", "table_view",
{"database": "foo", "table": "humbug", "format": None}, {"database": "foo", "table": "humbug", "format": None},
), ),
( (
"/foo/humbug.json", "/foo/humbug.json",
"TableView", "table_view",
{"database": "foo", "table": "humbug", "format": "json"}, {"database": "foo", "table": "humbug", "format": "json"},
), ),
( (
"/foo/humbug.blah", "/foo/humbug.blah",
"TableView", "table_view",
{"database": "foo", "table": "humbug", "format": "blah"}, {"database": "foo", "table": "humbug", "format": "blah"},
), ),
( (
@ -47,12 +47,14 @@ def routes():
("/-/metadata", "JsonDataView", {"format": None}), ("/-/metadata", "JsonDataView", {"format": None}),
), ),
) )
def test_routes(routes, path, expected_class, expected_matches): def test_routes(routes, path, expected_name, expected_matches):
match, view = resolve_routes(routes, path) match, view = resolve_routes(routes, path)
if expected_class is None: if expected_name is None:
assert match is None assert match is None
else: else:
assert view.view_class.__name__ == expected_class assert (
view.__name__ == expected_name or view.view_class.__name__ == expected_name
)
assert match.groupdict() == expected_matches assert match.groupdict() == expected_matches