@@ -61,117 +61,6 @@ Please ensure to update your code according to the guidance.
6161 - 0.20.0
6262 - Use ``responses.mock.assert_all_requests_are_fired ``,
6363 ``responses.mock.passthru_prefixes ``, ``responses.mock.target `` instead.
64-
65- BETA Features
66- -------------
67- Below you can find a list of BETA features. Although we will try to keep the API backwards compatible
68- with released version, we reserve the right to change these APIs before they are considered stable. Please share your feedback via
69- `GitHub Issues <https://github.com/getsentry/responses/issues >`_.
70-
71- Record Responses to files
72- ^^^^^^^^^^^^^^^^^^^^^^^^^
73-
74- You can perform real requests to the server and ``responses `` will automatically record the output to the
75- file. Recorded data is stored in `YAML <https://yaml.org >`_ format.
76-
77- Apply ``@responses._recorder.record(file_path="out.yaml") `` decorator to any function where you perform
78- requests to record responses to ``out.yaml `` file.
79-
80- Following code
81-
82- .. code-block :: python
83-
84- import requests
85- from responses import _recorder
86-
87-
88- def another ():
89- rsp = requests.get(" https://httpstat.us/500" )
90- rsp = requests.get(" https://httpstat.us/202" )
91-
92-
93- @_recorder.record (file_path = " out.yaml" )
94- def test_recorder ():
95- rsp = requests.get(" https://httpstat.us/404" )
96- rsp = requests.get(" https://httpbin.org/status/wrong" )
97- another()
98-
99- will produce next output:
100-
101- .. code-block :: yaml
102-
103- responses :
104- - response :
105- auto_calculate_content_length : false
106- body : 404 Not Found
107- content_type : text/plain
108- method : GET
109- status : 404
110- url : https://httpstat.us/404
111- - response :
112- auto_calculate_content_length : false
113- body : Invalid status code
114- content_type : text/plain
115- method : GET
116- status : 400
117- url : https://httpbin.org/status/wrong
118- - response :
119- auto_calculate_content_length : false
120- body : 500 Internal Server Error
121- content_type : text/plain
122- method : GET
123- status : 500
124- url : https://httpstat.us/500
125- - response :
126- auto_calculate_content_length : false
127- body : 202 Accepted
128- content_type : text/plain
129- method : GET
130- status : 202
131- url : https://httpstat.us/202
132-
133- If you are in the REPL, you can also activete the recorder for all following responses:
134-
135- .. code-block :: python
136-
137- import requests
138- from responses import _recorder
139-
140- _recorder.recorder.start()
141-
142- requests.get(" https://httpstat.us/500" )
143-
144- _recorder.recorder.dump_to_file(" out.yaml" )
145-
146- # you can stop or reset the recorder
147- _recorder.recorder.stop()
148- _recorder.recorder.reset()
149-
150- Replay responses (populate registry) from files
151- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
152-
153- You can populate your active registry from a ``yaml `` file with recorded responses.
154- (See `Record Responses to files `_ to understand how to obtain a file).
155- To do that you need to execute ``responses._add_from_file(file_path="out.yaml") `` within
156- an activated decorator or a context manager.
157-
158- The following code example registers a ``patch `` response, then all responses present in
159- ``out.yaml `` file and a ``post `` response at the end.
160-
161- .. code-block :: python
162-
163- import responses
164-
165-
166- @responses.activate
167- def run ():
168- responses.patch(" http://httpbin.org" )
169- responses._add_from_file(file_path = " out.yaml" )
170- responses.post(" http://httpbin.org/form" )
171-
172-
173- run()
174-
17564Basics
17665------
17766
@@ -1418,6 +1307,116 @@ single thread to access it.
14181307
14191308 await run()
14201309
1310+ BETA Features
1311+ -------------
1312+ Below you can find a list of BETA features. Although we will try to keep the API backwards compatible
1313+ with released version, we reserve the right to change these APIs before they are considered stable. Please share your feedback via
1314+ `GitHub Issues <https://github.com/getsentry/responses/issues >`_.
1315+
1316+ Record Responses to files
1317+ ^^^^^^^^^^^^^^^^^^^^^^^^^
1318+
1319+ You can perform real requests to the server and ``responses `` will automatically record the output to the
1320+ file. Recorded data is stored in `YAML <https://yaml.org >`_ format.
1321+
1322+ Apply ``@responses._recorder.record(file_path="out.yaml") `` decorator to any function where you perform
1323+ requests to record responses to ``out.yaml `` file.
1324+
1325+ Following code
1326+
1327+ .. code-block :: python
1328+
1329+ import requests
1330+ from responses import _recorder
1331+
1332+
1333+ def another ():
1334+ rsp = requests.get(" https://httpstat.us/500" )
1335+ rsp = requests.get(" https://httpstat.us/202" )
1336+
1337+
1338+ @_recorder.record (file_path = " out.yaml" )
1339+ def test_recorder ():
1340+ rsp = requests.get(" https://httpstat.us/404" )
1341+ rsp = requests.get(" https://httpbin.org/status/wrong" )
1342+ another()
1343+
1344+ will produce next output:
1345+
1346+ .. code-block :: yaml
1347+
1348+ responses :
1349+ - response :
1350+ auto_calculate_content_length : false
1351+ body : 404 Not Found
1352+ content_type : text/plain
1353+ method : GET
1354+ status : 404
1355+ url : https://httpstat.us/404
1356+ - response :
1357+ auto_calculate_content_length : false
1358+ body : Invalid status code
1359+ content_type : text/plain
1360+ method : GET
1361+ status : 400
1362+ url : https://httpbin.org/status/wrong
1363+ - response :
1364+ auto_calculate_content_length : false
1365+ body : 500 Internal Server Error
1366+ content_type : text/plain
1367+ method : GET
1368+ status : 500
1369+ url : https://httpstat.us/500
1370+ - response :
1371+ auto_calculate_content_length : false
1372+ body : 202 Accepted
1373+ content_type : text/plain
1374+ method : GET
1375+ status : 202
1376+ url : https://httpstat.us/202
1377+
1378+ If you are in the REPL, you can also activete the recorder for all following responses:
1379+
1380+ .. code-block :: python
1381+
1382+ import requests
1383+ from responses import _recorder
1384+
1385+ _recorder.recorder.start()
1386+
1387+ requests.get(" https://httpstat.us/500" )
1388+
1389+ _recorder.recorder.dump_to_file(" out.yaml" )
1390+
1391+ # you can stop or reset the recorder
1392+ _recorder.recorder.stop()
1393+ _recorder.recorder.reset()
1394+
1395+ Replay responses (populate registry) from files
1396+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1397+
1398+ You can populate your active registry from a ``yaml `` file with recorded responses.
1399+ (See `Record Responses to files `_ to understand how to obtain a file).
1400+ To do that you need to execute ``responses._add_from_file(file_path="out.yaml") `` within
1401+ an activated decorator or a context manager.
1402+
1403+ The following code example registers a ``patch `` response, then all responses present in
1404+ ``out.yaml `` file and a ``post `` response at the end.
1405+
1406+ .. code-block :: python
1407+
1408+ import responses
1409+
1410+
1411+ @responses.activate
1412+ def run ():
1413+ responses.patch(" http://httpbin.org" )
1414+ responses._add_from_file(file_path = " out.yaml" )
1415+ responses.post(" http://httpbin.org/form" )
1416+
1417+
1418+ run()
1419+
14211420
14221421 Contributing
14231422------------
0 commit comments