Skip to content

Commit

Permalink
feat: Add new methods for hook object
Browse files Browse the repository at this point in the history
  • Loading branch information
Bara committed Sep 23, 2024
1 parent 9e0725a commit 93ddac3
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
10 changes: 10 additions & 0 deletions rossum_api/elis_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions rossum_api/elis_api_client_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
46 changes: 46 additions & 0 deletions tests/elis_api_client/test_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)

0 comments on commit 93ddac3

Please sign in to comment.