Skip to content

Add SetCookie utility#254

Merged
lundberg merged 4 commits intomasterfrom
feature/set-cookie-util
Mar 19, 2024
Merged

Add SetCookie utility#254
lundberg merged 4 commits intomasterfrom
feature/set-cookie-util

Conversation

@lundberg
Copy link
Copy Markdown
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

@codecov
Copy link
Copy Markdown

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.

@lundberg lundberg force-pushed the feature/set-cookie-util branch from 0980bf2 to a7e45ae Compare March 18, 2024 16:01
@lundberg lundberg force-pushed the feature/files-pattern branch from b66080b to c1a38e8 Compare March 18, 2024 16:13
Base automatically changed from feature/files-pattern to master March 18, 2024 16:14
@lundberg lundberg force-pushed the feature/set-cookie-util branch from a7e45ae to 1a28a73 Compare March 18, 2024 16:15
@lundberg lundberg merged commit e97b677 into master Mar 19, 2024
@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