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

Add SetCookie utility #254

Merged
merged 4 commits into from
Mar 19, 2024
Merged

Add SetCookie utility #254

merged 4 commits into from
Mar 19, 2024

Conversation

lundberg
Copy link
Owner

@lundberg lundberg commented Mar 18, 2024

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

Copy link

codecov bot commented Mar 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

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

Additional details and impacted files
@@            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     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Base automatically changed from feature/files-pattern to master March 18, 2024 16:14
@lundberg lundberg merged commit e97b677 into master Mar 19, 2024
10 checks passed
@lundberg lundberg deleted the feature/set-cookie-util branch March 19, 2024 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: easily mock cookies
1 participant