Skip to content

Commit

Permalink
Update openapi-core to 0.19.4+
Browse files Browse the repository at this point in the history
  • Loading branch information
correl committed Oct 21, 2024
1 parent 10de1bd commit 5d44207
Show file tree
Hide file tree
Showing 12 changed files with 425 additions and 519 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ packages = [
[tool.poetry.dependencies]
python = "^3.9"
tornado = "^5 || ^6"
openapi-core = "^0.14.2"
openapi-core = "^0.19.4"
ietfparse = "^1.8.0"
typing-extensions = "^4.0.1"

Expand Down
21 changes: 21 additions & 0 deletions tests/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import hypothesis.strategies as s
from werkzeug.datastructures import Headers

field_names = s.text(
s.characters(
min_codepoint=33,
max_codepoint=126,
blacklist_categories=["Lu"],
blacklist_characters=":\r\n",
),
min_size=1,
)

field_values = s.text(
s.characters(min_codepoint=0x20, max_codepoint=0x7E, blacklist_characters="; \r\n"),
min_size=1,
)

headers: s.SearchStrategy[Headers] = s.builds(
Headers, s.lists(s.tuples(field_names, field_values))
)
43 changes: 22 additions & 21 deletions tests/test_handler.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import datetime
import json
import re
import typing
import unittest.mock

from openapi_core.exceptions import OpenAPIError # type: ignore
from openapi_core.exceptions import OpenAPIError
import tornado.httpclient
import tornado.web
import tornado.testing

from tornado_openapi3.handler import OpenAPIRequestHandler
from tornado_openapi3.types import Deserializer, Formatter


class USDateFormatter:
Expand Down Expand Up @@ -74,23 +76,25 @@ class ResourceHandler(OpenAPIRequestHandler):
},
}

custom_formatters = {
"usdate": USDateFormatter(),
}
@property
def custom_formatters(self) -> typing.Dict[str, Formatter]:
return {
"usdate": USDateFormatter(),
}

custom_media_type_deserializers = {
"application/vnd.example.resource+json": json.loads,
}
@property
def custom_media_type_deserializers(self) -> typing.Dict[str, Deserializer]:
return {
"application/vnd.example.resource+json": json.loads,
}

async def post(self) -> None:
self.set_header("Content-Type", "application/vnd.example.resource+json")
self.finish(
json.dumps(
{
"name": self.validated.body["name"],
}
)
)
body = b""
if isinstance(self.validated.body, dict) and "name" in self.validated.body:
body = json.dumps({"name": self.validated.body["name"]}).encode()

self.finish(body)


class DefaultSchemaTest(tornado.testing.AsyncHTTPTestCase):
Expand All @@ -102,8 +106,7 @@ async def prepare(self) -> None:
with test.assertRaises(NotImplementedError):
self.spec

async def get(self) -> None:
...
async def get(self) -> None: ...

return tornado.web.Application(
[
Expand All @@ -124,8 +127,7 @@ class RequestHandler(OpenAPIRequestHandler):
async def prepare(self) -> None:
test.assertEqual(dict(), self.custom_formatters)

async def get(self) -> None:
...
async def get(self) -> None: ...

return tornado.web.Application(
[
Expand All @@ -146,8 +148,7 @@ class RequestHandler(OpenAPIRequestHandler):
async def prepare(self) -> None:
test.assertEqual(dict(), self.custom_media_type_deserializers)

async def get(self) -> None:
...
async def get(self) -> None: ...

return tornado.web.Application(
[
Expand Down Expand Up @@ -246,7 +247,7 @@ def test_format_error(self) -> None:

def test_unexpected_openapi_error(self) -> None:
with unittest.mock.patch(
"openapi_core.validation.datatypes.BaseValidationResult.raise_for_errors",
"openapi_core.OpenAPI.unmarshal_request",
side_effect=OpenAPIError,
):
response = self.fetch(
Expand Down
Loading

0 comments on commit 5d44207

Please sign in to comment.