[tests] add outbox create test
This commit is contained in:
parent
6d28cccaf6
commit
7fbb4bbd81
1 changed files with 46 additions and 0 deletions
|
@ -50,3 +50,49 @@ async def test_outbox_send_follow_request(
|
||||||
outbox_object = db.execute(select(models.OutboxObject)).scalar_one()
|
outbox_object = db.execute(select(models.OutboxObject)).scalar_one()
|
||||||
assert outbox_object.ap_type == "Follow"
|
assert outbox_object.ap_type == "Follow"
|
||||||
assert outbox_object.activity_object_ap_id == remote_ap_id
|
assert outbox_object.activity_object_ap_id == remote_ap_id
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_outbox_send_create_activity(
|
||||||
|
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_create
|
||||||
|
from app.activitypub import VisibilityEnum
|
||||||
|
from app.orgpython import to_html
|
||||||
|
|
||||||
|
async with async_session() as db_session: #type: ignore
|
||||||
|
content = "*Blod Text* =code Text= \n"
|
||||||
|
content = to_html(content)
|
||||||
|
|
||||||
|
await _send_create(
|
||||||
|
db_session,
|
||||||
|
"Note",
|
||||||
|
content,
|
||||||
|
VisibilityEnum.PUBLIC
|
||||||
|
)
|
||||||
|
|
||||||
|
# And the Follow activity was created in the outbox
|
||||||
|
outbox_object = db.execute(select(models.OutboxObject)).scalar_one()
|
||||||
|
assert outbox_object.ap_type == "Note"
|
||||||
|
print(outbox_object.ap_object["content"])
|
||||||
|
assert outbox_object.ap_object["content"] == content
|
||||||
|
|
Loading…
Reference in a new issue