Skip to content

Commit

Permalink
feat(Client): Allow passing data or json_data to delete
Browse files Browse the repository at this point in the history
  • Loading branch information
joseotoro committed Sep 16, 2024
1 parent 6dbc30f commit 2172e7c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
5 changes: 3 additions & 2 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,12 @@ def test_post_object(httpserver):

def test_delete(httpserver):
httpserver.expect_request(
"/api/v3/foo", method="DELETE", headers={"X-Apikey": "dummy_api_key"}
"/api/v3/foo", method="DELETE", headers={"X-Apikey": "dummy_api_key"},
json={"hello": "world"},
).respond_with_json({"data": "dummy_data"})

with new_client(httpserver) as client:
response = client.delete("/foo")
response = client.delete("/foo", json_data={"hello": "world"})

assert response.status == 200

Expand Down
25 changes: 21 additions & 4 deletions vt/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,26 +336,43 @@ def close(self) -> None:
"""
return make_sync(self.close_async())

def delete(self, path: str, *path_args: typing.Any) -> ClientResponse:
def delete(
self,
path: str,
*path_args: typing.Any,
data: typing.Optional[typing.Union[str, bytes]] = None,
json_data: typing.Optional[typing.Dict] = None
) -> ClientResponse:
"""Sends a DELETE request to a given API endpoint.
:param path: Path to API endpoint, can contain format placeholders {}.
:param path_args: A variable number of arguments that are put into any
placeholders used in path.
:param data: Data sent in the request body.
:param json_data: dict containing data to send in the request body as JSON.
:type path: str
:type data: A string or bytes
:type json_data: dict
:returns: An instance of :class:`ClientResponse`.
"""
return make_sync(self.delete_async(path, *path_args))
return make_sync(
self.delete_async(path, *path_args, data=data, json_data=json_data)
)

async def delete_async(
self,
path: str,
*path_args: typing.Any
*path_args: typing.Any,
data: typing.Optional[typing.Union[str, bytes]] = None,
json_data: typing.Optional[typing.Dict] = None
) -> ClientResponse:
"""Like :func:`delete` but returns a coroutine."""
return ClientResponse(
await self._get_session().delete(
self._full_url(path, *path_args), proxy=self._proxy
self._full_url(path, *path_args),
data=data,
json=json_data,
proxy=self._proxy
)
)

Expand Down
2 changes: 1 addition & 1 deletion vt/iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __init__(
"""Initializes an iterator.
This function is not intended to be called directly. Client.iterator() is
the preferred way for creating an iteraror.
the preferred way for creating an iterator.
"""
self._client = client
self._path = path
Expand Down

0 comments on commit 2172e7c

Please sign in to comment.