diff --git a/tests/test_inbox.py b/tests/test_inbox.py index 3db3d6f..5033bb2 100644 --- a/tests/test_inbox.py +++ b/tests/test_inbox.py @@ -5,6 +5,7 @@ import respx import httpx from uuid import uuid4 from tests import factories +from tests.utils import build_remote_actor from unittest import mock from app.main import app @@ -25,14 +26,8 @@ def test_inbox_follow_request( ) -> None: # build test actor - ra = factories.RemoteActorFactory( - base_url="https://example.com", - username="test", - public_key="pk", - ) - + ra = build_remote_actor() ap_id = ra.ap_id # type: ignore - app.dependency_overrides[precheck.inbox_prechecker] = factories.inbox_prechecker # mock request respx_mock.get(ap_id).mock(return_value=httpx.Response(200,json=ra.ap_actor)) @@ -99,11 +94,7 @@ def test_inbox_announce_request( ) -> None: # build test actor - ra = factories.RemoteActorFactory( - base_url="https://example.com", - username="test", - public_key="pk", - ) + ra = build_remote_actor() ap_id = ra.ap_id # type: ignore app.dependency_overrides[precheck.inbox_prechecker] = factories.inbox_prechecker diff --git a/tests/test_outbox.py b/tests/test_outbox.py index f85d341..51f094e 100644 --- a/tests/test_outbox.py +++ b/tests/test_outbox.py @@ -5,6 +5,7 @@ import respx import httpx from uuid import uuid4 from tests import factories +from tests.utils import build_remote_actor from unittest import mock from app.main import app @@ -24,15 +25,8 @@ async def test_outbox_send_follow_request( respx_mock: respx.MockRouter, ) -> None: # build test actor - ra = factories.RemoteActorFactory( - base_url="https://example.com", - username="test", - public_key="pk", - ) - + ra = build_remote_actor() remote_ap_id = ra.ap_id # type: ignore - app.dependency_overrides[precheck.inbox_prechecker] = \ - factories.inbox_prechecker # mock request respx_mock.get(remote_ap_id).mock( @@ -59,15 +53,8 @@ async def test_outbox_send_create_activity( respx_mock: respx.MockRouter, ) -> None: # build test actor - ra = factories.RemoteActorFactory( - base_url="https://example.com", - username="test", - public_key="pk", - ) - + ra = build_remote_actor() remote_ap_id = ra.ap_id # type: ignore - app.dependency_overrides[precheck.inbox_prechecker] = \ - factories.inbox_prechecker # mock request respx_mock.get(remote_ap_id).mock( diff --git a/tests/utils.py b/tests/utils.py new file mode 100644 index 0000000..258cc3a --- /dev/null +++ b/tests/utils.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 +from tests import factories +from app.main import app +from app.utils import precheck + + + +def build_remote_actor(): + ra = factories.RemoteActorFactory( + base_url="https://example.com", + username="test", + public_key="pk", + ) + + app.dependency_overrides[precheck.inbox_prechecker] = \ + factories.inbox_prechecker + + return ra