Add support for Response parameters to set headers, cookies, and status codes (#294)

*  Add support for declaring a Response parameter to set headers and cookies

*  Add source for docs and tests

* 📝 Add docs for setting headers, cookies and status code

* 📝 Add attribution to Hug for inspiring response parameters
This commit is contained in:
Sebastián Ramírez
2019-06-06 14:29:40 +04:00
committed by GitHub
parent c8eea09664
commit 5f7fe926ab
17 changed files with 229 additions and 13 deletions

View File

@@ -0,0 +1,15 @@
from starlette.testclient import TestClient
from response_change_status_code.tutorial001 import app
client = TestClient(app)
def test_path_operation():
response = client.put("/get-or-create-task/foo")
print(response.content)
assert response.status_code == 200
assert response.json() == "Listen to the Bar Fighters"
response = client.put("/get-or-create-task/bar")
assert response.status_code == 201
assert response.json() == "This didn't exist before"

View File

@@ -0,0 +1,12 @@
from starlette.testclient import TestClient
from response_cookies.tutorial002 import app
client = TestClient(app)
def test_path_operation():
response = client.post("/cookie-and-object/")
assert response.status_code == 200
assert response.json() == {"message": "Come to the dark side, we have cookies"}
assert response.cookies["fakesession"] == "fake-cookie-session-value"

View File

@@ -0,0 +1,12 @@
from starlette.testclient import TestClient
from response_headers.tutorial002 import app
client = TestClient(app)
def test_path_operation():
response = client.get("/headers-and-object/")
assert response.status_code == 200
assert response.json() == {"message": "Hello World"}
assert response.headers["X-Cat-Dog"] == "alone in the world"