Comments (6)
BTW this is a nice library. I just used it in some of my tests!
from httpretty.
HI @lsemel, first of all, thanks for the feedback.
I don't quite understand what you mean with builtin urls. What is the goal you want to achieve?
from httpretty.
Here's an example from tests I wrote yesterday. I was testing code that makes HTTP requests, to ensure it reacts properly when it gets different response codes (specifically, that it retries a certain number of times after a certain interval when it gets a 500 error, but doesn't do this when it gets a 404 or 200).
To do this, I pointed it at the httpbin.org service, which provides URLs like this can be used to test HTTP clients, specifically https://httpbin.org/status/[status_code], which will always return the specified status code. This works well, except my tests are going to fail if httpbin.org ever goes down.
If I wanted to make my tests self-contained by replacing httpbin.org with HTTPretty, I'd have to do the following in my test setup:
HTTPretty.register_uri(HTTPretty.GET, "http://foobar.com/500",status=500)
HTTPretty.register_uri(HTTPretty.GET, "http://foobar.com/404",status=404)
HTTPretty.register_uri(HTTPretty.GET, "http://foobar.com/200",status=200)
And then reuse those URLs within my tests.
@httprettified
def test_500(self):
result = do_something_with_url('http://foobar.com/500')
If httpretty had some of the urls of httpbin.org built in, for the most common cases (like returning a specific status code, returning specific response headers, or returning get and post data) it'd save a lot of repetition in registering urls to set up tests and mimic the experience of using something like httpbin.org
from httpretty.
What about the response rotation API?
from httpretty import httprettified, HTTPretty
from lsemel.core import API
@httprettified
def test_my_code_reacs_appropriately_when_taking_a_500():
HTTPretty.register_uri(HTTPretty.GET, "http://api.lsemel.com/v1/whatever",
responses=[
HTTPretty.Response(status=200),
HTTPretty.Response(status=404),
HTTPretty.Response(status=500),
]))
api = API()
assert api.fetch_whatever_data() == "OK" # HTTPretty returned 200 so that's ok
assert api.fetch_whatever_data() == "OK" # HTTPretty returned 404 so that's ok
assert api.fetch_whatever_data() == "FAILED!" # HTTPretty returned 500 so that's bad!!!
from httpretty.
I might not have understood your idea completely, but from what I can understand, having a preset of some URL's does not make much sense because:
- HTTPretty users would need to learn by heart what are the default URL's
- The code you are testing will need to hardcode access to a fake URL (i.e: foobar.com)
- It's just easier to declare responses in HTTPretty so rather than memorizing predefined URLs the developer that already knows how to use HTTPretty has full control over the expected responses.
Thoughts?!
from httpretty.
Can I close this issue?
from httpretty.
Related Issues (20)
- 1.1.4: pytest is failing because missing `context` fixture HOT 2
- Record/Replay feature returns incorrect HTTP status code HOT 1
- ConnectionError when making multiple requests using a session on Windows HOT 1
- Dependency Dashboard
- Action Required: Fix Renovate Configuration
- Emulate server down then coming online HOT 1
- Incorrect examples in documentation (contextmanager) HOT 2
- 1.1.4: pytest is failing because missing `context` and `port` fixtures and some pytest warnings HOT 6
- httpretty.errors.UnmockedError: Failed to socket.setblocking because because a real socket does not exist HOT 1
- 1.1.4: sphinx warnings `reference target not found`
- Typing error when using callback as body
- State of project HOT 1
- test_httpretty_should_handle_paths_starting_with_two_slashes needs update HOT 1
- 1.1.4: Tests are failing on s390x because of "did not run within two miliseconds" HOT 1
- Document global allow_net_connect flag HOT 1
- Request body isn't decoded when client specifies its charset
- Link headers Example does not work
- Reset should blank latest_requests? HOT 1
- FakeSockFile: `'super' object has no attribute 'flush'` HOT 1
- urllib3.contrib.pyopenssl is being deprecated
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from httpretty.