From 232269fe8582c4d553172f510265a0b8cbccfaff Mon Sep 17 00:00:00 2001 From: Bara Date: Mon, 23 Sep 2024 17:05:16 +0200 Subject: [PATCH] feat: Add new methods for hook object --- rossum_api/elis_api_client.py | 10 +++++++ rossum_api/elis_api_client_sync.py | 10 +++++++ tests/elis_api_client/test_hooks.py | 46 +++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) diff --git a/rossum_api/elis_api_client.py b/rossum_api/elis_api_client.py index 0a58734..6760a55 100644 --- a/rossum_api/elis_api_client.py +++ b/rossum_api/elis_api_client.py @@ -634,6 +634,16 @@ async def create_new_hook(self, data: Dict[str, Any]) -> Hook: return self._deserializer(Resource.Hook, hook) + async def update_part_hook(self, hook_id: int, data: Dict[str, Any]) -> Hook: + """https://elis.rossum.ai/api/docs/#update-part-of-a-hook""" + hook = await self._http_client.update(Resource.Hook, hook_id, data) + + return self._deserializer(Resource.Hook, hook) + + async def delete_hook(self, hook_id: int) -> None: + """https://elis.rossum.ai/api/docs/#delete-a-hook""" + return await self._http_client.delete(Resource.Hook, hook_id) + # ##### USER ROLES ##### async def list_all_user_roles( self, diff --git a/rossum_api/elis_api_client_sync.py b/rossum_api/elis_api_client_sync.py index 5433644..44d5d63 100644 --- a/rossum_api/elis_api_client_sync.py +++ b/rossum_api/elis_api_client_sync.py @@ -533,6 +533,16 @@ def create_new_hook(self, data: Dict[str, Any]) -> Hook: """https://elis.rossum.ai/api/docs/#create-a-new-hook.""" return self.event_loop.run_until_complete(self.elis_api_client.create_new_hook(data)) + def update_part_hook(self, hook_id: int, data: Dict[str, Any]) -> Hook: + """https://elis.rossum.ai/api/docs/#update-part-of-a-hook""" + return self.event_loop.run_until_complete( + self.elis_api_client.update_part_hook(hook_id, data) + ) + + def delete_hook(self, hook_id: int) -> None: + """https://elis.rossum.ai/api/docs/#delete-a-hook""" + return self.event_loop.run_until_complete(self.elis_api_client.delete_hook(hook_id)) + # ##### USER ROLES ##### def list_all_user_roles( self, diff --git a/tests/elis_api_client/test_hooks.py b/tests/elis_api_client/test_hooks.py index 98f3ba2..b1f22de 100644 --- a/tests/elis_api_client/test_hooks.py +++ b/tests/elis_api_client/test_hooks.py @@ -79,6 +79,29 @@ async def test_create_new_hook(self, elis_client, dummy_hook): http_client.create.assert_called_with(Resource.Hook, data) + async def test_update_part_hook(self, elis_client, dummy_hook): + client, http_client = elis_client + http_client.update.return_value = dummy_hook + + hid = dummy_hook["id"] + data = { + "name": "New Hook Name", + } + hook = await client.update_part_hook(hid, data) + + assert hook == Hook(**dummy_hook) + + http_client.update.assert_called_with(Resource.Hook, hid, data) + + async def test_delete_hook(self, elis_client, dummy_hook): + client, http_client = elis_client + http_client.delete.return_value = None + + hid = dummy_hook["id"] + await client.delete_hook(hid) + + http_client.delete.assert_called_with(Resource.Hook, hid) + class TestHooksSync: def test_list_all_hooks(self, elis_client_sync, dummy_hook, mock_generator): @@ -118,3 +141,26 @@ def test_create_new_hook(self, elis_client_sync, dummy_hook): assert hook == Hook(**dummy_hook) http_client.create.assert_called_with(Resource.Hook, data) + + def test_update_part_hook(self, elis_client_sync, dummy_hook): + client, http_client = elis_client_sync + http_client.update.return_value = dummy_hook + + hid = dummy_hook["id"] + data = { + "name": "New Hook Name", + } + hook = client.update_part_hook(hid, data) + + assert hook == Hook(**dummy_hook) + + http_client.update.assert_called_with(Resource.Hook, hid, data) + + def test_delete_hook(self, elis_client_sync, dummy_hook): + client, http_client = elis_client_sync + http_client.delete.return_value = None + + hid = dummy_hook["id"] + client.delete_hook(hid) + + http_client.delete.assert_called_with(Resource.Hook, hid)