|
@@ -1,6 +1,6 @@
|
|
|
Metadata-Version: 2.1
|
|
|
Name: responses
|
|
|
-Version: 0.25.3
|
|
|
+Version: 0.25.5
|
|
|
Summary: A utility library for mocking out the `requests` Python library.
|
|
|
Home-page: https://github.com/getsentry/responses
|
|
|
Author: David Cramer
|
|
@@ -24,21 +24,21 @@ Classifier: Topic :: Software Development
|
|
|
Requires-Python: >=3.8
|
|
|
Description-Content-Type: text/x-rst
|
|
|
License-File: LICENSE
|
|
|
-Requires-Dist: requests <3.0,>=2.30.0
|
|
|
-Requires-Dist: urllib3 <3.0,>=1.25.10
|
|
|
+Requires-Dist: requests<3.0,>=2.30.0
|
|
|
+Requires-Dist: urllib3<3.0,>=1.25.10
|
|
|
Requires-Dist: pyyaml
|
|
|
Provides-Extra: tests
|
|
|
-Requires-Dist: pytest >=7.0.0 ; extra == 'tests'
|
|
|
-Requires-Dist: coverage >=6.0.0 ; extra == 'tests'
|
|
|
-Requires-Dist: pytest-cov ; extra == 'tests'
|
|
|
-Requires-Dist: pytest-asyncio ; extra == 'tests'
|
|
|
-Requires-Dist: pytest-httpserver ; extra == 'tests'
|
|
|
-Requires-Dist: flake8 ; extra == 'tests'
|
|
|
-Requires-Dist: types-PyYAML ; extra == 'tests'
|
|
|
-Requires-Dist: types-requests ; extra == 'tests'
|
|
|
-Requires-Dist: mypy ; extra == 'tests'
|
|
|
-Requires-Dist: tomli-w ; extra == 'tests'
|
|
|
-Requires-Dist: tomli ; (python_version < "3.11") and extra == 'tests'
|
|
|
+Requires-Dist: pytest>=7.0.0; extra == "tests"
|
|
|
+Requires-Dist: coverage>=6.0.0; extra == "tests"
|
|
|
+Requires-Dist: pytest-cov; extra == "tests"
|
|
|
+Requires-Dist: pytest-asyncio; extra == "tests"
|
|
|
+Requires-Dist: pytest-httpserver; extra == "tests"
|
|
|
+Requires-Dist: flake8; extra == "tests"
|
|
|
+Requires-Dist: types-PyYAML; extra == "tests"
|
|
|
+Requires-Dist: types-requests; extra == "tests"
|
|
|
+Requires-Dist: mypy; extra == "tests"
|
|
|
+Requires-Dist: tomli-w; extra == "tests"
|
|
|
+Requires-Dist: tomli; python_version < "3.11" and extra == "tests"
|
|
|
|
|
|
Responses
|
|
|
=========
|
|
@@ -104,100 +104,6 @@ Please ensure to update your code according to the guidance.
|
|
|
- Use ``responses.mock.assert_all_requests_are_fired``,
|
|
|
``responses.mock.passthru_prefixes``, ``responses.mock.target`` instead.
|
|
|
|
|
|
-BETA Features
|
|
|
--------------
|
|
|
-Below you can find a list of BETA features. Although we will try to keep the API backwards compatible
|
|
|
-with released version, we reserve the right to change these APIs before they are considered stable. Please share your feedback via
|
|
|
-`GitHub Issues <https://github.com/getsentry/responses/issues>`_.
|
|
|
-
|
|
|
-Record Responses to files
|
|
|
-^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
-
|
|
|
-You can perform real requests to the server and ``responses`` will automatically record the output to the
|
|
|
-file. Recorded data is stored in `YAML <https://yaml.org>`_ format.
|
|
|
-
|
|
|
-Apply ``@responses._recorder.record(file_path="out.yaml")`` decorator to any function where you perform
|
|
|
-requests to record responses to ``out.yaml`` file.
|
|
|
-
|
|
|
-Following code
|
|
|
-
|
|
|
-.. code-block:: python
|
|
|
-
|
|
|
- import requests
|
|
|
- from responses import _recorder
|
|
|
-
|
|
|
-
|
|
|
- def another():
|
|
|
- rsp = requests.get("https://httpstat.us/500")
|
|
|
- rsp = requests.get("https://httpstat.us/202")
|
|
|
-
|
|
|
-
|
|
|
- @_recorder.record(file_path="out.yaml")
|
|
|
- def test_recorder():
|
|
|
- rsp = requests.get("https://httpstat.us/404")
|
|
|
- rsp = requests.get("https://httpbin.org/status/wrong")
|
|
|
- another()
|
|
|
-
|
|
|
-will produce next output:
|
|
|
-
|
|
|
-.. code-block:: yaml
|
|
|
-
|
|
|
- responses:
|
|
|
- - response:
|
|
|
- auto_calculate_content_length: false
|
|
|
- body: 404 Not Found
|
|
|
- content_type: text/plain
|
|
|
- method: GET
|
|
|
- status: 404
|
|
|
- url: https://httpstat.us/404
|
|
|
- - response:
|
|
|
- auto_calculate_content_length: false
|
|
|
- body: Invalid status code
|
|
|
- content_type: text/plain
|
|
|
- method: GET
|
|
|
- status: 400
|
|
|
- url: https://httpbin.org/status/wrong
|
|
|
- - response:
|
|
|
- auto_calculate_content_length: false
|
|
|
- body: 500 Internal Server Error
|
|
|
- content_type: text/plain
|
|
|
- method: GET
|
|
|
- status: 500
|
|
|
- url: https://httpstat.us/500
|
|
|
- - response:
|
|
|
- auto_calculate_content_length: false
|
|
|
- body: 202 Accepted
|
|
|
- content_type: text/plain
|
|
|
- method: GET
|
|
|
- status: 202
|
|
|
- url: https://httpstat.us/202
|
|
|
-
|
|
|
-
|
|
|
-Replay responses (populate registry) from files
|
|
|
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
-
|
|
|
-You can populate your active registry from a ``yaml`` file with recorded responses.
|
|
|
-(See `Record Responses to files`_ to understand how to obtain a file).
|
|
|
-To do that you need to execute ``responses._add_from_file(file_path="out.yaml")`` within
|
|
|
-an activated decorator or a context manager.
|
|
|
-
|
|
|
-The following code example registers a ``patch`` response, then all responses present in
|
|
|
-``out.yaml`` file and a ``post`` response at the end.
|
|
|
-
|
|
|
-.. code-block:: python
|
|
|
-
|
|
|
- import responses
|
|
|
-
|
|
|
-
|
|
|
- @responses.activate
|
|
|
- def run():
|
|
|
- responses.patch("http://httpbin.org")
|
|
|
- responses._add_from_file(file_path="out.yaml")
|
|
|
- responses.post("http://httpbin.org/form")
|
|
|
-
|
|
|
-
|
|
|
- run()
|
|
|
-
|
|
|
Basics
|
|
|
------
|
|
|
|
|
@@ -941,16 +847,19 @@ Integration with unit test frameworks
|
|
|
Responses as a ``pytest`` fixture
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
+Use the pytest-responses package to export ``responses`` as a pytest fixture.
|
|
|
+
|
|
|
+``pip install pytest-responses``
|
|
|
+
|
|
|
+You can then access it in a pytest script using:
|
|
|
+
|
|
|
.. code-block:: python
|
|
|
|
|
|
- @pytest.fixture
|
|
|
- def mocked_responses():
|
|
|
- with responses.RequestsMock() as rsps:
|
|
|
- yield rsps
|
|
|
+ import pytest_responses
|
|
|
|
|
|
|
|
|
- def test_api(mocked_responses):
|
|
|
- mocked_responses.get(
|
|
|
+ def test_api(responses):
|
|
|
+ responses.get(
|
|
|
"http://twitter.com/api/1/foobar",
|
|
|
body="{}",
|
|
|
status=200,
|
|
@@ -1441,6 +1350,116 @@ single thread to access it.
|
|
|
|
|
|
await run()
|
|
|
|
|
|
+BETA Features
|
|
|
+-------------
|
|
|
+Below you can find a list of BETA features. Although we will try to keep the API backwards compatible
|
|
|
+with released version, we reserve the right to change these APIs before they are considered stable. Please share your feedback via
|
|
|
+`GitHub Issues <https://github.com/getsentry/responses/issues>`_.
|
|
|
+
|
|
|
+Record Responses to files
|
|
|
+^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
+
|
|
|
+You can perform real requests to the server and ``responses`` will automatically record the output to the
|
|
|
+file. Recorded data is stored in `YAML <https://yaml.org>`_ format.
|
|
|
+
|
|
|
+Apply ``@responses._recorder.record(file_path="out.yaml")`` decorator to any function where you perform
|
|
|
+requests to record responses to ``out.yaml`` file.
|
|
|
+
|
|
|
+Following code
|
|
|
+
|
|
|
+.. code-block:: python
|
|
|
+
|
|
|
+ import requests
|
|
|
+ from responses import _recorder
|
|
|
+
|
|
|
+
|
|
|
+ def another():
|
|
|
+ rsp = requests.get("https://httpstat.us/500")
|
|
|
+ rsp = requests.get("https://httpstat.us/202")
|
|
|
+
|
|
|
+
|
|
|
+ @_recorder.record(file_path="out.yaml")
|
|
|
+ def test_recorder():
|
|
|
+ rsp = requests.get("https://httpstat.us/404")
|
|
|
+ rsp = requests.get("https://httpbin.org/status/wrong")
|
|
|
+ another()
|
|
|
+
|
|
|
+will produce next output:
|
|
|
+
|
|
|
+.. code-block:: yaml
|
|
|
+
|
|
|
+ responses:
|
|
|
+ - response:
|
|
|
+ auto_calculate_content_length: false
|
|
|
+ body: 404 Not Found
|
|
|
+ content_type: text/plain
|
|
|
+ method: GET
|
|
|
+ status: 404
|
|
|
+ url: https://httpstat.us/404
|
|
|
+ - response:
|
|
|
+ auto_calculate_content_length: false
|
|
|
+ body: Invalid status code
|
|
|
+ content_type: text/plain
|
|
|
+ method: GET
|
|
|
+ status: 400
|
|
|
+ url: https://httpbin.org/status/wrong
|
|
|
+ - response:
|
|
|
+ auto_calculate_content_length: false
|
|
|
+ body: 500 Internal Server Error
|
|
|
+ content_type: text/plain
|
|
|
+ method: GET
|
|
|
+ status: 500
|
|
|
+ url: https://httpstat.us/500
|
|
|
+ - response:
|
|
|
+ auto_calculate_content_length: false
|
|
|
+ body: 202 Accepted
|
|
|
+ content_type: text/plain
|
|
|
+ method: GET
|
|
|
+ status: 202
|
|
|
+ url: https://httpstat.us/202
|
|
|
+
|
|
|
+If you are in the REPL, you can also activete the recorder for all following responses:
|
|
|
+
|
|
|
+.. code-block:: python
|
|
|
+
|
|
|
+ import requests
|
|
|
+ from responses import _recorder
|
|
|
+
|
|
|
+ _recorder.recorder.start()
|
|
|
+
|
|
|
+ requests.get("https://httpstat.us/500")
|
|
|
+
|
|
|
+ _recorder.recorder.dump_to_file("out.yaml")
|
|
|
+
|
|
|
+ # you can stop or reset the recorder
|
|
|
+ _recorder.recorder.stop()
|
|
|
+ _recorder.recorder.reset()
|
|
|
+
|
|
|
+Replay responses (populate registry) from files
|
|
|
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
+
|
|
|
+You can populate your active registry from a ``yaml`` file with recorded responses.
|
|
|
+(See `Record Responses to files`_ to understand how to obtain a file).
|
|
|
+To do that you need to execute ``responses._add_from_file(file_path="out.yaml")`` within
|
|
|
+an activated decorator or a context manager.
|
|
|
+
|
|
|
+The following code example registers a ``patch`` response, then all responses present in
|
|
|
+``out.yaml`` file and a ``post`` response at the end.
|
|
|
+
|
|
|
+.. code-block:: python
|
|
|
+
|
|
|
+ import responses
|
|
|
+
|
|
|
+
|
|
|
+ @responses.activate
|
|
|
+ def run():
|
|
|
+ responses.patch("http://httpbin.org")
|
|
|
+ responses._add_from_file(file_path="out.yaml")
|
|
|
+ responses.post("http://httpbin.org/form")
|
|
|
+
|
|
|
+
|
|
|
+ run()
|
|
|
+
|
|
|
|
|
|
Contributing
|
|
|
------------
|