diff --git a/starlette/endpoints.py b/starlette/endpoints.py index eb1dace42..107690266 100644 --- a/starlette/endpoints.py +++ b/starlette/endpoints.py @@ -74,7 +74,7 @@ async def dispatch(self) -> None: if message["type"] == "websocket.receive": data = await self.decode(websocket, message) await self.on_receive(websocket, data) - elif message["type"] == "websocket.disconnect": + elif message["type"] == "websocket.disconnect": # pragma: no branch close_code = int(message.get("code") or status.WS_1000_NORMAL_CLOSURE) break except Exception as exc: diff --git a/starlette/middleware/wsgi.py b/starlette/middleware/wsgi.py index 71f4ab5de..6e0a3fae6 100644 --- a/starlette/middleware/wsgi.py +++ b/starlette/middleware/wsgi.py @@ -121,7 +121,7 @@ def start_response( exc_info: typing.Any = None, ) -> None: self.exc_info = exc_info - if not self.response_started: + if not self.response_started: # pragma: no branch self.response_started = True status_code_string, _ = status.split(" ", 1) status_code = int(status_code_string) diff --git a/starlette/templating.py b/starlette/templating.py index 78bfb8c26..6b01aac92 100644 --- a/starlette/templating.py +++ b/starlette/templating.py @@ -43,7 +43,7 @@ def __init__( async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None: request = self.context.get("request", {}) extensions = request.get("extensions", {}) - if "http.response.debug" in extensions: + if "http.response.debug" in extensions: # pragma: no branch await send( { "type": "http.response.debug", diff --git a/tests/test_responses.py b/tests/test_responses.py index 9f801419a..28f2feb2d 100644 --- a/tests/test_responses.py +++ b/tests/test_responses.py @@ -393,6 +393,18 @@ async def app(scope: Scope, receive: Receive, send: Send) -> None: assert response.headers["set-cookie"] == "mycookie=myvalue; SameSite=lax" +def test_set_cookie_samesite_none(test_client_factory: TestClientFactory) -> None: + async def app(scope: Scope, receive: Receive, send: Send) -> None: + response = Response("Hello, world!", media_type="text/plain") + response.set_cookie("mycookie", "myvalue", samesite=None) + await response(scope, receive, send) + + client = test_client_factory(app) + response = client.get("/") + assert response.text == "Hello, world!" + assert response.headers["set-cookie"] == "mycookie=myvalue; Path=/" + + @pytest.mark.parametrize( "expires", [ diff --git a/tests/test_staticfiles.py b/tests/test_staticfiles.py index 8f7423593..b4f131719 100644 --- a/tests/test_staticfiles.py +++ b/tests/test_staticfiles.py @@ -216,6 +216,21 @@ def test_staticfiles_304_with_etag_match(tmpdir: Path, test_client_factory: Test assert second_resp.content == b"" +def test_staticfiles_200_with_etag_mismatch(tmpdir: Path, test_client_factory: TestClientFactory) -> None: + path = os.path.join(tmpdir, "example.txt") + with open(path, "w") as file: + file.write("") + + app = StaticFiles(directory=tmpdir) + client = test_client_factory(app) + first_resp = client.get("/example.txt") + assert first_resp.status_code == 200 + assert first_resp.headers["etag"] != '"123"' + second_resp = client.get("/example.txt", headers={"if-none-match": '"123"'}) + assert second_resp.status_code == 200 + assert second_resp.content == b"" + + def test_staticfiles_304_with_last_modified_compare_last_req( tmpdir: Path, test_client_factory: TestClientFactory ) -> None: