[refactor] test inbox prechecker

This commit is contained in:
SouthFox 2023-04-11 16:07:35 +08:00
parent 4b2c978794
commit 9ff2d04ccf
2 changed files with 10 additions and 7 deletions

View file

@ -1,5 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import factory import factory
import fastapi
import app.activitypub as ap import app.activitypub as ap
from app import models from app import models
@ -61,3 +62,10 @@ class ActorFactory(factory.alchemy.SQLAlchemyModelFactory):
ap_type = "Person" ap_type = "Person"
ap_id = "stub" ap_id = "stub"
async def inbox_prechecker(
request: fastapi.Request,
) -> bool:
return True

View file

@ -4,7 +4,7 @@ import fastapi
import respx import respx
import httpx import httpx
from uuid import uuid4 from uuid import uuid4
from tests import factories # type: ignore from tests import factories
from unittest import mock from unittest import mock
from app.main import app from app.main import app
@ -24,11 +24,6 @@ def test_inbox_follow_request(
respx_mock: respx.MockRouter, respx_mock: respx.MockRouter,
) -> None: ) -> None:
async def inbox_prechecker(
request: fastapi.Request,
) -> bool:
return True
# build test actor # build test actor
ra = factories.RemoteActorFactory( ra = factories.RemoteActorFactory(
base_url="https://example.com", base_url="https://example.com",
@ -37,7 +32,7 @@ def test_inbox_follow_request(
) )
ap_id = ra.ap_id # type: ignore ap_id = ra.ap_id # type: ignore
app.dependency_overrides[precheck.inbox_prechecker] = inbox_prechecker app.dependency_overrides[precheck.inbox_prechecker] = factories.inbox_prechecker
# mock request # mock request
respx_mock.get(ap_id).mock(return_value=httpx.Response(200,json=ra.ap_actor)) respx_mock.get(ap_id).mock(return_value=httpx.Response(200,json=ra.ap_actor))