Skip to content

Commit

Permalink
Merge branch 'master' into mbeliaev/fix_511
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Mar 17, 2022
2 parents 05a83d2 + 1724937 commit 658c0e8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
6 changes: 5 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
0.20.0
------

* Fixed the issue when `reset()` method was called in not stopped mock. See #511
* Deprecate `responses.assert_all_requests_are_fired`, `responses.passthru_prefixes`, `responses.target`
since they are not actual properties of the class instance.
Use `responses.mock.assert_all_requests_are_fired`,
`responses.mock.passthru_prefixes`, `responses.mock.target` instead.

0.19.0
------
Expand All @@ -23,7 +28,6 @@
* An error is now raised when both `content_type` and `headers[content-type]` are provided as parameters.
* When a request isn't matched the passthru prefixes are now included in error messages.


0.18.0
------

Expand Down
26 changes: 20 additions & 6 deletions responses/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ def assert_call_count(self, url, count):
"add",
"add_callback",
"add_passthru",
"assert_all_requests_are_fired",
"_deprecated_assert_all_requests_are_fired",
"assert_call_count",
"calls",
"delete",
Expand All @@ -904,7 +904,7 @@ def assert_call_count(self, url, count):
"HEAD",
"options",
"OPTIONS",
"passthru_prefixes",
"_deprecated_passthru_prefixes",
"patch",
"PATCH",
"post",
Expand All @@ -918,15 +918,16 @@ def assert_call_count(self, url, count):
"response_callback",
"start",
"stop",
"target",
"_deprecated_target",
"upsert",
]

# expose only methods and/or read-only methods
activate = _default_mock.activate
add = _default_mock.add
add_callback = _default_mock.add_callback
add_passthru = _default_mock.add_passthru
assert_all_requests_are_fired = _default_mock.assert_all_requests_are_fired
_deprecated_assert_all_requests_are_fired = _default_mock.assert_all_requests_are_fired
assert_call_count = _default_mock.assert_call_count
calls = _default_mock.calls
delete = _default_mock.delete
Expand All @@ -937,7 +938,7 @@ def assert_call_count(self, url, count):
HEAD = _default_mock.HEAD
options = _default_mock.options
OPTIONS = _default_mock.OPTIONS
passthru_prefixes = _default_mock.passthru_prefixes
_deprecated_passthru_prefixes = _default_mock.passthru_prefixes
patch = _default_mock.patch
PATCH = _default_mock.PATCH
post = _default_mock.post
Expand All @@ -951,5 +952,18 @@ def assert_call_count(self, url, count):
response_callback = _default_mock.response_callback
start = _default_mock.start
stop = _default_mock.stop
target = _default_mock.target
_deprecated_target = _default_mock.target
upsert = _default_mock.upsert


deprecated_names = ["assert_all_requests_are_fired", "passthru_prefixes", "target"]


def __getattr__(name):
if name in deprecated_names:
warn(
f"{name} is deprecated. Please use 'responses.mock.{name}",
DeprecationWarning,
)
return globals()[f"_deprecated_{name}"]
raise AttributeError(f"module {__name__} has no attribute {name}")
13 changes: 13 additions & 0 deletions responses/tests/test_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,19 @@ def run():
assert_reset()


def test_deprecated_package_attributes():
"""Validates that deprecation warning is raised when package attributes are called."""
# keep separate context manager to avoid leakage
with pytest.deprecated_call():
responses.assert_all_requests_are_fired

with pytest.deprecated_call():
responses.passthru_prefixes

with pytest.deprecated_call():
responses.target


def test_callback_deprecated_stream_argument():
with pytest.deprecated_call():
CallbackResponse(responses.GET, "url", lambda x: x, stream=False)
Expand Down

0 comments on commit 658c0e8

Please sign in to comment.