Skip to content

Commit

Permalink
test_routes also now asserts matches, refs #1666
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Mar 19, 2022
1 parent 711767b commit 764738d
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,34 @@ def routes():


@pytest.mark.parametrize(
"path,expected",
"path,expected_class,expected_matches",
(
("/", "IndexView"),
("/foo", "DatabaseView"),
("/foo.csv", "DatabaseView"),
("/foo.json", "DatabaseView"),
("/foo.humbug", "DatabaseView"),
("/foo/humbug", "TableView"),
("/foo/humbug.json", "TableView"),
("/foo/humbug.blah", "TableView"),
("/foo/humbug/1", "RowView"),
("/foo/humbug/1.json", "RowView"),
("/-/metadata.json", "JsonDataView"),
("/-/metadata", "JsonDataView"),
("/", "IndexView", {"as_format": ""}),
("/foo", "DatabaseView", {"as_format": None, "db_name": "foo"}),
("/foo.csv", "DatabaseView", {"as_format": ".csv", "db_name": "foo"}),
("/foo.json", "DatabaseView", {"as_format": ".json", "db_name": "foo"}),
("/foo.humbug", "DatabaseView", {"as_format": None, "db_name": "foo.humbug"}),
("/foo/humbug", "TableView", {"db_name": "foo", "table": "humbug"}),
("/foo/humbug.json", "TableView", {"db_name": "foo", "table": "humbug"}),
("/foo/humbug.blah", "TableView", {"db_name": "foo", "table": "humbug"}),
(
"/foo/humbug/1",
"RowView",
{"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)
if expected is None:
if expected_class is None:
assert match is None
else:
assert view.view_class.__name__ == expected
assert view.view_class.__name__ == expected_class
assert match.groupdict() == expected_matches

1 comment on commit 764738d

@simonw
Copy link
Owner Author

@simonw simonw commented on 764738d Mar 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also refs #1667 and #1660.

Please sign in to comment.