Skip to content

Commit 1f97c3c

Browse files
authored
Add default to response.cookies (#3047)
* Cleanup some typing * Add custom CLI commands * Add unit tests * Add default to response cookies
1 parent a767ade commit 1f97c3c

9 files changed

Lines changed: 108 additions & 132 deletions

File tree

guide/content/en/emoji.py

Lines changed: 94 additions & 114 deletions
Large diffs are not rendered by default.

guide/webapp/display/markdown.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def heading(self, text: str, level: int, **attrs) -> str:
5656
{
5757
"id": ident,
5858
"class": (
59-
f"is-size-{level}-desktop " f"is-size-{level+2}-touch"
59+
f"is-size-{level}-desktop is-size-{level + 2}-touch"
6060
),
6161
},
6262
text,

guide/webapp/display/plugins/tabs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,5 @@ def _render_tab(self, renderer: HTMLRenderer, text: str, **attrs):
5050
else ""
5151
)
5252
content = f'<div class="tab-content">{text}</div>\n'
53-
tab = f'<li><a>{attrs["title"]}</a>{content}</li>\n'
53+
tab = f"<li><a>{attrs['title']}</a>{content}</li>\n"
5454
return start + tab + end

sanic/cookies/response.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def cookies(self) -> list[Cookie]:
7373
Returns:
7474
List[Cookie]: A list of cookies in the CookieJar.
7575
"""
76-
return self.headers.getall(self.HEADER_KEY)
76+
return self.headers.getall(self.HEADER_KEY, [])
7777

7878
def get_cookie(
7979
self,

tests/test_cli.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,9 @@ def test_auto_reload(cmd: str, caplog, port):
250250
info = read_app_info(lines)
251251

252252
assert info["debug"] is False, f"Unexpected value of debug {info}"
253-
assert (
254-
info["auto_reload"] is True
255-
), f"Unexpected value of auto reload {info}"
253+
assert info["auto_reload"] is True, (
254+
f"Unexpected value of auto reload {info}"
255+
)
256256

257257

258258
@pytest.mark.parametrize(
@@ -273,9 +273,9 @@ def test_access_logs(cmd: str, expected: bool, caplog, port):
273273
info = read_app_info(lines)
274274
if info["access_log"] != expected:
275275
print(lines)
276-
assert (
277-
info["access_log"] is expected
278-
), f"Expected: {expected}. Received: {info}. Lines: {lines}"
276+
assert info["access_log"] is expected, (
277+
f"Expected: {expected}. Received: {info}. Lines: {lines}"
278+
)
279279

280280

281281
@pytest.mark.parametrize("cmd", ("--version", "-v"))

tests/test_headers.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,12 +386,10 @@ def test_accept_misc():
386386
)
387387
a = headers.parse_accept(header)
388388
assert repr(a) == (
389-
"[*/plain;param=123, text/plain, text/*, "
390-
"foo/bar;q=0.5, foo/bar;q=0.0]"
389+
"[*/plain;param=123, text/plain, text/*, foo/bar;q=0.5, foo/bar;q=0.0]"
391390
) # noqa: E501
392391
assert str(a) == (
393-
"*/plain;param=123, text/plain, text/*, "
394-
"foo/bar;q=0.5, foo/bar;q=0.0"
392+
"*/plain;param=123, text/plain, text/*, foo/bar;q=0.5, foo/bar;q=0.0"
395393
) # noqa: E501
396394
# q=1 types don't match foo/bar but match the two others,
397395
# text/* comes first and matches */plain because it

tests/test_request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ async def get(request):
8080
"/", headers={"X-REQUEST-ID": f"{request_id}"}
8181
)
8282
assert request.id == request_id
83-
assert type(request.id) == expected_type
83+
assert type(request.id) is expected_type
8484

8585

8686
def test_custom_generator():

tests/test_routes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ def handler(request):
11211121
return text("pass")
11221122

11231123
assert str(excinfo.value) == (
1124-
"Expected either string or Iterable of " "host strings, not {!r}"
1124+
"Expected either string or Iterable of host strings, not {!r}"
11251125
).format(host)
11261126

11271127

tests/test_views.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,7 @@ def _iternal_method(self):
195195

196196
def get(self, request):
197197
self._iternal_method()
198-
return text(
199-
f"I am get method and global var " f"is {self.global_var}"
200-
)
198+
return text(f"I am get method and global var is {self.global_var}")
201199

202200
app.add_route(DummyView.as_view(), "/")
203201
request, response = app.test_client.get("/")

0 commit comments

Comments
 (0)