From 34235dd3fa56ace6fff15f41fda4741c4102475c Mon Sep 17 00:00:00 2001 From: sinisaos Date: Tue, 9 May 2023 15:25:31 +0200 Subject: [PATCH 1/2] add post event hooks --- docs/source/crud/hooks.rst | 89 +++++++++++++++++++++++++++++-- piccolo_api/crud/endpoints.py | 23 +++++++- piccolo_api/crud/hooks.py | 3 ++ tests/crud/test_crud_endpoints.py | 4 -- tests/crud/test_hooks.py | 69 ++++++++++++++++++++++++ 5 files changed, 179 insertions(+), 9 deletions(-) diff --git a/docs/source/crud/hooks.rst b/docs/source/crud/hooks.rst index 423fb2b7..b227a61b 100644 --- a/docs/source/crud/hooks.rst +++ b/docs/source/crud/hooks.rst @@ -16,6 +16,7 @@ Define a method, and register it with :class:`PiccoloCRUD Date: Wed, 10 May 2023 06:51:19 +0200 Subject: [PATCH 2/2] change post endpoint response from list to dict --- piccolo_api/crud/endpoints.py | 2 +- tests/fastapi/test_fastapi_endpoints.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/piccolo_api/crud/endpoints.py b/piccolo_api/crud/endpoints.py index 4eab5416..49015907 100644 --- a/piccolo_api/crud/endpoints.py +++ b/piccolo_api/crud/endpoints.py @@ -918,7 +918,7 @@ async def post_single( row=row, request=request, ) - response = await row.save().run() + response = (await row.save().run())[0] if self._hook_map: await execute_post_hooks( hooks=self._hook_map, diff --git a/tests/fastapi/test_fastapi_endpoints.py b/tests/fastapi/test_fastapi_endpoints.py index 1284a163..6e0c2871 100644 --- a/tests/fastapi/test_fastapi_endpoints.py +++ b/tests/fastapi/test_fastapi_endpoints.py @@ -207,7 +207,7 @@ def test_post(self): "/movies/", json={"name": "Star Wars", "rating": 93} ) self.assertEqual(response.status_code, 201) - self.assertEqual(response.json(), [{"id": 2}]) + self.assertEqual(response.json(), {"id": 2}) def test_put(self): client = TestClient(app)