FastAPI-fastkit 1.0.0__py3-none-any.whl → 1.0.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fastapi_fastkit/__init__.py +10 -1
- fastapi_fastkit/backend/main.py +482 -482
- fastapi_fastkit/backend/transducer.py +106 -106
- fastapi_fastkit/cli.py +664 -631
- fastapi_fastkit/core/settings.py +155 -155
- fastapi_fastkit/fastapi_project_template/README.md +90 -90
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/.env-tpl +1 -1
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/.gitignore-tpl +30 -30
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/README.md-tpl +107 -107
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/requirements.txt-tpl +36 -36
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/scripts/format.sh-tpl +5 -5
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/scripts/lint.sh-tpl +5 -5
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/scripts/run-server.sh-tpl +8 -8
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/scripts/test.sh-tpl +6 -6
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/setup.cfg-tpl +14 -14
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/setup.py-tpl +25 -25
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/src/api/api.py-tpl +9 -9
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/src/api/routes/items.py-tpl +57 -57
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/src/core/config.py-tpl +64 -64
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/src/crud/items.py-tpl +21 -21
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/src/main.py-tpl +26 -26
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/src/mocks/mock_items.json-tpl +8 -8
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/src/schemas/items.py-tpl +22 -22
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/tests/conftest.py-tpl +42 -42
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/tests/test_items.py-tpl +48 -48
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/.env-tpl +1 -1
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/.gitignore-tpl +191 -191
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/README.md-tpl +156 -156
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/requirements.txt-tpl +36 -36
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/scripts/format.sh-tpl +5 -5
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/scripts/lint.sh-tpl +5 -5
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/scripts/run-server.sh-tpl +8 -8
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/scripts/test.sh-tpl +6 -6
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/setup.cfg-tpl +12 -12
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/setup.py-tpl +27 -27
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/.DS_Store +0 -0
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/api/api.py-tpl +9 -9
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/api/routes/items.py-tpl +172 -172
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/core/config.py-tpl +64 -64
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/crud/items.py-tpl +21 -21
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/helper/exceptions.py-tpl +103 -103
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/helper/pagination.py-tpl +72 -72
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/main.py-tpl +39 -39
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/mocks/mock_items.json-tpl +8 -8
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/schemas/base.py-tpl +49 -49
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/schemas/items.py-tpl +22 -22
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/utils/documents.py-tpl +20 -20
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/tests/conftest.py-tpl +42 -42
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/tests/test_items.py-tpl +61 -61
- fastapi_fastkit/fastapi_project_template/fastapi-default/README.md-tpl +101 -101
- fastapi_fastkit/fastapi_project_template/fastapi-default/scripts/run-server.sh-tpl +8 -8
- fastapi_fastkit/fastapi_project_template/fastapi-default/setup.py-tpl +22 -22
- fastapi_fastkit/fastapi_project_template/fastapi-default/src/mocks/mock_items.json-tpl +8 -8
- fastapi_fastkit/fastapi_project_template/fastapi-default/tests/conftest.py-tpl +30 -30
- fastapi_fastkit/fastapi_project_template/fastapi-default/tests/test_items.py-tpl +44 -44
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/.env-tpl +1 -1
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/.gitignore-tpl +30 -30
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/Dockerfile-tpl +23 -23
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/README.md-tpl +119 -119
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/requirements.txt-tpl +36 -36
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/scripts/format.sh-tpl +5 -5
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/scripts/lint.sh-tpl +5 -5
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/scripts/run-server.sh-tpl +8 -8
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/scripts/test.sh-tpl +6 -6
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/setup.cfg-tpl +13 -13
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/setup.py-tpl +22 -22
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/src/api/api.py-tpl +6 -6
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/src/api/routes/items.py-tpl +54 -54
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/src/core/config.py-tpl +64 -64
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/src/crud/items.py-tpl +15 -15
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/src/main.py-tpl +26 -26
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/src/mocks/mock_items.json-tpl +8 -8
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/src/schemas/items.py-tpl +19 -19
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/tests/conftest.py-tpl +30 -30
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/tests/test_items.py-tpl +44 -44
- fastapi_fastkit/fastapi_project_template/fastapi-empty/.env-tpl +1 -1
- fastapi_fastkit/fastapi_project_template/fastapi-empty/setup.py-tpl +22 -22
- fastapi_fastkit/fastapi_project_template/fastapi-empty/src/core/config.py-tpl +75 -75
- fastapi_fastkit/fastapi_project_template/fastapi-empty/src/main.py-tpl +36 -36
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/.env-tpl +9 -9
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/.gitignore-tpl +30 -30
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/Dockerfile-tpl +23 -23
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/README.md-tpl +144 -144
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/alembic.ini-tpl +119 -119
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/docker-compose.yml-tpl +44 -44
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/requirements.txt-tpl +41 -41
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/scripts/format.sh-tpl +5 -5
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/scripts/lint.sh-tpl +5 -5
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/scripts/pre-start.sh-tpl +16 -16
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/scripts/run-server.sh-tpl +8 -8
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/scripts/test.sh-tpl +10 -10
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/setup.cfg-tpl +13 -13
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/setup.py-tpl +25 -25
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/alembic/README-tpl +1 -1
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/alembic/env.py-tpl +85 -85
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/alembic/script.py.mako-tpl +26 -26
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/alembic/versions/bedcdc35b64a_first_alembic.py-tpl +37 -37
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/api/api.py-tpl +11 -11
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/api/deps.py-tpl +19 -19
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/api/routes/items.py-tpl +109 -109
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/core/config.py-tpl +88 -88
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/core/db.py-tpl +53 -53
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/crud/items.py-tpl +102 -102
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/main.py-tpl +45 -45
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/schemas/items.py-tpl +54 -54
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/utils/backend_pre_start.py-tpl +39 -39
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/utils/init_data.py-tpl +23 -23
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/utils/tests_pre_start.py-tpl +39 -39
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/tests/conftest.py-tpl +63 -63
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/tests/test_items.py-tpl +44 -44
- fastapi_fastkit/fastapi_project_template/modules/api/routes/new_route.py-tpl +64 -64
- fastapi_fastkit/fastapi_project_template/modules/crud/new_route.py-tpl +29 -29
- fastapi_fastkit/fastapi_project_template/modules/schemas/new_route.py-tpl +23 -23
- fastapi_fastkit/logs/fastkit_debug_20250702_161423.log +21 -0
- fastapi_fastkit/logs/fastkit_debug_20250702_162706.log +20 -0
- fastapi_fastkit/logs/fastkit_debug_20250702_163010.log +21 -0
- fastapi_fastkit/logs/fastkit_debug_20250702_163526.log +21 -0
- fastapi_fastkit/logs/fastkit_debug_20250702_164053.log +21 -0
- fastapi_fastkit/logs/fastkit_debug_20250702_165220.log +21 -0
- fastapi_fastkit/logs/fastkit_debug_20250702_165647.log +21 -0
- fastapi_fastkit/utils/logging.py +112 -1
- fastapi_fastkit/utils/main.py +140 -129
- fastapi_fastkit-1.0.2.dist-info/METADATA +320 -0
- {fastapi_fastkit-1.0.0.dist-info → fastapi_fastkit-1.0.2.dist-info}/RECORD +127 -119
- {fastapi_fastkit-1.0.0.dist-info → fastapi_fastkit-1.0.2.dist-info}/WHEEL +1 -1
- {fastapi_fastkit-1.0.0.dist-info → fastapi_fastkit-1.0.2.dist-info}/licenses/LICENSE +21 -21
- fastapi_fastkit-1.0.0.dist-info/METADATA +0 -208
- {fastapi_fastkit-1.0.0.dist-info → fastapi_fastkit-1.0.2.dist-info}/entry_points.txt +0 -0
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
# --------------------------------------------------------------------------
|
|
2
|
-
# The module defines custom base response schemas.
|
|
3
|
-
# --------------------------------------------------------------------------
|
|
4
|
-
from typing import Generic, Optional, TypeVar
|
|
5
|
-
|
|
6
|
-
from pydantic import BaseModel, Field
|
|
7
|
-
|
|
8
|
-
T = TypeVar("T")
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class ResponseSchema(BaseModel, Generic[T]):
|
|
12
|
-
timestamp: str = Field(
|
|
13
|
-
...,
|
|
14
|
-
description="The timestamp when the response was generated.",
|
|
15
|
-
)
|
|
16
|
-
status: int = Field(..., description="HTTP status code.")
|
|
17
|
-
code: str = Field(
|
|
18
|
-
...,
|
|
19
|
-
description="Server identification code.",
|
|
20
|
-
)
|
|
21
|
-
path: str = Field(
|
|
22
|
-
...,
|
|
23
|
-
description="Request path.",
|
|
24
|
-
)
|
|
25
|
-
message: T = Field(
|
|
26
|
-
...,
|
|
27
|
-
description="Data details or error messages requested.",
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
class ConfigDict:
|
|
31
|
-
json_schema_extra = {
|
|
32
|
-
"example": {
|
|
33
|
-
"timestamp": "2023-02-10T01:00:00.000Z",
|
|
34
|
-
"status": 200,
|
|
35
|
-
"code": "HTTP-200",
|
|
36
|
-
"path": "/v1/<some/endpoint>",
|
|
37
|
-
"message": {
|
|
38
|
-
"id": "123e4567-e89b-12d3-a456-426614174000",
|
|
39
|
-
"email": "example@example.com",
|
|
40
|
-
"password": "secret",
|
|
41
|
-
"nickname": "example_nick",
|
|
42
|
-
"create_at": "2023-02-10T01:00:00.000Z",
|
|
43
|
-
"bio": "example bio",
|
|
44
|
-
"profile_img": "https://example.com/profile.jpg",
|
|
45
|
-
"first_name": "John",
|
|
46
|
-
"last_name": "Doe",
|
|
47
|
-
},
|
|
48
|
-
}
|
|
49
|
-
}
|
|
1
|
+
# --------------------------------------------------------------------------
|
|
2
|
+
# The module defines custom base response schemas.
|
|
3
|
+
# --------------------------------------------------------------------------
|
|
4
|
+
from typing import Generic, Optional, TypeVar
|
|
5
|
+
|
|
6
|
+
from pydantic import BaseModel, Field
|
|
7
|
+
|
|
8
|
+
T = TypeVar("T")
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class ResponseSchema(BaseModel, Generic[T]):
|
|
12
|
+
timestamp: str = Field(
|
|
13
|
+
...,
|
|
14
|
+
description="The timestamp when the response was generated.",
|
|
15
|
+
)
|
|
16
|
+
status: int = Field(..., description="HTTP status code.")
|
|
17
|
+
code: str = Field(
|
|
18
|
+
...,
|
|
19
|
+
description="Server identification code.",
|
|
20
|
+
)
|
|
21
|
+
path: str = Field(
|
|
22
|
+
...,
|
|
23
|
+
description="Request path.",
|
|
24
|
+
)
|
|
25
|
+
message: T = Field(
|
|
26
|
+
...,
|
|
27
|
+
description="Data details or error messages requested.",
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
class ConfigDict:
|
|
31
|
+
json_schema_extra = {
|
|
32
|
+
"example": {
|
|
33
|
+
"timestamp": "2023-02-10T01:00:00.000Z",
|
|
34
|
+
"status": 200,
|
|
35
|
+
"code": "HTTP-200",
|
|
36
|
+
"path": "/v1/<some/endpoint>",
|
|
37
|
+
"message": {
|
|
38
|
+
"id": "123e4567-e89b-12d3-a456-426614174000",
|
|
39
|
+
"email": "example@example.com",
|
|
40
|
+
"password": "secret",
|
|
41
|
+
"nickname": "example_nick",
|
|
42
|
+
"create_at": "2023-02-10T01:00:00.000Z",
|
|
43
|
+
"bio": "example bio",
|
|
44
|
+
"profile_img": "https://example.com/profile.jpg",
|
|
45
|
+
"first_name": "John",
|
|
46
|
+
"last_name": "Doe",
|
|
47
|
+
},
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
# --------------------------------------------------------------------------
|
|
2
|
-
# Item schema module
|
|
3
|
-
# --------------------------------------------------------------------------
|
|
4
|
-
from typing import Optional
|
|
5
|
-
|
|
6
|
-
from pydantic import BaseModel, ConfigDict
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class ItemBase(BaseModel):
|
|
10
|
-
name: str
|
|
11
|
-
description: Optional[str] = None
|
|
12
|
-
price: float
|
|
13
|
-
category: str
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class ItemCreate(ItemBase):
|
|
17
|
-
pass
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
class ItemResponse(ItemBase):
|
|
21
|
-
id: int
|
|
22
|
-
model_config = ConfigDict(from_attributes=True)
|
|
1
|
+
# --------------------------------------------------------------------------
|
|
2
|
+
# Item schema module
|
|
3
|
+
# --------------------------------------------------------------------------
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
from pydantic import BaseModel, ConfigDict
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class ItemBase(BaseModel):
|
|
10
|
+
name: str
|
|
11
|
+
description: Optional[str] = None
|
|
12
|
+
price: float
|
|
13
|
+
category: str
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class ItemCreate(ItemBase):
|
|
17
|
+
pass
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class ItemResponse(ItemBase):
|
|
21
|
+
id: int
|
|
22
|
+
model_config = ConfigDict(from_attributes=True)
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
# --------------------------------------------------------------------------
|
|
2
|
-
# The module defines API docs content that OpenAPI generator can read.
|
|
3
|
-
# --------------------------------------------------------------------------
|
|
4
|
-
from fastapi import FastAPI
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def add_description_at_api_tags(app: FastAPI):
|
|
8
|
-
tag_descriptions = {
|
|
9
|
-
"items": "Item API. Performs item CRUD operations...",
|
|
10
|
-
# put routers' description here after create and connect them.
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
openapi_tags = [
|
|
14
|
-
{"name": tag, "description": desc} for tag, desc in tag_descriptions.items()
|
|
15
|
-
]
|
|
16
|
-
|
|
17
|
-
if app.openapi_tags:
|
|
18
|
-
app.openapi_tags.extend(openapi_tags)
|
|
19
|
-
else:
|
|
20
|
-
app.openapi_tags = openapi_tags
|
|
1
|
+
# --------------------------------------------------------------------------
|
|
2
|
+
# The module defines API docs content that OpenAPI generator can read.
|
|
3
|
+
# --------------------------------------------------------------------------
|
|
4
|
+
from fastapi import FastAPI
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def add_description_at_api_tags(app: FastAPI):
|
|
8
|
+
tag_descriptions = {
|
|
9
|
+
"items": "Item API. Performs item CRUD operations...",
|
|
10
|
+
# put routers' description here after create and connect them.
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
openapi_tags = [
|
|
14
|
+
{"name": tag, "description": desc} for tag, desc in tag_descriptions.items()
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
if app.openapi_tags:
|
|
18
|
+
app.openapi_tags.extend(openapi_tags)
|
|
19
|
+
else:
|
|
20
|
+
app.openapi_tags = openapi_tags
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
# --------------------------------------------------------------------------
|
|
2
|
-
# pytest runtime configuration module
|
|
3
|
-
# --------------------------------------------------------------------------
|
|
4
|
-
import asyncio
|
|
5
|
-
import os
|
|
6
|
-
import typing
|
|
7
|
-
from pathlib import Path
|
|
8
|
-
|
|
9
|
-
import pytest
|
|
10
|
-
import pytest_asyncio
|
|
11
|
-
from httpx import ASGITransport, AsyncClient
|
|
12
|
-
|
|
13
|
-
from src.main import app
|
|
14
|
-
|
|
15
|
-
MOCK_PATH = os.path.join(os.path.dirname(__file__), "../src/mocks/mock_items.json")
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
@pytest.fixture(scope="session")
|
|
19
|
-
def event_loop(request) -> typing.Generator:
|
|
20
|
-
loop = asyncio.get_event_loop()
|
|
21
|
-
yield loop
|
|
22
|
-
loop.close()
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
@pytest_asyncio.fixture(scope="module", autouse=True)
|
|
26
|
-
def mock_data_reset():
|
|
27
|
-
# Back up original data into memory
|
|
28
|
-
mock_path = Path(__file__).parent.parent / "src/mocks/mock_items.json"
|
|
29
|
-
original_data = mock_path.read_text()
|
|
30
|
-
|
|
31
|
-
yield
|
|
32
|
-
|
|
33
|
-
# After test, restore original data
|
|
34
|
-
mock_path.write_text(original_data)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
@pytest_asyncio.fixture(scope="module")
|
|
38
|
-
async def client():
|
|
39
|
-
async with AsyncClient(
|
|
40
|
-
transport=ASGITransport(app=app), base_url="http://test"
|
|
41
|
-
) as ac:
|
|
42
|
-
yield ac
|
|
1
|
+
# --------------------------------------------------------------------------
|
|
2
|
+
# pytest runtime configuration module
|
|
3
|
+
# --------------------------------------------------------------------------
|
|
4
|
+
import asyncio
|
|
5
|
+
import os
|
|
6
|
+
import typing
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
import pytest
|
|
10
|
+
import pytest_asyncio
|
|
11
|
+
from httpx import ASGITransport, AsyncClient
|
|
12
|
+
|
|
13
|
+
from src.main import app
|
|
14
|
+
|
|
15
|
+
MOCK_PATH = os.path.join(os.path.dirname(__file__), "../src/mocks/mock_items.json")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@pytest.fixture(scope="session")
|
|
19
|
+
def event_loop(request) -> typing.Generator:
|
|
20
|
+
loop = asyncio.get_event_loop()
|
|
21
|
+
yield loop
|
|
22
|
+
loop.close()
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@pytest_asyncio.fixture(scope="module", autouse=True)
|
|
26
|
+
def mock_data_reset():
|
|
27
|
+
# Back up original data into memory
|
|
28
|
+
mock_path = Path(__file__).parent.parent / "src/mocks/mock_items.json"
|
|
29
|
+
original_data = mock_path.read_text()
|
|
30
|
+
|
|
31
|
+
yield
|
|
32
|
+
|
|
33
|
+
# After test, restore original data
|
|
34
|
+
mock_path.write_text(original_data)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@pytest_asyncio.fixture(scope="module")
|
|
38
|
+
async def client():
|
|
39
|
+
async with AsyncClient(
|
|
40
|
+
transport=ASGITransport(app=app), base_url="http://test"
|
|
41
|
+
) as ac:
|
|
42
|
+
yield ac
|
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
# --------------------------------------------------------------------------
|
|
2
|
-
# Item endpoint testcases
|
|
3
|
-
# --------------------------------------------------------------------------
|
|
4
|
-
import pytest
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
@pytest.mark.asyncio
|
|
8
|
-
async def test_read_all_items(client):
|
|
9
|
-
response = await client.get("/items/")
|
|
10
|
-
assert response.status_code == 200
|
|
11
|
-
data = response.json()
|
|
12
|
-
assert data["status"] == 200
|
|
13
|
-
assert data["code"] == "HTTP-200"
|
|
14
|
-
assert isinstance(data["message"], list)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
@pytest.mark.asyncio
|
|
18
|
-
async def test_get_item_success(client):
|
|
19
|
-
response = await client.get("/items/1")
|
|
20
|
-
assert response.status_code == 200
|
|
21
|
-
data = response.json()
|
|
22
|
-
assert data["message"]["id"] == 1
|
|
23
|
-
assert data["message"]["name"] == "Test Item 1"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
@pytest.mark.asyncio
|
|
27
|
-
async def test_get_item_not_found(client):
|
|
28
|
-
response = await client.get("/items/999")
|
|
29
|
-
assert response.status_code == 404
|
|
30
|
-
data = response.json()
|
|
31
|
-
assert data["code"] == "HTTP-002"
|
|
32
|
-
assert "Item not found" in data["message"]
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
@pytest.mark.asyncio
|
|
36
|
-
async def test_create_item(client):
|
|
37
|
-
test_item = {"name": "New Item", "price": 30.0, "category": "test"}
|
|
38
|
-
response = await client.post("/items/", json=test_item)
|
|
39
|
-
assert response.status_code == 201
|
|
40
|
-
data = response.json()
|
|
41
|
-
assert data["message"]["id"] == 2
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
@pytest.mark.asyncio
|
|
45
|
-
async def test_update_item(client):
|
|
46
|
-
update_data = {"name": "Updated Item", "price": 25.0, "category": "test"}
|
|
47
|
-
response = await client.put("/items/1", json=update_data)
|
|
48
|
-
assert response.status_code == 200
|
|
49
|
-
data = response.json()
|
|
50
|
-
assert data["message"]["name"] == "Updated Item"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
@pytest.mark.asyncio
|
|
54
|
-
async def test_delete_item(client):
|
|
55
|
-
# First delete
|
|
56
|
-
response = await client.delete("/items/1")
|
|
57
|
-
assert response.status_code == 200
|
|
58
|
-
|
|
59
|
-
# Verify deletion
|
|
60
|
-
verify_response = await client.get("/items/1")
|
|
61
|
-
assert verify_response.status_code == 404
|
|
1
|
+
# --------------------------------------------------------------------------
|
|
2
|
+
# Item endpoint testcases
|
|
3
|
+
# --------------------------------------------------------------------------
|
|
4
|
+
import pytest
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@pytest.mark.asyncio
|
|
8
|
+
async def test_read_all_items(client):
|
|
9
|
+
response = await client.get("/items/")
|
|
10
|
+
assert response.status_code == 200
|
|
11
|
+
data = response.json()
|
|
12
|
+
assert data["status"] == 200
|
|
13
|
+
assert data["code"] == "HTTP-200"
|
|
14
|
+
assert isinstance(data["message"], list)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@pytest.mark.asyncio
|
|
18
|
+
async def test_get_item_success(client):
|
|
19
|
+
response = await client.get("/items/1")
|
|
20
|
+
assert response.status_code == 200
|
|
21
|
+
data = response.json()
|
|
22
|
+
assert data["message"]["id"] == 1
|
|
23
|
+
assert data["message"]["name"] == "Test Item 1"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@pytest.mark.asyncio
|
|
27
|
+
async def test_get_item_not_found(client):
|
|
28
|
+
response = await client.get("/items/999")
|
|
29
|
+
assert response.status_code == 404
|
|
30
|
+
data = response.json()
|
|
31
|
+
assert data["code"] == "HTTP-002"
|
|
32
|
+
assert "Item not found" in data["message"]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@pytest.mark.asyncio
|
|
36
|
+
async def test_create_item(client):
|
|
37
|
+
test_item = {"name": "New Item", "price": 30.0, "category": "test"}
|
|
38
|
+
response = await client.post("/items/", json=test_item)
|
|
39
|
+
assert response.status_code == 201
|
|
40
|
+
data = response.json()
|
|
41
|
+
assert data["message"]["id"] == 2
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@pytest.mark.asyncio
|
|
45
|
+
async def test_update_item(client):
|
|
46
|
+
update_data = {"name": "Updated Item", "price": 25.0, "category": "test"}
|
|
47
|
+
response = await client.put("/items/1", json=update_data)
|
|
48
|
+
assert response.status_code == 200
|
|
49
|
+
data = response.json()
|
|
50
|
+
assert data["message"]["name"] == "Updated Item"
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@pytest.mark.asyncio
|
|
54
|
+
async def test_delete_item(client):
|
|
55
|
+
# First delete
|
|
56
|
+
response = await client.delete("/items/1")
|
|
57
|
+
assert response.status_code == 200
|
|
58
|
+
|
|
59
|
+
# Verify deletion
|
|
60
|
+
verify_response = await client.get("/items/1")
|
|
61
|
+
assert verify_response.status_code == 404
|
|
@@ -1,101 +1,101 @@
|
|
|
1
|
-
# Simple FastAPI Project
|
|
2
|
-
|
|
3
|
-
Simple CRUD API application using FastAPI
|
|
4
|
-
|
|
5
|
-
## Tech Stack
|
|
6
|
-
|
|
7
|
-
- Python 3.12+
|
|
8
|
-
- FastAPI + uvicorn
|
|
9
|
-
- pydantic 2 & pydantic-settings
|
|
10
|
-
- pytest
|
|
11
|
-
- mypy + black + isort
|
|
12
|
-
|
|
13
|
-
## Project Structure
|
|
14
|
-
|
|
15
|
-
```
|
|
16
|
-
.
|
|
17
|
-
├── README.md
|
|
18
|
-
├── requirements.txt
|
|
19
|
-
├── setup.py
|
|
20
|
-
├── scripts
|
|
21
|
-
│ └── run-server.sh
|
|
22
|
-
├── src
|
|
23
|
-
│ ├── main.py
|
|
24
|
-
│ ├── schemas
|
|
25
|
-
│ │ └── items.py
|
|
26
|
-
│ ├── mocks
|
|
27
|
-
│ │ └── mock_items.json
|
|
28
|
-
│ ├── crud
|
|
29
|
-
│ │ └── items.py
|
|
30
|
-
│ ├── core
|
|
31
|
-
│ │ └── config.py
|
|
32
|
-
│ └── api
|
|
33
|
-
│ ├── api.py
|
|
34
|
-
│ └── routes
|
|
35
|
-
│ └── items.py
|
|
36
|
-
└── tests
|
|
37
|
-
├── __init__.py
|
|
38
|
-
├── test_items.py
|
|
39
|
-
└── conftest.py
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
## How to run
|
|
43
|
-
|
|
44
|
-
At venv, run command below:
|
|
45
|
-
|
|
46
|
-
```bash
|
|
47
|
-
# Start development server (using script)
|
|
48
|
-
$ bash scripts/run-server.sh
|
|
49
|
-
|
|
50
|
-
# Manual run
|
|
51
|
-
$ uvicorn src.main:app --reload
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
After running server instance, you can check API documentation below:
|
|
55
|
-
|
|
56
|
-
```bash
|
|
57
|
-
<domain:port>/docs # Swagger format
|
|
58
|
-
<domain:port>/redoc # ReDoc format
|
|
59
|
-
|
|
60
|
-
# example
|
|
61
|
-
http://127.0.0.1:8000/docs
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
## API Endpoints
|
|
65
|
-
|
|
66
|
-
| Method | Endpoint | Description |
|
|
67
|
-
|--------|------------------|----------------------------|
|
|
68
|
-
| GET | `/items/` | List all items |
|
|
69
|
-
| GET | `/items/{id}` | Get single item |
|
|
70
|
-
| POST | `/items/` | Create new item |
|
|
71
|
-
| PUT | `/items/{id}` | Update existing item |
|
|
72
|
-
| DELETE | `/items/{id}` | Delete item |
|
|
73
|
-
|
|
74
|
-
## Key Features
|
|
75
|
-
|
|
76
|
-
- Initial data loading with mock data
|
|
77
|
-
- Pydantic model-based data validation
|
|
78
|
-
- Demo CRUD operations implementation (Item CRUD)
|
|
79
|
-
- Integrated test cases
|
|
80
|
-
|
|
81
|
-
## Running Tests
|
|
82
|
-
|
|
83
|
-
```bash
|
|
84
|
-
# Run all tests
|
|
85
|
-
pytest tests/
|
|
86
|
-
|
|
87
|
-
# Run specific test file
|
|
88
|
-
pytest tests/test_items.py -v
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
For other FastAPI guides, please refer <https://fastapi.tiangolo.com/tutorial/>
|
|
92
|
-
|
|
93
|
-
# Project Origin
|
|
94
|
-
|
|
95
|
-
This project was created based on the template from the [FastAPI-fastkit](https://github.com/bnbong/FastAPI-fastkit) project.
|
|
96
|
-
|
|
97
|
-
The `FastAPI-fastkit` is an open-source project that helps Python and FastAPI beginners quickly set up a FastAPI-based application development environment in a framework-like structure.
|
|
98
|
-
|
|
99
|
-
### Template Information
|
|
100
|
-
- Template creator: [bnbong](mailto:bbbong9@gmail.com)
|
|
101
|
-
- FastAPI-fastkit project maintainer: [bnbong](mailto:bbbong9@gmail.com)
|
|
1
|
+
# Simple FastAPI Project
|
|
2
|
+
|
|
3
|
+
Simple CRUD API application using FastAPI
|
|
4
|
+
|
|
5
|
+
## Tech Stack
|
|
6
|
+
|
|
7
|
+
- Python 3.12+
|
|
8
|
+
- FastAPI + uvicorn
|
|
9
|
+
- pydantic 2 & pydantic-settings
|
|
10
|
+
- pytest
|
|
11
|
+
- mypy + black + isort
|
|
12
|
+
|
|
13
|
+
## Project Structure
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
.
|
|
17
|
+
├── README.md
|
|
18
|
+
├── requirements.txt
|
|
19
|
+
├── setup.py
|
|
20
|
+
├── scripts
|
|
21
|
+
│ └── run-server.sh
|
|
22
|
+
├── src
|
|
23
|
+
│ ├── main.py
|
|
24
|
+
│ ├── schemas
|
|
25
|
+
│ │ └── items.py
|
|
26
|
+
│ ├── mocks
|
|
27
|
+
│ │ └── mock_items.json
|
|
28
|
+
│ ├── crud
|
|
29
|
+
│ │ └── items.py
|
|
30
|
+
│ ├── core
|
|
31
|
+
│ │ └── config.py
|
|
32
|
+
│ └── api
|
|
33
|
+
│ ├── api.py
|
|
34
|
+
│ └── routes
|
|
35
|
+
│ └── items.py
|
|
36
|
+
└── tests
|
|
37
|
+
├── __init__.py
|
|
38
|
+
├── test_items.py
|
|
39
|
+
└── conftest.py
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## How to run
|
|
43
|
+
|
|
44
|
+
At venv, run command below:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# Start development server (using script)
|
|
48
|
+
$ bash scripts/run-server.sh
|
|
49
|
+
|
|
50
|
+
# Manual run
|
|
51
|
+
$ uvicorn src.main:app --reload
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
After running server instance, you can check API documentation below:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
<domain:port>/docs # Swagger format
|
|
58
|
+
<domain:port>/redoc # ReDoc format
|
|
59
|
+
|
|
60
|
+
# example
|
|
61
|
+
http://127.0.0.1:8000/docs
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## API Endpoints
|
|
65
|
+
|
|
66
|
+
| Method | Endpoint | Description |
|
|
67
|
+
|--------|------------------|----------------------------|
|
|
68
|
+
| GET | `/items/` | List all items |
|
|
69
|
+
| GET | `/items/{id}` | Get single item |
|
|
70
|
+
| POST | `/items/` | Create new item |
|
|
71
|
+
| PUT | `/items/{id}` | Update existing item |
|
|
72
|
+
| DELETE | `/items/{id}` | Delete item |
|
|
73
|
+
|
|
74
|
+
## Key Features
|
|
75
|
+
|
|
76
|
+
- Initial data loading with mock data
|
|
77
|
+
- Pydantic model-based data validation
|
|
78
|
+
- Demo CRUD operations implementation (Item CRUD)
|
|
79
|
+
- Integrated test cases
|
|
80
|
+
|
|
81
|
+
## Running Tests
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
# Run all tests
|
|
85
|
+
pytest tests/
|
|
86
|
+
|
|
87
|
+
# Run specific test file
|
|
88
|
+
pytest tests/test_items.py -v
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
For other FastAPI guides, please refer <https://fastapi.tiangolo.com/tutorial/>
|
|
92
|
+
|
|
93
|
+
# Project Origin
|
|
94
|
+
|
|
95
|
+
This project was created based on the template from the [FastAPI-fastkit](https://github.com/bnbong/FastAPI-fastkit) project.
|
|
96
|
+
|
|
97
|
+
The `FastAPI-fastkit` is an open-source project that helps Python and FastAPI beginners quickly set up a FastAPI-based application development environment in a framework-like structure.
|
|
98
|
+
|
|
99
|
+
### Template Information
|
|
100
|
+
- Template creator: [bnbong](mailto:bbbong9@gmail.com)
|
|
101
|
+
- FastAPI-fastkit project maintainer: [bnbong](mailto:bbbong9@gmail.com)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
|
|
3
|
-
set -e
|
|
4
|
-
set -x
|
|
5
|
-
|
|
6
|
-
source .venv/bin/activate
|
|
7
|
-
|
|
8
|
-
uvicorn src.main:app --reload
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
set -e
|
|
4
|
+
set -x
|
|
5
|
+
|
|
6
|
+
source .venv/bin/activate
|
|
7
|
+
|
|
8
|
+
uvicorn src.main:app --reload
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
# --------------------------------------------------------------------------
|
|
2
|
-
# package setup module
|
|
3
|
-
# --------------------------------------------------------------------------
|
|
4
|
-
from setuptools import find_packages, setup
|
|
5
|
-
|
|
6
|
-
install_requires: list[str] = [
|
|
7
|
-
"fastapi",
|
|
8
|
-
"uvicorn",
|
|
9
|
-
"pydantic",
|
|
10
|
-
"pydantic-settings",
|
|
11
|
-
"python-dotenv",
|
|
12
|
-
]
|
|
13
|
-
|
|
14
|
-
setup(
|
|
15
|
-
name="<project_name>",
|
|
16
|
-
description="[FastAPI-fastkit templated] <description>",
|
|
17
|
-
author="<author>",
|
|
18
|
-
author_email=f"<author_email>",
|
|
19
|
-
packages=find_packages(where="src"),
|
|
20
|
-
requires=["python (>=3.12)"],
|
|
21
|
-
install_requires=install_requires,
|
|
22
|
-
)
|
|
1
|
+
# --------------------------------------------------------------------------
|
|
2
|
+
# package setup module
|
|
3
|
+
# --------------------------------------------------------------------------
|
|
4
|
+
from setuptools import find_packages, setup
|
|
5
|
+
|
|
6
|
+
install_requires: list[str] = [
|
|
7
|
+
"fastapi",
|
|
8
|
+
"uvicorn",
|
|
9
|
+
"pydantic",
|
|
10
|
+
"pydantic-settings",
|
|
11
|
+
"python-dotenv",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
setup(
|
|
15
|
+
name="<project_name>",
|
|
16
|
+
description="[FastAPI-fastkit templated] <description>",
|
|
17
|
+
author="<author>",
|
|
18
|
+
author_email=f"<author_email>",
|
|
19
|
+
packages=find_packages(where="src"),
|
|
20
|
+
requires=["python (>=3.12)"],
|
|
21
|
+
install_requires=install_requires,
|
|
22
|
+
)
|