Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Client): Allow passing data or json_data to delete #199

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading