diff tests/unit/test_ap-gateway.py @ 3981:acc9dfc8ba8d

component AP gateway: parse body immediately on `POST` request: the body is parsed immediately during a `POST` request: this avoids duplication of code, and allows to check the body data before continuing (will be used to filter some requests in a future patch).
author Goffi <goffi@goffi.org>
date Tue, 15 Nov 2022 18:07:34 +0100
parents d43b197735d1
children 69d970f974ff
line wrap: on
line diff
--- a/tests/unit/test_ap-gateway.py	Tue Nov 15 18:03:07 2022 +0100
+++ b/tests/unit/test_ap-gateway.py	Tue Nov 15 18:07:34 2022 +0100
@@ -629,7 +629,7 @@
         ap_gateway,
         type_: Optional[str] = None,
         url: Optional[str] = None,
-        doc: Optional[Any] = None,
+        data: Optional[dict] = None,
         query_data: Optional[dict] = None,
         signing_actor: Optional[str] = None,
     ) -> Dict[str, Any]:
@@ -637,8 +637,7 @@
 
         @param type_: one of the AP query type (e.g. "outbox")
         @param url: URL to query (mutually exclusif with type_)
-        @param doc: if set, a document to embed in content of the request (will be
-        converted to JSON)
+        @param data: object used as body of the request
         @param query_data: query data as returned by parse.parse_qs
         @return dict with kw params to use
         """
@@ -661,12 +660,11 @@
         request = Request(MagicMock())
         request.path = path.encode()
         request.uri = uri.encode()
-        if doc is not None:
-            request.content = io.BytesIO(json.dumps(doc).encode())
 
         ap_url = parse.urljoin(f"https://{ap_gateway.public_url}", path)
         kwargs = {
             "request": request,
+            "data": data,
             "account_jid": test_jid,
             "node": None,
             "ap_account": test_jid.full(),
@@ -1510,7 +1508,7 @@
             with patch.object(ap_gateway._p, "sendItems") as sendItems:
                 await ap_gateway.server.resource.APInboxRequest(
                     **self.ap_request_params(
-                        ap_gateway, "inbox", doc=like, signing_actor=TEST_AP_ACTOR_ID
+                        ap_gateway, "inbox", data=like, signing_actor=TEST_AP_ACTOR_ID
                     )
                 )
 
@@ -1614,7 +1612,7 @@
             with patch.object(ap_gateway._p, "sendItems") as sendItems:
                 await ap_gateway.server.resource.APInboxRequest(
                     **self.ap_request_params(
-                        ap_gateway, "inbox", doc=like, signing_actor=TEST_AP_ACTOR_ID
+                        ap_gateway, "inbox", data=like, signing_actor=TEST_AP_ACTOR_ID
                     )
                 )