mirror of
https://github.com/django/django.git
synced 2025-06-23 20:39:12 +00:00
Refs #36467 -- Added test for Set-Cookie header values in ASGIHandler.
This commit is contained in:
parent
1520870c4a
commit
1cd91d5d4b
@ -78,6 +78,16 @@ class ASGITest(SimpleTestCase):
|
|||||||
# Allow response.close() to finish.
|
# Allow response.close() to finish.
|
||||||
await communicator.wait()
|
await communicator.wait()
|
||||||
|
|
||||||
|
async def test_asgi_cookies(self):
|
||||||
|
application = get_asgi_application()
|
||||||
|
scope = self.async_request_factory._base_scope(path="/cookie/")
|
||||||
|
communicator = ApplicationCommunicator(application, scope)
|
||||||
|
await communicator.send_input({"type": "http.request"})
|
||||||
|
response_start = await communicator.receive_output()
|
||||||
|
self.assertIn((b"Set-Cookie", b"key=value; Path=/"), response_start["headers"])
|
||||||
|
# Allow response.close() to finish.
|
||||||
|
await communicator.wait()
|
||||||
|
|
||||||
# Python's file API is not async compatible. A third-party library such
|
# Python's file API is not async compatible. A third-party library such
|
||||||
# as https://github.com/Tinche/aiofiles allows passing the file to
|
# as https://github.com/Tinche/aiofiles allows passing the file to
|
||||||
# FileResponse as an async iterator. With a sync iterator
|
# FileResponse as an async iterator. With a sync iterator
|
||||||
|
@ -25,6 +25,12 @@ def hello_meta(request):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def hello_cookie(request):
|
||||||
|
response = HttpResponse("Hello World!")
|
||||||
|
response.set_cookie("key", "value")
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
def sync_waiter(request):
|
def sync_waiter(request):
|
||||||
with sync_waiter.lock:
|
with sync_waiter.lock:
|
||||||
sync_waiter.active_threads.add(threading.current_thread())
|
sync_waiter.active_threads.add(threading.current_thread())
|
||||||
@ -61,6 +67,7 @@ test_filename = __file__
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", hello),
|
path("", hello),
|
||||||
|
path("cookie/", hello_cookie),
|
||||||
path("file/", lambda x: FileResponse(open(test_filename, "rb"))),
|
path("file/", lambda x: FileResponse(open(test_filename, "rb"))),
|
||||||
path("meta/", hello_meta),
|
path("meta/", hello_meta),
|
||||||
path("post/", post_echo),
|
path("post/", post_echo),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user