[tests] add follow outbox test
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
SouthFox 2023-04-28 15:25:00 +08:00
parent 5dccddb496
commit d814a094d9

52
tests/test_outbox.py Normal file
View file

@ -0,0 +1,52 @@
#!/usr/bin/env python3
import pytest
import fastapi
import respx
import httpx
from uuid import uuid4
from tests import factories
from unittest import mock
from app.main import app
from app.utils import precheck
from fastapi.testclient import TestClient
from sqlalchemy.orm import Session
from app import activitypub as ap, httpsig
from app.config import AP_CONTENT_TYPE
from app import models
from sqlalchemy import select
@pytest.mark.asyncio
async def test_outbox_send_follow_request(
db: Session,
client: TestClient,
respx_mock: respx.MockRouter,
) -> None:
# build test actor
ra = factories.RemoteActorFactory(
base_url="https://example.com",
username="test",
public_key="pk",
)
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(
return_value=httpx.Response(200,json=ra.ap_actor))
respx_mock.post(remote_ap_id + "/inbox").mock(
return_value=httpx.Response(202))
from app.database import async_session
from app.boxes import send_follow
async with async_session() as db_session: #type: ignore
await send_follow(db_session, remote_ap_id)
# And the Follow activity was created in the outbox
outbox_object = db.execute(select(models.OutboxObject)).scalar_one()
assert outbox_object.ap_type == "Follow"
assert outbox_object.activity_object_ap_id == remote_ap_id