File tree Expand file tree Collapse file tree 13 files changed +32
-24
lines changed
tests/test_app_name_snake_case
test_presentation/test_fastapi Expand file tree Collapse file tree 13 files changed +32
-24
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ WORKDIR /app
44
55ENV UV_LINK_MODE copy
66ENV UV_PROJECT_ENVIRONMENT /run/app/.venv
7- ENV UV_CACHE_DIR copy /run/app/uv
7+ ENV UV_CACHE_DIR /run/app/uv
88
99ENV PYTHONPATH /app/src:/app/tests
1010ENV WATCHFILES_FORCE_POLLING true
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ build-backend = "hatchling.build"
4242packages = [" src/app_name_snake_case" ]
4343
4444[project .scripts ]
45- app-name-kebab-case-fastapi-dev = " app_name_snake_case.entrypoint.web_service .__main__:main"
45+ app-name-kebab-case-fastapi-dev = " app_name_snake_case.main.fastapi .__main__:main"
4646
4747[tool .mypy ]
4848mypy_path = " $MYPY_CONFIG_FILE_DIR/src:$MYPY_CONFIG_FILE_DIR/tests"
Original file line number Diff line number Diff line change 11from dataclasses import dataclass
22
3+ from app_name_snake_case .application .ports .transaction import Transaction
34from app_name_snake_case .application .ports .user_id_signing import UserIDSigning
45from app_name_snake_case .application .ports .user_views import UserViews
56
89class ViewUser [SignedUserIDT , UserViewT , UserViewWithIDT ]:
910 user_id_signing : UserIDSigning [SignedUserIDT ]
1011 user_views : UserViews [UserViewT , UserViewWithIDT ]
12+ transaction : Transaction
1113
1214 async def __call__ (
1315 self , signed_user_id : SignedUserIDT | None
@@ -19,4 +21,5 @@ async def __call__(
1921 signed_user_id = signed_user_id
2022 )
2123
22- return await self .user_views .view_of_user_with_id (user_id )
24+ async with self .transaction :
25+ return await self .user_views .view_of_user_with_id (user_id )
Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ async def provide_postgres_session(
5858 @provide (scope = Scope .APP )
5959 def provide_user_id_signing (
6060 self , envs : Envs
61- ) -> UserIDSigning [str ]:
61+ ) -> AnyOf [ UserIDSigningToHS256JWT , UserIDSigning [JWT ] ]:
6262 return UserIDSigningToHS256JWT (secret = envs .jwt_secret )
6363
6464 @provide (scope = Scope .REQUEST )
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ async def view_of_user_with_id(
2727 return None
2828
2929 user_name : str | None = await self .session .scalar (
30- select (user_table .c .name ).where (user_table .c .name )
30+ select (user_table .c .name ).where (user_table .c .id == user_id )
3131 )
3232 if user_name is None :
3333 return None
Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ async def app_from(container: AsyncContainer) -> FastAPI:
5454 app = _FastAPIWithAdditionalModels (
5555 title = "app-name-kebab-case" ,
5656 version = version ,
57- summary = "app_name_description" ,
57+ summary = "app_name_description. " ,
5858 openapi_tags = tags_metadata ,
5959 contact = {"name" : "Alexander Smolin" , "url" : author_url },
6060 license_info = {
Original file line number Diff line number Diff line change @@ -45,9 +45,7 @@ def __new__(
4545 ] # type: ignore[assignment]
4646 type_ .StrWithLock = Annotated [str , Depends (api_key_with_auto_error )] # type: ignore[assignment]
4747
48- type_ .StrOrNone = Annotated [
49- str | None , FastAPICookie (alias = key , default = None )
50- ] # type: ignore[assignment]
48+ type_ .StrOrNone = Annotated [str | None , FastAPICookie (alias = key )] # type: ignore[assignment]
5149 type_ .Str = Annotated [str , FastAPICookie (alias = key )] # type: ignore[assignment]
5250
5351 type_ .key = key
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ class RegisterUserSchema(BaseModel):
2121 "/user" ,
2222 responses = {
2323 status .HTTP_200_OK : {"model" : UserSchema },
24- status .HTTP_204_NO_CONTENT : {"model" : NoDataSchema },
24+ status .HTTP_204_NO_CONTENT : {},
2525 },
2626 summary = "View user" ,
2727 description = "View current user." ,
@@ -34,6 +34,8 @@ async def view_user_route(
3434) -> Response :
3535 view = await view_user (signed_user_id = signed_user_id )
3636
37- response_model = NoDataSchema () if view is None else view
38- response_body = response_model .model_dump (mode = "json" , by_alias = True )
37+ if view is None :
38+ return Response (b"" , status_code = status .HTTP_204_NO_CONTENT )
39+
40+ response_body = view .model_dump (mode = "json" , by_alias = True )
3941 return JSONResponse (response_body )
Original file line number Diff line number Diff line change 1- from app_name_snake_case .infrastructure .typenv .envs import Envs
21from pytest import Item , fixture , mark
32from pytest_asyncio import is_async_test
43
4+ from app_name_snake_case .infrastructure .typenv .envs import Envs
5+
56
67@fixture (scope = "session" )
78def envs () -> Envs :
Original file line number Diff line number Diff line change 11from collections .abc import AsyncIterable
22
3- from app_name_snake_case .infrastructure .sqlalchemy .tables import metadata
4- from app_name_snake_case .infrastructure .typenv .envs import Envs
53from pytest import fixture
64from sqlalchemy import NullPool , delete
75from sqlalchemy .ext .asyncio import (
108 create_async_engine ,
119)
1210
11+ from app_name_snake_case .infrastructure .sqlalchemy .tables import metadata
12+ from app_name_snake_case .infrastructure .typenv .envs import Envs
13+
1314
1415@fixture (scope = "session" )
1516def engine (envs : Envs ) -> AsyncEngine :
You can’t perform that action at this time.
0 commit comments