-
-
Notifications
You must be signed in to change notification settings - Fork 357
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
mbeliaev/recorder #545
mbeliaev/recorder #545
Conversation
Codecov Report
@@ Coverage Diff @@
## master #545 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 7 9 +2
Lines 2644 2730 +86
=========================================
+ Hits 2644 2730 +86
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
# Conflicts: # CHANGES
added types added "toml" dependence
@markstory if we are fine with the idea of implementation, then I will add tests to increase coverage so, following code 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.toml")
def test_recorder():
rsp = requests.get("https://httpstat.us/404")
rsp = requests.get("https://httpbin.org/status/wrong")
another() will product next output in out.toml [[responses]]
[responses.response]
method = "GET"
url = "https://httpstat.us/404"
body = "404 Not Found"
status = 404
content_type = "text/plain"
auto_calculate_content_length = false
[[responses]]
[responses.response]
method = "GET"
url = "https://httpbin.org/status/wrong"
body = "Invalid status code"
status = 400
content_type = "text/plain"
auto_calculate_content_length = false
[[responses]]
[responses.response]
method = "GET"
url = "https://httpstat.us/500"
body = "500 Internal Server Error"
status = 500
content_type = "text/plain"
auto_calculate_content_length = false
[[responses]]
[responses.response]
method = "GET"
url = "https://httpstat.us/202"
body = "202 Accepted"
status = 202
content_type = "text/plain"
auto_calculate_content_length = false |
responses/registries.py
Outdated
@@ -73,6 +79,31 @@ def replace(self, response: "BaseResponse") -> "BaseResponse": | |||
self.registered[index] = response | |||
return response | |||
|
|||
def _dump(self, destination: "io.IOBase") -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should dumping to a file be a separate thing? That would let userland code or us in the future change the serialization format that is being used to save response fixtures.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to create it in the registry because this will allow to dump existing tests to the file
Eg
If user ran responses.add()
multiple times, then user can run responses.get_registry()._dump(*args)
That will allow safe (compared to brand new recording) transfer to the new method if required
In the future we can provide serializer
argument, but at the moment I am a bit reluctant to support other serializers than one we decide
Also, user can also overwrite this method after inheriting
Or what are the other options to introduce this method?
As a separate function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't dumping be on the Recorder()
? I'm concerned that recording feels like it is half in the Recorder and half in the registry right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@markstory
done!
this could be done even as a separate function. Then it will be possible to easily dump existing registries into the file
Co-authored-by: Mark Story <[email protected]>
# Conflicts: # CHANGES
@markstory |
@markstory |
propose beta feature for 0.22.0 to record responses to files using
man in the middle
there are still steps to polish within this PR (types, docs, style, etc), but before doing this I need to confirm the idea.
General workflow looks like:
which will product following
out.yml
file:later I am going to extend the functionality and add possibility to load these yaml files