mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
response.set_cookie(), closes #795
This commit is contained in:
parent
f240970b83
commit
008e2f63c2
6 changed files with 108 additions and 31 deletions
|
|
@ -1,4 +1,5 @@
|
|||
from datasette.utils.asgi import Response
|
||||
import pytest
|
||||
|
||||
|
||||
def test_response_html():
|
||||
|
|
@ -26,3 +27,28 @@ def test_response_redirect():
|
|||
response = Response.redirect("/foo")
|
||||
assert 302 == response.status
|
||||
assert "/foo" == response.headers["Location"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_response_set_cookie():
|
||||
events = []
|
||||
|
||||
async def send(event):
|
||||
events.append(event)
|
||||
|
||||
response = Response.redirect("/foo")
|
||||
response.set_cookie("foo", "bar", max_age=10, httponly=True)
|
||||
await response.asgi_send(send)
|
||||
|
||||
assert [
|
||||
{
|
||||
"type": "http.response.start",
|
||||
"status": 302,
|
||||
"headers": [
|
||||
[b"Location", b"/foo"],
|
||||
[b"content-type", b"text/plain"],
|
||||
[b"set-cookie", b"foo=bar; HttpOnly; Max-Age=10; Path=/; SameSite=lax"],
|
||||
],
|
||||
},
|
||||
{"type": "http.response.body", "body": b""},
|
||||
] == events
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue