From c21a792b2b584ff736c997af5f5839713734e70b Mon Sep 17 00:00:00 2001 From: southfox Date: Thu, 27 Apr 2023 11:18:03 +0800 Subject: [PATCH] [tests] add undo test --- tests/test_inbox.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/tests/test_inbox.py b/tests/test_inbox.py index c806271..3db3d6f 100644 --- a/tests/test_inbox.py +++ b/tests/test_inbox.py @@ -40,13 +40,14 @@ def test_inbox_follow_request( # send follower request with mock.patch("app.boxes.MANUALLY_APPROVES_FOLLOWERS", False): + follow_id = ap_id + "/follow/" + (uuid4().hex) response = client.post( "/inbox", headers={"Content-Type": AP_CONTENT_TYPE}, json={ "@context": ap.AS_CTX, "type": "Follow", - "id": ap_id + "/follow/" + (uuid4().hex), + "id": follow_id, "actor": ap_id, "object": ap.ME["id"], }, @@ -65,6 +66,31 @@ def test_inbox_follow_request( follower_actor = db.execute(select(models.Follower)).scalar_one() assert follower_actor.ap_actor_id == ap_id + # send undo follower request + with mock.patch("app.boxes.MANUALLY_APPROVES_FOLLOWERS", False): + undo_id = ap_id + "/undo/" + (uuid4().hex) + response = client.post( + "/inbox", + headers={"Content-Type": AP_CONTENT_TYPE}, + json={ + "@context": ap.AS_CTX, + "type": "Undo", + "id": undo_id, + "actor": ap_id, + "object": { + "type": "Follow", + "id": follow_id, + "actor": ap_id, + "object": ap.ME["id"], + }, + }, + ) + assert response.status_code == 202 + + # follower was not saved in follower table + follower_actor = db.execute(select(models.Follower)).scalar_one_or_none() + assert follower_actor == None + def test_inbox_announce_request( db: Session,