Skip to content

Commit 63db782

Browse files
committed
Rename asserter, maintain backwards compatability
1 parent f0c920c commit 63db782

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

README.md

+8-15
Original file line numberDiff line numberDiff line change
@@ -192,28 +192,21 @@ This will automatically add the `json_asserter` and set it as a class attribute
192192
This allows you to just call `self.json_asserter`, allowing for cleaner unit tests imports.
193193

194194

195-
### HTTPrettyAsserter Usage
195+
### ResponsesAsserter Usage
196196

197197
When mocking calls, this can help in ensuring all calls, and only those, were made as expected, with the desired parameters.
198-
In order to use, simply import the HTTPrettyAsserter from test_utils and use it in place of the usual httpretty:
199-
```python
200-
@pytest.yield_fixture
201-
def modified_http_pretty():
202-
HTTPrettyAsserter.enable(allow_net_connect=False)
203-
yield HTTPrettyAsserter
204-
HTTPrettyAsserter.disable()
205-
```
198+
In order to use, simply import the `modified_responses` fixture from test_utils.
206199

207-
Then, you just need to register the uris for the calls you want to mock, and ensure that it is returned in the mocking:
200+
Then, you just need to register the uris for the calls you want to mock:
208201
```python
209202
@pytest.fixture
210-
def http_pretty_list_mocking(modified_http_pretty):
211-
modified_http_pretty.register_uri(modified_http_pretty.POST, 'http://google.com/path', status=status.HTTP_200_OK)
212-
modified_http_pretty.register_uri(modified_http_pretty.POST, 'http://google.com/other_path',
203+
def responses_list_mocking(modified_responses):
204+
modified_responses.register_uri(modified_responses.POST, 'http://google.com/path', status=status.HTTP_200_OK)
205+
modified_responses.register_uri(modified_responses.POST, 'http://google.com/other_path',
213206
status=status.HTTP_200_OK)
214-
modified_http_pretty.register_uri(modified_http_pretty.POST, 'http://bing.com/bing_path',
207+
modified_responses.register_uri(modified_responses.POST, 'http://bing.com/bing_path',
215208
status=status.HTTP_200_OK)
216-
return modified_http_pretty
209+
return modified_responses
217210
```
218211

219212
In a test that you want to check the calls on, you simply need to use the mocking fixture and call `.assert_calls(assertions)` on the fixture.

src/shipchain_common/test_utils/httpretty_asserter.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from ..utils import parse_urlencoded_data, parse_value
2121

2222

23-
class ResponsesHTTPretty:
23+
class ResponsesHTTPrettyWrapper:
2424
def __init__(self):
2525
self.mock = responses.mock
2626

@@ -50,8 +50,7 @@ def latest_requests(self):
5050
def reset(self):
5151
self.mock._calls.reset() # pylint:disable=protected-access
5252

53-
54-
class HTTPrettyAsserter(ResponsesHTTPretty):
53+
class ResponsesAsserter(ResponsesHTTPrettyWrapper):
5554
def _parse_calls_into_list(self):
5655
calls_list = []
5756
assert self.latest_requests, 'Error: No calls made to be parsed.'
@@ -102,13 +101,18 @@ def reset_calls(self):
102101

103102

104103
@pytest.yield_fixture(scope='function')
105-
def modified_http_pretty():
104+
def modified_responses():
106105
responses.start()
107-
http_pretty_asserter = HTTPrettyAsserter()
108-
yield http_pretty_asserter
109-
http_pretty_asserter.reset_calls()
106+
responses_asserter = ResponsesAsserter()
107+
yield responses_asserter
108+
responses_asserter.reset_calls()
110109
try:
111110
responses.stop()
112111
except RuntimeError:
113112
# Ignore unittest.mock "stop called on unstarted patcher" exception
114113
pass
114+
115+
116+
# Deprecated names for backwards-compatibility
117+
HTTPrettyAsserter = ResponsesAsserter
118+
modified_http_pretty = modified_responses

0 commit comments

Comments
 (0)