lundberg / respx

Mock HTTPX with awesome request patterns and response side effects 🦋
https://lundberg.github.io/respx
BSD 3-Clause "New" or "Revised" License
602 stars 39 forks source link

Add `SetCookie` utility #254

Closed lundberg closed 6 months ago

lundberg commented 6 months ago

Adds a respx.SetCookie utility that can be used for easier mocking of response Set-Cookie headers.

The route.respond(...) helper is also enhanced with a cookies kwarg that supports dict[str, str], Sequence[tuple[str, str]] or Sequence[SetCookie].

Example usage via headers:

respx.post("https://example.com/").mock(
    return_value=httpx.Response(200, headers=[SetCookie("foo", "bar")])
)

.. or by using respond ..

respx.post("https://example.com/").respond(cookies={"foo": "bar"})
respx.post("https://example.com/").respond(cookies=[SetCookie("foo", "bar", path="/", ...)])

Fixes #249

codecov[bot] commented 6 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 100.00%. Comparing base (24ee4a9) to head (c670ccb).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #254 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 21 22 +1 Lines 2845 2910 +65 Branches 428 443 +15 ========================================= + Hits 2845 2910 +65 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.