Skip to content

Commit

Permalink
tests: Adapt url assertion to respect HTTP method(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasjuhrich committed May 17, 2024
1 parent d277bb1 commit e364506
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
7 changes: 5 additions & 2 deletions tests/frontend/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,13 @@ def config(module_session: Session) -> Config:

@pytest.fixture(scope="session")
def blueprint_urls(app: PycroftFlask) -> BlueprintUrls:
def _blueprint_urls(blueprint_name: str) -> list[str]:
def _blueprint_urls(
blueprint_name: str, methods: set[str] = {"GET", "POST"} # noqa: B006
) -> list[str]:
return [
_build_rule(request_ctx.url_adapter, rule)
(_build_rule(request_ctx.url_adapter, rule), method)
for rule in app.url_map.iter_rules()
for method in rule.methods & methods
if rule.endpoint.startswith(f"{blueprint_name}.")
]
return _blueprint_urls
Expand Down
2 changes: 1 addition & 1 deletion tests/frontend/fixture_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def login_context(test_client: TestClient, login: str, password: str):
test_client.get("/logout")


BlueprintUrls: t.TypeAlias = t.Callable[[str], list[str]]
BlueprintUrls: t.TypeAlias = t.Callable[[str], list[str, str]]
_argument_creator_map = {
IntegerConverter: lambda c: 1,
UnicodeConverter: lambda c: "test",
Expand Down
20 changes: 10 additions & 10 deletions tests/frontend/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,26 +104,26 @@ def member_logged_in(
yield

def test_access_user(self, client: TestClient, blueprint_urls: BlueprintUrls):
for url in blueprint_urls("user"):
client.assert_url_forbidden(url)
for url, method in blueprint_urls("user"):
client.assert_url_forbidden(url, method=method)

def test_access_finance(self, client: TestClient, blueprint_urls: BlueprintUrls):
for url in blueprint_urls("finance"):
client.assert_url_forbidden(url)
for url, method in blueprint_urls("finance"):
client.assert_url_forbidden(url, method=method)

def test_access_buildings(self, client: TestClient, blueprint_urls: BlueprintUrls):
for url in blueprint_urls("facilities"):
client.assert_url_forbidden(url)
for url, method in blueprint_urls("facilities"):
client.assert_url_forbidden(url, method=method)

def test_access_infrastructure(
self, client: TestClient, blueprint_urls: BlueprintUrls
):
for url in blueprint_urls("infrastructure"):
client.assert_url_forbidden(url)
for url, method in blueprint_urls("infrastructure"):
client.assert_url_forbidden(url, method=method)

def test_access_properties(self, client: TestClient, blueprint_urls: BlueprintUrls):
for url in blueprint_urls("properties"):
client.assert_url_forbidden(url)
for url, method in blueprint_urls("properties"):
client.assert_url_forbidden(url, method=method)

def test_access_login(self, client: TestClient, blueprint_urls: BlueprintUrls):
# Login see Test_010_Anonymous
Expand Down

0 comments on commit e364506

Please sign in to comment.