Skip to content

Commit

Permalink
new: post /_admin/echo (#310)
Browse files Browse the repository at this point in the history
* new: `Database. echo_request()`

* remove: `echo_request`
  • Loading branch information
aMahanna committed Jan 26, 2024
1 parent cb338b6 commit 6653c1b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
17 changes: 13 additions & 4 deletions arango/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,14 +570,23 @@ def response_handler(resp: Response) -> datetime:

return self._execute(request, response_handler)

def echo(self) -> Result[Json]:
"""Return details of the last request (e.g. headers, payload).
def echo(self, body: Optional[Any] = None) -> Result[Json]:
"""Return details of the last request (e.g. headers, payload),
or echo the given request body.
:param body: The body of the request. Can be of any type
and is simply forwarded. If not set, the details of the last
request are returned.
:type body: dict | list | str | int | float | None
:return: Details of the last request.
:rtype: dict
:raise arango.exceptions.ServerEchoError: If retrieval fails.
"""
request = Request(method="get", endpoint="/_admin/echo")
request = (
Request(method="get", endpoint="/_admin/echo")
if body is None
else Request(method="post", endpoint="/_admin/echo", data=body)
)

def response_handler(resp: Response) -> Json:
if not resp.is_success:
Expand Down
3 changes: 3 additions & 0 deletions docs/admin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ database.
# Echo the last request.
sys_db.echo()

# Echo a request
sys_db.echo('request goes here')

# Reload the routing collection.
sys_db.reload_routing()

Expand Down
6 changes: 6 additions & 0 deletions tests/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ def test_database_misc_methods(client, sys_db, db, bad_db, cluster, secret):
bad_db.echo()
assert err.value.error_code in {11, 1228}

# Test echo (forward request)
body = "request goes here"
echo = db.echo(body)
assert isinstance(echo, dict)
assert echo["requestBody"] == body

# Test read_log with default parameters
# Deprecated in 3.8.0
# TODO: Remove in future release
Expand Down

0 comments on commit 6653c1b

Please sign in to comment.