Skip to content

Commit

Permalink
Expand the ParsedRequest example in the README
Browse files Browse the repository at this point in the history
  • Loading branch information
DevL committed Mar 20, 2024
1 parent d74b0b6 commit 9ee5529
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ Returns a `requests.Response` object with either the return value of its `json()

### `ParsedRequest`

A test helper object wrapping a `PreparedRequest` object to make it easier to write assertions.
A test helper object wrapping a `PreparedRequest` object to make it easier to write assertions. In addition to wrapping the `PreparedRequest`'s `body`, `headers`, `method`, and `url` properties, it also provides the following convenience properties.

* `endpoint` - the URL without any query parameters.
* `query` - any query parameters, parsed and decoded.
* `json` - the body parsed as JSON.
* `text` - the body decoded as a string.

#### Example

Expand All @@ -114,9 +119,11 @@ from requtests import ParsedRequest
def _create_user_assertions(prepared_request, **kwargs):
parsed_request = ParsedRequest(prepared_request)
assert parsed_request.method == "POST"
assert parsed_request.url == "https://example.com/users?action=create"
assert parsed_request.endpoint == "https://example.com/users"
assert parsed_request.query == {"action": "create"}
assert parsed_request.headers["Authorization"] == "Bearer token"
assert parsed_request.body == b'{"username": "my_username"}'
assert parsed_request.json == {"username": "my_username"}
assert parsed_request.text == '{"username": "my_username"}'
```

0 comments on commit 9ee5529

Please sign in to comment.