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

remove readonly properties #497

Merged
merged 9 commits into from Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 8 additions & 1 deletion CHANGES
@@ -1,3 +1,11 @@
0.20.0
------

* 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 @@ -19,7 +27,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
Expand Up @@ -888,7 +888,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 @@ -899,7 +899,7 @@ def assert_call_count(self, url, count):
"HEAD",
"options",
"OPTIONS",
"passthru_prefixes",
"_deprecated_passthru_prefixes",
"patch",
"PATCH",
"post",
Expand All @@ -913,15 +913,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 @@ -932,7 +933,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 @@ -946,5 +947,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
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