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

apply partialmethod to shortcuts #583

Merged
merged 3 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Add support for the `loose` version of `json_params_matcher` via named argument `strict_match`. See #551
* Add lists support as JSON objects in `json_params_matcher`. See #559
* Added project links to pypi listing.
* `delete`, `get`, `head`, `options`, `patch`, `post`, `put` shortcuts are redone using `functools.partialmethod`.
beliaev-maksim marked this conversation as resolved.
Show resolved Hide resolved
* Fix `MaxRetryError` exception. Replace exception by `RetryError` according to `requests` implementation. See #572.

0.21.0
Expand Down
28 changes: 8 additions & 20 deletions responses/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json as json_module
import logging
from collections import namedtuple
from functools import partialmethod
from functools import wraps
from http import client
from itertools import groupby
Expand Down Expand Up @@ -752,26 +753,13 @@ def add(
response = Response(method=method, url=url, body=body, **kwargs)
return self._registry.add(response)

def delete(self, *args: Any, **kwargs: Any) -> BaseResponse:
return self.add(DELETE, *args, **kwargs)

def get(self, *args: Any, **kwargs: Any) -> BaseResponse:
return self.add(GET, *args, **kwargs)

def head(self, *args: Any, **kwargs: Any) -> BaseResponse:
return self.add(HEAD, *args, **kwargs)

def options(self, *args: Any, **kwargs: Any) -> BaseResponse:
return self.add(OPTIONS, *args, **kwargs)

def patch(self, *args: Any, **kwargs: Any) -> BaseResponse:
return self.add(PATCH, *args, **kwargs)

def post(self, *args: Any, **kwargs: Any) -> BaseResponse:
return self.add(POST, *args, **kwargs)

def put(self, *args: Any, **kwargs: Any) -> BaseResponse:
return self.add(PUT, *args, **kwargs)
delete = partialmethod(add, DELETE)
get = partialmethod(add, GET)
head = partialmethod(add, HEAD)
options = partialmethod(add, OPTIONS)
patch = partialmethod(add, PATCH)
post = partialmethod(add, POST)
put = partialmethod(add, PUT)

def add_passthru(self, prefix: _URLPatternType) -> None:
"""
Expand Down