code reformatting

This commit is contained in:
Vincent Maillol 2021-07-11 07:31:37 +02:00
parent 08ab4d2610
commit 89a22f2fcd
9 changed files with 33 additions and 14 deletions

View File

@ -1,5 +1,5 @@
from .view import PydanticView
__version__ = "1.9.0"
__version__ = "1.9.1"
__all__ = ("PydanticView", "__version__")

View File

@ -305,7 +305,10 @@ class Components:
class OpenApiSpec3:
def __init__(self):
self._spec = {"openapi": "3.0.0", "info": {"version": "1.0.0", "title": "Aiohttp pydantic application"}}
self._spec = {
"openapi": "3.0.0",
"info": {"version": "1.0.0", "title": "Aiohttp pydantic application"},
}
@property
def info(self) -> Info:

View File

@ -147,7 +147,11 @@ def _add_http_method_to_oas(
)
def generate_oas(apps: List[Application], version_spec: Optional[str] = None, title_spec: Optional[str] = None) -> dict:
def generate_oas(
apps: List[Application],
version_spec: Optional[str] = None,
title_spec: Optional[str] = None,
) -> dict:
"""
Generate and return Open Api Specification from PydanticView in application.
"""

View File

@ -60,7 +60,9 @@ class PydanticView(AbstractView):
def raise_not_allowed(self) -> None:
warnings.warn(
"PydanticView.raise_not_allowed is deprecated and renamed _raise_allowed_methods",
DeprecationWarning, stacklevel=2)
DeprecationWarning,
stacklevel=2,
)
self._raise_allowed_methods()
@staticmethod

View File

@ -28,7 +28,6 @@ class PydanticViewParent(PydanticView):
def test_allowed_methods_get_decorated_exactly_once():
class ChildView(PydanticViewParent):
async def post(self, id: int, /):
pass
@ -44,7 +43,6 @@ def test_allowed_methods_get_decorated_exactly_once():
def test_methods_inherited_from_aiohttp_view_should_not_be_decorated():
class ChildView(AiohttpViewParent, PydanticView):
async def post(self, id: int, /):
pass
@ -54,7 +52,6 @@ def test_methods_inherited_from_aiohttp_view_should_not_be_decorated():
def test_allowed_methods_are_set_correctly():
class ChildView(AiohttpViewParent, PydanticView):
async def post(self, id: int, /):
pass

View File

@ -22,7 +22,7 @@ def test_show_oas_of_app(cmd_line):
args.func(args)
expected = dedent(
"""
"""
{
"info": {
"title": "Aiohttp pydantic application",
@ -73,7 +73,7 @@ def test_show_oas_of_sub_app(cmd_line):
args.output = StringIO()
args.func(args)
expected = dedent(
"""
"""
{
"info": {
"title": "Aiohttp pydantic application",

View File

@ -37,7 +37,10 @@ def test_info_version():
assert oas.info.version == "1.0.0"
oas.info.version = "3.14"
assert oas.info.version == "3.14"
assert oas.spec == {"info": {"version": "3.14", "title": "Aiohttp pydantic application"}, "openapi": "3.0.0"}
assert oas.spec == {
"info": {"version": "3.14", "title": "Aiohttp pydantic application"},
"openapi": "3.0.0",
}
def test_info_terms_of_service():

View File

@ -318,22 +318,32 @@ async def test_simple_type_route_should_have_get_method(generated_oas):
},
}
async def test_generated_view_info_default():
apps = (web.Application(),)
spec = generate_oas(apps)
assert spec == {'info': {'title': 'Aiohttp pydantic application', 'version': '1.0.0'}, 'openapi': '3.0.0'}
assert spec == {
"info": {"title": "Aiohttp pydantic application", "version": "1.0.0"},
"openapi": "3.0.0",
}
async def test_generated_view_info_as_version():
apps = (web.Application(),)
spec = generate_oas(apps, version_spec="test version")
assert spec == {'info': {'title': 'Aiohttp pydantic application', 'version': 'test version'}, 'openapi': '3.0.0'}
assert spec == {
"info": {"title": "Aiohttp pydantic application", "version": "test version"},
"openapi": "3.0.0",
}
async def test_generated_view_info_as_title():
apps = (web.Application(),)
spec = generate_oas(apps, title_spec="test title")
assert spec == {'info': {'title': 'test title', 'version': '1.0.0'}, 'openapi': '3.0.0'}
assert spec == {
"info": {"title": "test title", "version": "1.0.0"},
"openapi": "3.0.0",
}

View File

@ -11,7 +11,7 @@ class ArticleView(PydanticView):
with_comments: bool,
age: Optional[int] = None,
nb_items: int = 7,
tags: List[str] = Field(default_factory=list)
tags: List[str] = Field(default_factory=list),
):
return web.json_response(
{