microblog.pub/tests/utils.py

31 lines
783 B
Python
Raw Normal View History

2022-06-22 20:11:22 +02:00
from contextlib import contextmanager
2022-06-22 21:15:07 +02:00
from typing import Any
2022-06-22 20:11:22 +02:00
import fastapi
from app import actor
from app import httpsig
from app.config import session_serializer
from app.main import app
@contextmanager
def mock_httpsig_checker(ra: actor.RemoteActor):
async def httpsig_checker(
request: fastapi.Request,
) -> httpsig.HTTPSigInfo:
return httpsig.HTTPSigInfo(
has_valid_signature=True,
signed_by_ap_actor_id=ra.ap_id,
)
app.dependency_overrides[httpsig.httpsig_checker] = httpsig_checker
try:
yield
finally:
del app.dependency_overrides[httpsig.httpsig_checker]
2022-06-22 21:15:07 +02:00
def generate_admin_session_cookies() -> dict[str, Any]:
2022-06-22 20:11:22 +02:00
return {"session": session_serializer.dumps({"is_logged_in": True})}