-
-
Notifications
You must be signed in to change notification settings - Fork 275
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
Context manager and recording/playback. #10
Comments
Other serialization formats like YAML, XML (yuck) and maybe CURL? CURL could be extra useful as you could define
Just a thought! |
First stab at playback, which works: zapier@6b7b3a1 |
@bryanhelmig this idea is GENIUS! I'm implementing it right now |
If you look at vcrpy, a similar library, they don't have two context managers ( How can I help you @gabrielfalcao? |
What about: recording:with HTTPretty.record('~/work/project/tests/httpbin.json') as request_registry:
response = requests.post('http://httpbin.org/post', {'hello': 'world!'})
if response.status_code is 200:
request_registry.save_chapter(response) replayingwith HTTPretty.playback('/path/to/hello-world.json') as context:
response = requests.post('http://httpbin.org/post', {'hello': 'world!'})
assert 200 is response.status_code
assert 'application/json' is response.headers['Content-Type']
assert 'origin' in response.json
assert 'form' in response.json or from httpretty import httprettified
@httprettified.by('/path/to/hello-world.json'):
def test_httpbin_api_integration(context)
response = requests.post('http://httpbin.org/post', {'hello': 'world!'})
assert 200 is response.status_code
assert 'application/json' is response.headers['Content-Type']
assert 'origin' in response.json
assert 'form' in response.json how is that? |
Gabriel, The one with the decorator would be perfect if it does what Bryan suggests:
Some way to force a refresh of all the HTTP fixtures in a test suite, using for example a |
+1 on the decorator, but be sure to offer it as context manager as well! |
You can get some inspiration from here: https://github.com/vcr/vcr |
@gabrielfalcao, I can visit this issue if you haven't done so already. I'll be working on a forked copy. Send a pull request when ready. |
Perfect, I actually never had time to do it |
Anyone know if this issue still under consideration/development? |
@bjmc - I think it's dead unless you work on it. |
gittips are also a great motivation :D |
TODO: * Add context managers for easier use * Update docs
TODO: * Add context managers for easier use * Update docs
TODO: * Update docs * Add tests for newfunctionality
Check out vcr.py if you are interested in a project implementing this API :) |
+1 for vcr.py implementing the API. I love the concept of replayable fixtures. As GitHub rightly links, the main issues are to overcome values that change from one request to the next such as nonces and signatures, which cause cache misses. |
Hey guys, love love love this library (we Zapier folk do a lot of API stuff).
What I'd like to see is a pattern like this (I haven't had a chance to dive into the code much yet, so please forgive odd naming and such):
Now, located in
/path/to/hello-world.json
would be written a JSON file like the one below.I didn't bother to show full request/response serialization as it would probably be recorded, but I assume it could be partially defined with sensible defaults if you feel like hand rolling JSON and saving a few (a lot) of characters.
As long as you guys are cool with such a pattern and have no particular pointers on implementation, I'll dig in and make this happen. Its gonna be incredibly useful!
The text was updated successfully, but these errors were encountered: