mirror of
https://git.sr.ht/~tsileo/microblog.pub
synced 2024-12-21 12:44:27 +00:00
Cleanup utils
This commit is contained in:
parent
b7b04cad03
commit
f9f9e62e13
13 changed files with 21 additions and 13 deletions
|
@ -1,5 +1,6 @@
|
|||
import typing
|
||||
from dataclasses import dataclass
|
||||
from typing import Union
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
@ -148,7 +149,7 @@ ActorsMetadata = dict[str, ActorMetadata]
|
|||
|
||||
def get_actors_metadata(
|
||||
db: Session,
|
||||
actors: list["ActorModel"],
|
||||
actors: list[Union["ActorModel", "RemoteActor"]],
|
||||
) -> ActorsMetadata:
|
||||
from app import models
|
||||
|
||||
|
@ -179,6 +180,8 @@ def get_actors_metadata(
|
|||
}
|
||||
idx: ActorsMetadata = {}
|
||||
for actor in actors:
|
||||
if not actor.ap_id:
|
||||
raise ValueError("Should never happen")
|
||||
idx[actor.ap_id] = ActorMetadata(
|
||||
ap_actor_id=actor.ap_id,
|
||||
is_following=actor.ap_id in following,
|
||||
|
|
|
@ -72,9 +72,9 @@ def get_lookup(
|
|||
if query:
|
||||
ap_object = lookup(db, query)
|
||||
if ap_object.ap_type in ap.ACTOR_TYPES:
|
||||
actors_metadata = get_actors_metadata(db, [ap_object])
|
||||
actors_metadata = get_actors_metadata(db, [ap_object]) # type: ignore
|
||||
else:
|
||||
actors_metadata = get_actors_metadata(db, [ap_object.actor])
|
||||
actors_metadata = get_actors_metadata(db, [ap_object.actor]) # type: ignore
|
||||
print(ap_object)
|
||||
return templates.render_template(
|
||||
db,
|
||||
|
|
|
@ -7,10 +7,10 @@ from dateutil.parser import isoparse
|
|||
from markdown import markdown
|
||||
|
||||
from app import activitypub as ap
|
||||
from app import opengraph
|
||||
from app.actor import LOCAL_ACTOR
|
||||
from app.actor import Actor
|
||||
from app.actor import RemoteActor
|
||||
from app.utils import opengraph
|
||||
|
||||
|
||||
class Object:
|
||||
|
|
|
@ -23,8 +23,8 @@ from app.config import VERSION
|
|||
from app.config import generate_csrf_token
|
||||
from app.config import session_serializer
|
||||
from app.database import now
|
||||
from app.highlight import HIGHLIGHT_CSS
|
||||
from app.highlight import highlight
|
||||
from app.utils.highlight import HIGHLIGHT_CSS
|
||||
from app.utils.highlight import highlight
|
||||
|
||||
_templates = Jinja2Templates(directory="app/templates")
|
||||
|
||||
|
|
0
app/utils/__init__.py
Normal file
0
app/utils/__init__.py
Normal file
|
@ -8,7 +8,7 @@ from pydantic import BaseModel
|
|||
|
||||
from app import activitypub as ap
|
||||
from app import config
|
||||
from app.urlutils import is_url_valid
|
||||
from app.utils.url import is_url_valid
|
||||
|
||||
|
||||
class OpenGraphMeta(BaseModel):
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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})}
|
||||
|
|
Loading…
Reference in a new issue