Compare commits

..

4 Commits

Author SHA1 Message Date
L. Kärkkäinen
8027563144 Remove unused import 2023-09-20 20:11:45 +01:00
L. Kärkkäinen
875e921bda Do not strip entity-headers. 2023-09-20 19:59:35 +01:00
L. Kärkkäinen
11c841ab4e Add test for issue #2823 2023-09-20 19:58:44 +01:00
freddiewanah
a5a9658896 Refactor test cases to improve unit test quality (#2796)
Co-authored-by: Adam Hopkins <adam@amhopkins.com>
2023-09-07 15:26:56 +03:00
6 changed files with 15 additions and 24 deletions

View File

@@ -22,7 +22,6 @@ span.linenos.special { color: #000000; background-color: #ffffc0; padding-left:
.cs { color: #a2a2a2; font-style: italic } /* Comment.Special */
.gd { color: #777777 } /* Generic.Deleted */
.ge { color: #777777 } /* Generic.Emph */
.ges { color: #777777 } /* Generic.EmphStrong */
.gr { color: #777777 } /* Generic.Error */
.gh { color: #777777 } /* Generic.Heading */
.gi { color: #777777 } /* Generic.Inserted */

View File

@@ -1,8 +1,3 @@
sanic>=23.6.*
sanic-ext>=23.6.*
msgspec
python-frontmatter
pygments
docstring-parser
libsass
mistune

View File

@@ -1,11 +1,3 @@
"""Sanic User Guide
https://sanic.dev
Built using the SHH stack:
- Sanic
- html5tagger
- HTMX"""
from pathlib import Path
from webapp.worker.factory import create_app

View File

@@ -24,7 +24,6 @@ from sanic.helpers import (
Default,
_default,
has_message_body,
remove_entity_headers,
)
from sanic.http import Http
@@ -106,9 +105,6 @@ class BaseHTTPResponse:
Returns:
Iterator[Tuple[bytes, bytes]]: A list of header tuples encoded in bytes for sending
""" # noqa: E501
# TODO: Make a blacklist set of header names and then filter with that
if self.status in (304, 412): # Not Modified, Precondition Failed
self.headers = remove_entity_headers(self.headers)
if has_message_body(self.status):
self.headers.setdefault("content-type", self.content_type)
# Encode headers into bytes

View File

@@ -20,6 +20,7 @@ from pytest import LogCaptureFixture
from sanic import Request, Sanic
from sanic.compat import Header
from sanic.constants import DEFAULT_HTTP_CONTENT_TYPE
from sanic.cookies import CookieJar
from sanic.response import (
HTTPResponse,
@@ -177,6 +178,10 @@ def json_app(app):
async def unmodified_handler(request: Request):
return json(JSON_DATA, status=304)
@app.get("/precondition")
async def precondition_handler(request: Request):
return json(JSON_DATA, status=412)
@app.delete("/")
async def delete_handler(request: Request):
return json(None, status=204)
@@ -192,6 +197,10 @@ def test_json_response(json_app):
assert response.text == json_dumps(JSON_DATA)
assert response.json == JSON_DATA
request, response = json_app.test_client.get("/precondition")
assert response.status == 412
assert response.json == JSON_DATA
def test_no_content(json_app):
request, response = json_app.test_client.get("/no-content")
@@ -545,7 +554,7 @@ def test_raw_response(app):
return raw(b"raw_response")
request, response = app.test_client.get("/test")
assert response.content_type == "application/octet-stream"
assert response.content_type == DEFAULT_HTTP_CONTENT_TYPE
assert response.body == b"raw_response"

View File

@@ -502,7 +502,7 @@ def test_dynamic_route_int(app):
request, response = app.test_client.get("/folder/12345")
assert response.text == "OK"
assert type(results[0]) is int
assert isinstance(results[0], int)
request, response = app.test_client.get("/folder/asdf")
assert response.status == 404
@@ -518,7 +518,7 @@ def test_dynamic_route_number(app):
request, response = app.test_client.get("/weight/12345")
assert response.text == "OK"
assert type(results[0]) is float
assert isinstance(results[0], float)
request, response = app.test_client.get("/weight/1234.56")
assert response.status == 200
@@ -567,7 +567,7 @@ def test_dynamic_route_uuid(app):
url = "/quirky/123e4567-e89b-12d3-a456-426655440000"
request, response = app.test_client.get(url)
assert response.text == "OK"
assert type(results[0]) is uuid.UUID
assert isinstance(results[0], uuid.UUID)
generated_uuid = uuid.uuid4()
request, response = app.test_client.get(f"/quirky/{generated_uuid}")
@@ -861,7 +861,7 @@ def test_dynamic_add_route_int(app):
request, response = app.test_client.get("/folder/12345")
assert response.text == "OK"
assert type(results[0]) is int
assert isinstance(results[0], int)
request, response = app.test_client.get("/folder/asdf")
assert response.status == 404
@@ -878,7 +878,7 @@ def test_dynamic_add_route_number(app):
request, response = app.test_client.get("/weight/12345")
assert response.text == "OK"
assert type(results[0]) is float
assert isinstance(results[0], float)
request, response = app.test_client.get("/weight/1234.56")
assert response.status == 200