Skip to content

Commit

Permalink
test: add tests in test_requests (#2677)
Browse files Browse the repository at this point in the history
* test: add tests in test_requests

* test: add test for Request.close method

* fix: typo

* test: ignore conditional branch in coverage report and remove unnecessary test

* test: pragma no branch

---------

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
  • Loading branch information
Orenoid and Kludex authored Sep 23, 2024
1 parent d289ac7 commit 4fbf766
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions starlette/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -276,7 +276,7 @@ def form(
return AwaitableOrContextManagerWrapper(self._get_form(max_files=max_files, max_fields=max_fields))

async def close(self) -> None:
if self._form is not None:
if self._form is not None: # pragma: no branch
await self._form.close()

async def is_disconnected(self) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ async def app(scope: Scope, receive: Receive, send: Send) -> None:
# Browsers don't send extra whitespace or semicolons in Cookie headers,
# but cookie_parser() should parse whitespace the same way
# document.cookie parses whitespace.
# (" = b ; ; = ; c = ; ", {"": "b", "c": ""}),
(" = b ; ; = ; c = ; ", {"": "b", "c": ""}),
],
)
def test_cookies_invalid(
Expand Down

0 comments on commit 4fbf766

Please sign in to comment.