From 4258aa85cbd5034ae5f34cdb550c69bc17f89490 Mon Sep 17 00:00:00 2001 From: Orenoid Date: Mon, 23 Sep 2024 02:36:33 +0800 Subject: [PATCH] test: pragma no branch --- starlette/requests.py | 6 +++--- tests/test_requests.py | 28 ---------------------------- 2 files changed, 3 insertions(+), 31 deletions(-) diff --git a/starlette/requests.py b/starlette/requests.py index 5cc26acf2..26c13d1ca 100644 --- a/starlette/requests.py +++ b/starlette/requests.py @@ -93,7 +93,7 @@ def app(self) -> typing.Any: @property def url(self) -> URL: - if not hasattr(self, "_url"): + if not hasattr(self, "_url"): # pragma: no branch self._url = URL(scope=self.scope) return self._url @@ -122,7 +122,7 @@ def headers(self) -> Headers: @property def query_params(self) -> QueryParams: - if not hasattr(self, "_query_params"): + if not hasattr(self, "_query_params"): # pragma: no branch self._query_params = QueryParams(self.scope["query_string"]) return self._query_params @@ -237,7 +237,7 @@ async def body(self) -> bytes: return self._body async def json(self) -> typing.Any: - if not hasattr(self, "_json"): + if not hasattr(self, "_json"): # pragma: no branch body = await self.body() self._json = json.loads(body) return self._json diff --git a/tests/test_requests.py b/tests/test_requests.py index 263479158..2f173713e 100644 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -28,34 +28,6 @@ async def app(scope: Scope, receive: Receive, send: Send) -> None: assert response.json() == {"method": "GET", "url": "https://example.org:123/"} -def test_request_lazy_load_property(test_client_factory: TestClientFactory) -> None: - async def app(scope: Scope, receive: Receive, send: Send) -> None: - request = Request(scope, receive) - assert not hasattr(request, "_url") - assert not hasattr(request, "_query_params") - assert not hasattr(request, "_json") - # trigger lazy loading - _, _, _ = request.url, request.query_params, await request.json() - assert hasattr(request, "_url") - assert hasattr(request, "_query_params") - assert hasattr(request, "_json") - data = { - "url": str(request.url), - "query_params": dict(request.query_params), - "json": await request.json(), - } - response = JSONResponse(data) - await response(scope, receive, send) - - client = test_client_factory(app) - response = client.post("/42?foo=bar", json={"baz": "qux"}) - assert response.json() == { - "url": "http://testserver/42?foo=bar", - "query_params": {"foo": "bar"}, - "json": {"baz": "qux"}, - } - - def test_request_query_params(test_client_factory: TestClientFactory) -> None: async def app(scope: Scope, receive: Receive, send: Send) -> None: request = Request(scope, receive)