Cleanup utils

This commit is contained in:
Thomas Sileo 2022-06-22 21:15:07 +02:00
parent b7b04cad03
commit f9f9e62e13
13 changed files with 21 additions and 13 deletions

View file

@ -1,16 +1,20 @@
import typing
import starlette
from fastapi.testclient import TestClient
from app.main import app
def test_admin_endpoints_are_authenticated(client: TestClient):
def test_admin_endpoints_are_authenticated(client: TestClient) -> None:
routes_tested = []
for route in app.routes:
route = typing.cast(starlette.routing.Route, route)
if not route.path.startswith("/admin") or route.path == "/admin/login":
continue
for method in route.methods:
for method in route.methods: # type: ignore
resp = client.request(method, route.path)
# Admin routes should redirect to the login page

View file

@ -55,7 +55,6 @@ def test_enforce_httpsig__no_signature(
@pytest.mark.asyncio
async def test_enforce_httpsig__with_valid_signature(
client: TestClient,
respx_mock: respx.MockRouter,
) -> None:
# Given a remote actor
@ -105,7 +104,6 @@ def test_httpsig_checker__no_signature(
@pytest.mark.asyncio
async def test_httpsig_checker__with_valid_signature(
client: TestClient,
respx_mock: respx.MockRouter,
) -> None:
# Given a remote actor
@ -138,7 +136,6 @@ async def test_httpsig_checker__with_valid_signature(
@pytest.mark.asyncio
async def test_httpsig_checker__with_invvalid_signature(
client: TestClient,
respx_mock: respx.MockRouter,
) -> None:
# Given a remote actor

View file

@ -44,6 +44,9 @@ def test_new_outgoing_activity(
outbox_object = _setup_outbox_object()
inbox_url = "https://example.com/inbox"
if not outbox_object.id:
raise ValueError("Should never happen")
# When queuing the activity
outgoing_activity = new_outgoing_activity(db, inbox_url, outbox_object.id)

View file

@ -1,4 +1,5 @@
from contextlib import contextmanager
from typing import Any
import fastapi
@ -25,5 +26,5 @@ def mock_httpsig_checker(ra: actor.RemoteActor):
del app.dependency_overrides[httpsig.httpsig_checker]
def generate_admin_session_cookies() -> dict[str, str]:
def generate_admin_session_cookies() -> dict[str, Any]:
return {"session": session_serializer.dumps({"is_logged_in": True})}