From 0d690add7986b46b2707cb6026df2a0d226fd3f9 Mon Sep 17 00:00:00 2001 From: southfox Date: Mon, 8 May 2023 14:34:27 +0800 Subject: [PATCH] [tests] add like activity test --- tests/test_inbox.py | 69 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/tests/test_inbox.py b/tests/test_inbox.py index c7598f4..39c587e 100644 --- a/tests/test_inbox.py +++ b/tests/test_inbox.py @@ -153,3 +153,72 @@ def test_inbox_announce_activity( saved_note = db.execute(select(models.OutboxObject)).scalar_one() print(saved_note.ap_id) assert saved_note.announces_count == 1 + + +def test_inbox_like_activity( + db: Session, + client: TestClient, + respx_mock: respx.MockRouter, +) -> None: + # build test actor + 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)) + respx_mock.post(ap_id + "/inbox").mock(return_value=httpx.Response(202)) + + from app.models import now + from app.activitypub import VisibilityEnum + + note_id = ap.ME["id"] + (uuid4().hex) + published = now().replace(microsecond=0).isoformat().replace("+00:00", "Z") + note_object = { + "@context": ap.AS_EXTENDED_CTX, + "type": "Note", + "id": note_id, + "attributedTo": ap.ME["id"], + "content": "

Test!

", + "to": [ap.AS_PUBLIC], + "cc": [], + "published": published, + # "context": context, + # "conversation": context, + "url": note_id, + "tag": [], + "summary": None, + "inReplyTo": None, + "sensitive": False, + "attachment": [], + } + + outbox_object = models.OutboxObject( + public_id=note_id, + ap_object=note_object, + ap_id=note_id, + ap_type="Note", + visibility =VisibilityEnum.PUBLIC, + ) + + db.add(outbox_object) + db.commit() + + # send announce request + response = client.post( + "/inbox", + headers={"Content-Type": AP_CONTENT_TYPE}, + json={ + "@context": ap.AS_CTX, + "type": "Like", + "id": ap_id + "/like/" + (uuid4().hex), + "actor": ap_id, + "object": note_id, + }, + ) + assert response.status_code == 202 + + saved_note = db.execute(select(models.OutboxObject)).scalar_one() + print(saved_note.ap_id) + assert saved_note.likes_count == 1