MCPcopy
hub / github.com/encode/starlette / test_request_cookies

Function test_request_cookies

tests/test_requests.py:340–356  ·  tests/test_requests.py::test_request_cookies
(test_client_factory: TestClientFactory)

Source from the content-addressed store, hash-verified

338
339
340def test_request_cookies(test_client_factory: TestClientFactory) -> None:
341 async def app(scope: Scope, receive: Receive, send: Send) -> None:
342 request = Request(scope, receive)
343 mycookie = request.cookies.get(class="st">"mycookie")
344 if mycookie:
345 response = Response(mycookie, media_type=class="st">"text/plain")
346 else:
347 response = Response(class="st">"Hello, world!", media_type=class="st">"text/plain")
348 response.set_cookie(class="st">"mycookie", class="st">"Hello, cookies!")
349
350 await response(scope, receive, send)
351
352 client = test_client_factory(app)
353 response = client.get(class="st">"/")
354 assert response.text == class="st">"Hello, world!"
355 response = client.get(class="st">"/")
356 assert response.text == class="st">"Hello, cookies!"
357
358
359def test_cookie_lenient_parsing(test_client_factory: TestClientFactory) -> None:

Callers

nothing calls this directly

Calls 2

test_client_factoryFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected