33import respx
44from aioresponses import aioresponses
55from httpx import Response
6- from apkit .client import ActivityPubClient
6+ from apkit .client import ActivityPubClient
7+
8+ @pytest .fixture (scope = "session" )
9+ def shared_data ():
10+ data = {
11+ "actor_head" : {
12+ "Content-Type" : "application/activity+json" ,
13+ "vary" : "Accept-Encoding, Accept"
14+ },
15+ "actor_json" : {
16+ "@context" : ["https://www.w3.org/ns/activitystreams" ],
17+ "id" : "https://example.com/actor" ,
18+ "type" : "Application" ,
19+ "preferredUsername" : "actor" ,
20+ "inbox" : "https://example.com/actor/inbox"
21+ }
22+ }
23+ return data
724
825@respx .mock
9- def test_get_sync_success ():
26+ def test_get_sync_success (shared_data ):
1027 url = "https://example.com/actor"
11- respx .get (url ).mock (return_value = Response (200 , json = {"id" : url , "type" : "Person" }))
28+ respx .get (url ).mock (return_value = Response (
29+ 200 ,
30+ json = shared_data ["actor_json" ],
31+ headers = shared_data ["actor_head" ]
32+ ))
33+
1234 with ActivityPubClient () as client :
1335 with client .get (url ) as resp :
1436 data = resp .json ()
15- assert data ["type" ] == "Person "
37+ assert data ["type" ] == "Application "
1638 assert resp .status == 200
1739
1840@respx .mock
@@ -28,14 +50,20 @@ def test_sync_reused_error():
2850 pass
2951
3052@pytest .mark .asyncio
31- async def test_get_async_success ():
53+ async def test_get_async_success (shared_data ):
3254 url = "https://example.com/actor"
3355 with aioresponses () as m :
34- m .get (url , payload = {"id" : url , "type" : "Person" }, status = 200 )
56+ m .get (
57+ url ,
58+ payload = shared_data ["actor_json" ],
59+ headers = shared_data ["actor_head" ],
60+ status = 200
61+ )
62+
3563 async with ActivityPubClient () as client :
3664 async with client .get (url ) as resp :
3765 data = await resp .json ()
38- assert data ["type" ] == "Person "
66+ assert data ["type" ] == "Application "
3967 assert resp .status == 200
4068
4169@pytest .mark .asyncio
@@ -44,4 +72,4 @@ async def test_async_uninitialized_error():
4472 expected_msg = re .escape ("The async client session is not initialized or has been closed. Ensure you are using 'async with ActivityPubClient()'." )
4573 with pytest .raises (RuntimeError , match = expected_msg ):
4674 async with client .get ("https://example.com" ):
47- pass
75+ pass
0 commit comments