mirror of
https://github.com/kennethreitz/responder.git
synced 2026-06-05 06:46:14 +00:00
logos
This commit is contained in:
@@ -61,8 +61,8 @@ api.add_route("/graph", graphene.Schema(query=Query))
|
||||
We can then send a query to our service:
|
||||
|
||||
```pycon
|
||||
>>> requests = api.session(base_url="http://app/")
|
||||
>>> r = requests.get("http://app/graph", params={"query": "{ hello }"})
|
||||
>>> requests = api.session()
|
||||
>>> r = requests.get("http://:/graph", params={"query": "{ hello }"})
|
||||
>>> r.json()
|
||||
{'data': {'hello': 'Hello stranger'}}
|
||||
```
|
||||
@@ -70,7 +70,7 @@ We can then send a query to our service:
|
||||
Or, request YAML back:
|
||||
|
||||
```pycon
|
||||
>>> r = requests.get("http://app/graph", params={"query": "{ hello(name:\"john\") }"}, headers={"Accept": "application/x-yaml"})
|
||||
>>> r = requests.get("http://:/graph", params={"query": "{ hello(name:\"john\") }"}, headers={"Accept": "application/x-yaml"})
|
||||
>>> print(r.text)
|
||||
data: {hello: Hello john}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ def hello_world():
|
||||
return "Hello, World from flask!"
|
||||
|
||||
|
||||
api = responder.API(enable_hsts=True)
|
||||
api = responder.API(enable_hsts=False)
|
||||
api.mount("/hello", app)
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 349 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 762 KiB |
+49431
File diff suppressed because one or more lines are too long
+3
-3
@@ -27,7 +27,7 @@ class API:
|
||||
self.static_dir = Path(os.path.abspath(static_dir))
|
||||
self.templates_dir = Path(os.path.abspath(templates_dir))
|
||||
self.routes = {}
|
||||
self.enable_hsts = enable_hsts
|
||||
self.hsts_enabled = enable_hsts
|
||||
self.apps = {"/": self._wsgi_app}
|
||||
|
||||
# Make the static/templates directory if they don't exist.
|
||||
@@ -96,7 +96,7 @@ class API:
|
||||
route = self.path_matches_route(req.path)
|
||||
resp = models.Response(req=req)
|
||||
|
||||
if self.enable_hsts:
|
||||
if self.hsts_enabled:
|
||||
if req.url.startswith("http://"):
|
||||
url = req.url.replace("http://", "https://", 1)
|
||||
self.redirect(resp, location=url)
|
||||
@@ -203,7 +203,7 @@ class API:
|
||||
def mount(self, route, wsgi_app):
|
||||
self.apps.update({route: wsgi_app})
|
||||
|
||||
def session(self, base_url="http://app"):
|
||||
def session(self, base_url="http://;"):
|
||||
if self._session is None:
|
||||
session = RequestsSession()
|
||||
session.mount(base_url, RequestsWSGIAdapter(self))
|
||||
|
||||
+8
-10
@@ -102,7 +102,7 @@ def test_requests_session_works(api):
|
||||
def hello(req, resp):
|
||||
resp.text = TEXT
|
||||
|
||||
assert api.session().get("http://app/").text == TEXT
|
||||
assert api.session().get("http://;/").text == TEXT
|
||||
|
||||
|
||||
def test_status_code(api):
|
||||
@@ -111,9 +111,7 @@ def test_status_code(api):
|
||||
resp.text = "keep going"
|
||||
resp.status_code = responder.status_codes.HTTP_416
|
||||
|
||||
assert (
|
||||
api.session().get("http://app/").status_code == responder.status_codes.HTTP_416
|
||||
)
|
||||
assert api.session().get("http://;/").status_code == responder.status_codes.HTTP_416
|
||||
|
||||
|
||||
def test_json_media(api):
|
||||
@@ -123,7 +121,7 @@ def test_json_media(api):
|
||||
def media(req, resp):
|
||||
resp.media = dump
|
||||
|
||||
r = api.session().get("http://app/")
|
||||
r = api.session().get("http://;/")
|
||||
|
||||
assert "json" in r.headers["Content-Type"]
|
||||
assert r.json() == dump
|
||||
@@ -136,7 +134,7 @@ def test_yaml_media(api):
|
||||
def media(req, resp):
|
||||
resp.media = dump
|
||||
|
||||
r = api.session().get("http://app/", headers={"Accept": "yaml"})
|
||||
r = api.session().get("http://;/", headers={"Accept": "yaml"})
|
||||
|
||||
assert "yaml" in r.headers["Content-Type"]
|
||||
assert yaml.load(r.content) == dump
|
||||
@@ -145,7 +143,7 @@ def test_yaml_media(api):
|
||||
def test_graphql_schema_query_querying(api, schema):
|
||||
api.add_route("/", schema)
|
||||
|
||||
r = api.session().get("http://app/?q={ hello }", headers={"Accept": "json"})
|
||||
r = api.session().get("http://;/?q={ hello }", headers={"Accept": "json"})
|
||||
assert r.json() == {"data": {"hello": None}}
|
||||
|
||||
|
||||
@@ -154,7 +152,7 @@ def test_argumented_routing(api):
|
||||
def hello(req, resp, *, name):
|
||||
resp.text = f"Hello, {name}."
|
||||
|
||||
r = api.session().get("http://app/sean")
|
||||
r = api.session().get("http://;/sean")
|
||||
assert r.text == "Hello, sean."
|
||||
|
||||
|
||||
@@ -163,7 +161,7 @@ def test_mote_argumented_routing(api):
|
||||
def hello(req, resp, *, greeting, name):
|
||||
resp.text = f"{greeting}, {name}."
|
||||
|
||||
r = api.session().get("http://app/hello/lyndsy")
|
||||
r = api.session().get("http://;/hello/lyndsy")
|
||||
assert r.text == "hello, lyndsy."
|
||||
|
||||
|
||||
@@ -176,6 +174,6 @@ def test_request_and_get(api):
|
||||
def on_get(self, request, resp):
|
||||
resp.headers.update({"LIFE": "42"})
|
||||
|
||||
r = api.session().get("http://app/")
|
||||
r = api.session().get("http://;/")
|
||||
assert "DEATH" in r.headers
|
||||
assert "LIFE" in r.headers
|
||||
|
||||
Reference in New Issue
Block a user