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.
Files changed (128) hide show
  1. fastapi_fastkit/__init__.py +10 -1
  2. fastapi_fastkit/backend/main.py +482 -482
  3. fastapi_fastkit/backend/transducer.py +106 -106
  4. fastapi_fastkit/cli.py +664 -631
  5. fastapi_fastkit/core/settings.py +155 -155
  6. fastapi_fastkit/fastapi_project_template/README.md +90 -90
  7. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/.env-tpl +1 -1
  8. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/.gitignore-tpl +30 -30
  9. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/README.md-tpl +107 -107
  10. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/requirements.txt-tpl +36 -36
  11. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/scripts/format.sh-tpl +5 -5
  12. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/scripts/lint.sh-tpl +5 -5
  13. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/scripts/run-server.sh-tpl +8 -8
  14. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/scripts/test.sh-tpl +6 -6
  15. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/setup.cfg-tpl +14 -14
  16. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/setup.py-tpl +25 -25
  17. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/src/api/api.py-tpl +9 -9
  18. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/src/api/routes/items.py-tpl +57 -57
  19. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/src/core/config.py-tpl +64 -64
  20. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/src/crud/items.py-tpl +21 -21
  21. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/src/main.py-tpl +26 -26
  22. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/src/mocks/mock_items.json-tpl +8 -8
  23. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/src/schemas/items.py-tpl +22 -22
  24. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/tests/conftest.py-tpl +42 -42
  25. fastapi_fastkit/fastapi_project_template/fastapi-async-crud/tests/test_items.py-tpl +48 -48
  26. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/.env-tpl +1 -1
  27. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/.gitignore-tpl +191 -191
  28. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/README.md-tpl +156 -156
  29. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/requirements.txt-tpl +36 -36
  30. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/scripts/format.sh-tpl +5 -5
  31. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/scripts/lint.sh-tpl +5 -5
  32. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/scripts/run-server.sh-tpl +8 -8
  33. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/scripts/test.sh-tpl +6 -6
  34. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/setup.cfg-tpl +12 -12
  35. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/setup.py-tpl +27 -27
  36. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/.DS_Store +0 -0
  37. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/api/api.py-tpl +9 -9
  38. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/api/routes/items.py-tpl +172 -172
  39. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/core/config.py-tpl +64 -64
  40. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/crud/items.py-tpl +21 -21
  41. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/helper/exceptions.py-tpl +103 -103
  42. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/helper/pagination.py-tpl +72 -72
  43. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/main.py-tpl +39 -39
  44. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/mocks/mock_items.json-tpl +8 -8
  45. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/schemas/base.py-tpl +49 -49
  46. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/schemas/items.py-tpl +22 -22
  47. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/utils/documents.py-tpl +20 -20
  48. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/tests/conftest.py-tpl +42 -42
  49. fastapi_fastkit/fastapi_project_template/fastapi-custom-response/tests/test_items.py-tpl +61 -61
  50. fastapi_fastkit/fastapi_project_template/fastapi-default/README.md-tpl +101 -101
  51. fastapi_fastkit/fastapi_project_template/fastapi-default/scripts/run-server.sh-tpl +8 -8
  52. fastapi_fastkit/fastapi_project_template/fastapi-default/setup.py-tpl +22 -22
  53. fastapi_fastkit/fastapi_project_template/fastapi-default/src/mocks/mock_items.json-tpl +8 -8
  54. fastapi_fastkit/fastapi_project_template/fastapi-default/tests/conftest.py-tpl +30 -30
  55. fastapi_fastkit/fastapi_project_template/fastapi-default/tests/test_items.py-tpl +44 -44
  56. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/.env-tpl +1 -1
  57. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/.gitignore-tpl +30 -30
  58. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/Dockerfile-tpl +23 -23
  59. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/README.md-tpl +119 -119
  60. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/requirements.txt-tpl +36 -36
  61. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/scripts/format.sh-tpl +5 -5
  62. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/scripts/lint.sh-tpl +5 -5
  63. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/scripts/run-server.sh-tpl +8 -8
  64. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/scripts/test.sh-tpl +6 -6
  65. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/setup.cfg-tpl +13 -13
  66. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/setup.py-tpl +22 -22
  67. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/src/api/api.py-tpl +6 -6
  68. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/src/api/routes/items.py-tpl +54 -54
  69. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/src/core/config.py-tpl +64 -64
  70. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/src/crud/items.py-tpl +15 -15
  71. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/src/main.py-tpl +26 -26
  72. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/src/mocks/mock_items.json-tpl +8 -8
  73. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/src/schemas/items.py-tpl +19 -19
  74. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/tests/conftest.py-tpl +30 -30
  75. fastapi_fastkit/fastapi_project_template/fastapi-dockerized/tests/test_items.py-tpl +44 -44
  76. fastapi_fastkit/fastapi_project_template/fastapi-empty/.env-tpl +1 -1
  77. fastapi_fastkit/fastapi_project_template/fastapi-empty/setup.py-tpl +22 -22
  78. fastapi_fastkit/fastapi_project_template/fastapi-empty/src/core/config.py-tpl +75 -75
  79. fastapi_fastkit/fastapi_project_template/fastapi-empty/src/main.py-tpl +36 -36
  80. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/.env-tpl +9 -9
  81. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/.gitignore-tpl +30 -30
  82. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/Dockerfile-tpl +23 -23
  83. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/README.md-tpl +144 -144
  84. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/alembic.ini-tpl +119 -119
  85. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/docker-compose.yml-tpl +44 -44
  86. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/requirements.txt-tpl +41 -41
  87. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/scripts/format.sh-tpl +5 -5
  88. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/scripts/lint.sh-tpl +5 -5
  89. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/scripts/pre-start.sh-tpl +16 -16
  90. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/scripts/run-server.sh-tpl +8 -8
  91. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/scripts/test.sh-tpl +10 -10
  92. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/setup.cfg-tpl +13 -13
  93. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/setup.py-tpl +25 -25
  94. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/alembic/README-tpl +1 -1
  95. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/alembic/env.py-tpl +85 -85
  96. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/alembic/script.py.mako-tpl +26 -26
  97. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/alembic/versions/bedcdc35b64a_first_alembic.py-tpl +37 -37
  98. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/api/api.py-tpl +11 -11
  99. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/api/deps.py-tpl +19 -19
  100. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/api/routes/items.py-tpl +109 -109
  101. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/core/config.py-tpl +88 -88
  102. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/core/db.py-tpl +53 -53
  103. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/crud/items.py-tpl +102 -102
  104. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/main.py-tpl +45 -45
  105. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/schemas/items.py-tpl +54 -54
  106. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/utils/backend_pre_start.py-tpl +39 -39
  107. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/utils/init_data.py-tpl +23 -23
  108. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/utils/tests_pre_start.py-tpl +39 -39
  109. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/tests/conftest.py-tpl +63 -63
  110. fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/tests/test_items.py-tpl +44 -44
  111. fastapi_fastkit/fastapi_project_template/modules/api/routes/new_route.py-tpl +64 -64
  112. fastapi_fastkit/fastapi_project_template/modules/crud/new_route.py-tpl +29 -29
  113. fastapi_fastkit/fastapi_project_template/modules/schemas/new_route.py-tpl +23 -23
  114. fastapi_fastkit/logs/fastkit_debug_20250702_161423.log +21 -0
  115. fastapi_fastkit/logs/fastkit_debug_20250702_162706.log +20 -0
  116. fastapi_fastkit/logs/fastkit_debug_20250702_163010.log +21 -0
  117. fastapi_fastkit/logs/fastkit_debug_20250702_163526.log +21 -0
  118. fastapi_fastkit/logs/fastkit_debug_20250702_164053.log +21 -0
  119. fastapi_fastkit/logs/fastkit_debug_20250702_165220.log +21 -0
  120. fastapi_fastkit/logs/fastkit_debug_20250702_165647.log +21 -0
  121. fastapi_fastkit/utils/logging.py +112 -1
  122. fastapi_fastkit/utils/main.py +140 -129
  123. fastapi_fastkit-1.0.2.dist-info/METADATA +320 -0
  124. {fastapi_fastkit-1.0.0.dist-info → fastapi_fastkit-1.0.2.dist-info}/RECORD +127 -119
  125. {fastapi_fastkit-1.0.0.dist-info → fastapi_fastkit-1.0.2.dist-info}/WHEEL +1 -1
  126. {fastapi_fastkit-1.0.0.dist-info → fastapi_fastkit-1.0.2.dist-info}/licenses/LICENSE +21 -21
  127. fastapi_fastkit-1.0.0.dist-info/METADATA +0 -208
  128. {fastapi_fastkit-1.0.0.dist-info → fastapi_fastkit-1.0.2.dist-info}/entry_points.txt +0 -0
@@ -1,54 +1,54 @@
1
- # --------------------------------------------------------------------------
2
- # Item schema module
3
- # --------------------------------------------------------------------------
4
- from typing import Optional
5
-
6
- from sqlmodel import Field, SQLModel
7
-
8
-
9
- class ItemBase(SQLModel, table=True):
10
- """
11
- Base Item model that serves both as a SQLModel table definition and a Pydantic model.
12
-
13
- Attributes:
14
- name: The name of the item
15
- description: Optional description of the item
16
- price: The price of the item
17
- category: The category the item belongs to
18
-
19
- Notes:
20
- This model can be extended with additional fields as needed for your specific
21
- application requirements.
22
- """
23
- __tablename__ = "items"
24
-
25
- id: Optional[int] = Field(default=None, primary_key=True)
26
- name: str
27
- description: Optional[str] = None
28
- price: float
29
- category: str
30
-
31
-
32
- class ItemCreate(SQLModel):
33
- """
34
- Item creation model for API requests.
35
-
36
- Use this model to validate incoming data when creating new items.
37
- """
38
- name: str
39
- description: Optional[str] = None
40
- price: float
41
- category: str
42
-
43
-
44
- class ItemResponse(SQLModel):
45
- """
46
- Item response model for API responses.
47
-
48
- This model defines the structure of data returned to clients.
49
- """
50
- id: int
51
- name: str
52
- description: Optional[str] = None
53
- price: float
54
- category: str
1
+ # --------------------------------------------------------------------------
2
+ # Item schema module
3
+ # --------------------------------------------------------------------------
4
+ from typing import Optional
5
+
6
+ from sqlmodel import Field, SQLModel
7
+
8
+
9
+ class ItemBase(SQLModel, table=True):
10
+ """
11
+ Base Item model that serves both as a SQLModel table definition and a Pydantic model.
12
+
13
+ Attributes:
14
+ name: The name of the item
15
+ description: Optional description of the item
16
+ price: The price of the item
17
+ category: The category the item belongs to
18
+
19
+ Notes:
20
+ This model can be extended with additional fields as needed for your specific
21
+ application requirements.
22
+ """
23
+ __tablename__ = "items"
24
+
25
+ id: Optional[int] = Field(default=None, primary_key=True)
26
+ name: str
27
+ description: Optional[str] = None
28
+ price: float
29
+ category: str
30
+
31
+
32
+ class ItemCreate(SQLModel):
33
+ """
34
+ Item creation model for API requests.
35
+
36
+ Use this model to validate incoming data when creating new items.
37
+ """
38
+ name: str
39
+ description: Optional[str] = None
40
+ price: float
41
+ category: str
42
+
43
+
44
+ class ItemResponse(SQLModel):
45
+ """
46
+ Item response model for API responses.
47
+
48
+ This model defines the structure of data returned to clients.
49
+ """
50
+ id: int
51
+ name: str
52
+ description: Optional[str] = None
53
+ price: float
54
+ category: str
@@ -1,39 +1,39 @@
1
- import logging
2
-
3
- from sqlalchemy import Engine
4
- from sqlmodel import Session, select
5
- from tenacity import after_log, before_log, retry, stop_after_attempt, wait_fixed
6
-
7
- from src.core.db import engine
8
-
9
- logging.basicConfig(level=logging.INFO)
10
- logger = logging.getLogger(__name__)
11
-
12
- max_tries = 60 * 5 # 5 minutes
13
- wait_seconds = 1
14
-
15
-
16
- @retry(
17
- stop=stop_after_attempt(max_tries),
18
- wait=wait_fixed(wait_seconds),
19
- before=before_log(logger, logging.INFO),
20
- after=after_log(logger, logging.WARN),
21
- )
22
- def init(db_engine: Engine) -> None:
23
- try:
24
- with Session(db_engine) as session:
25
- # Try to create session to check if DB is awake
26
- session.exec(select(1))
27
- except Exception as e:
28
- logger.error(e)
29
- raise e
30
-
31
-
32
- def main() -> None:
33
- logger.info("Initializing service")
34
- init(engine)
35
- logger.info("Service finished initializing")
36
-
37
-
38
- if __name__ == "__main__":
39
- main()
1
+ import logging
2
+
3
+ from sqlalchemy import Engine
4
+ from sqlmodel import Session, select
5
+ from tenacity import after_log, before_log, retry, stop_after_attempt, wait_fixed
6
+
7
+ from src.core.db import engine
8
+
9
+ logging.basicConfig(level=logging.INFO)
10
+ logger = logging.getLogger(__name__)
11
+
12
+ max_tries = 60 * 5 # 5 minutes
13
+ wait_seconds = 1
14
+
15
+
16
+ @retry(
17
+ stop=stop_after_attempt(max_tries),
18
+ wait=wait_fixed(wait_seconds),
19
+ before=before_log(logger, logging.INFO),
20
+ after=after_log(logger, logging.WARN),
21
+ )
22
+ def init(db_engine: Engine) -> None:
23
+ try:
24
+ with Session(db_engine) as session:
25
+ # Try to create session to check if DB is awake
26
+ session.exec(select(1))
27
+ except Exception as e:
28
+ logger.error(e)
29
+ raise e
30
+
31
+
32
+ def main() -> None:
33
+ logger.info("Initializing service")
34
+ init(engine)
35
+ logger.info("Service finished initializing")
36
+
37
+
38
+ if __name__ == "__main__":
39
+ main()
@@ -1,23 +1,23 @@
1
- import logging
2
-
3
- from sqlmodel import Session
4
-
5
- from src.core.db import engine, init_db
6
-
7
- logging.basicConfig(level=logging.INFO)
8
- logger = logging.getLogger(__name__)
9
-
10
-
11
- def init() -> None:
12
- with Session(engine) as session:
13
- init_db(session)
14
-
15
-
16
- def main() -> None:
17
- logger.info("Creating initial data")
18
- init()
19
- logger.info("Initial data created")
20
-
21
-
22
- if __name__ == "__main__":
23
- main()
1
+ import logging
2
+
3
+ from sqlmodel import Session
4
+
5
+ from src.core.db import engine, init_db
6
+
7
+ logging.basicConfig(level=logging.INFO)
8
+ logger = logging.getLogger(__name__)
9
+
10
+
11
+ def init() -> None:
12
+ with Session(engine) as session:
13
+ init_db(session)
14
+
15
+
16
+ def main() -> None:
17
+ logger.info("Creating initial data")
18
+ init()
19
+ logger.info("Initial data created")
20
+
21
+
22
+ if __name__ == "__main__":
23
+ main()
@@ -1,39 +1,39 @@
1
- import logging
2
-
3
- from sqlalchemy import Engine
4
- from sqlmodel import Session, select
5
- from tenacity import after_log, before_log, retry, stop_after_attempt, wait_fixed
6
-
7
- from src.core.db import engine
8
-
9
- logging.basicConfig(level=logging.INFO)
10
- logger = logging.getLogger(__name__)
11
-
12
- max_tries = 60 * 5 # 5 minutes
13
- wait_seconds = 1
14
-
15
-
16
- @retry(
17
- stop=stop_after_attempt(max_tries),
18
- wait=wait_fixed(wait_seconds),
19
- before=before_log(logger, logging.INFO),
20
- after=after_log(logger, logging.WARN),
21
- )
22
- def init(db_engine: Engine) -> None:
23
- try:
24
- # Try to create session to check if DB is awake
25
- with Session(db_engine) as session:
26
- session.exec(select(1))
27
- except Exception as e:
28
- logger.error(e)
29
- raise e
30
-
31
-
32
- def main() -> None:
33
- logger.info("Initializing service")
34
- init(engine)
35
- logger.info("Service finished initializing")
36
-
37
-
38
- if __name__ == "__main__":
39
- main()
1
+ import logging
2
+
3
+ from sqlalchemy import Engine
4
+ from sqlmodel import Session, select
5
+ from tenacity import after_log, before_log, retry, stop_after_attempt, wait_fixed
6
+
7
+ from src.core.db import engine
8
+
9
+ logging.basicConfig(level=logging.INFO)
10
+ logger = logging.getLogger(__name__)
11
+
12
+ max_tries = 60 * 5 # 5 minutes
13
+ wait_seconds = 1
14
+
15
+
16
+ @retry(
17
+ stop=stop_after_attempt(max_tries),
18
+ wait=wait_fixed(wait_seconds),
19
+ before=before_log(logger, logging.INFO),
20
+ after=after_log(logger, logging.WARN),
21
+ )
22
+ def init(db_engine: Engine) -> None:
23
+ try:
24
+ # Try to create session to check if DB is awake
25
+ with Session(db_engine) as session:
26
+ session.exec(select(1))
27
+ except Exception as e:
28
+ logger.error(e)
29
+ raise e
30
+
31
+
32
+ def main() -> None:
33
+ logger.info("Initializing service")
34
+ init(engine)
35
+ logger.info("Service finished initializing")
36
+
37
+
38
+ if __name__ == "__main__":
39
+ main()
@@ -1,63 +1,63 @@
1
- # --------------------------------------------------------------------------
2
- # pytest runtime configuration module
3
- # --------------------------------------------------------------------------
4
- import json
5
- import os
6
- from collections.abc import Generator
7
- from typing import Dict, List
8
-
9
- import pytest
10
- from fastapi.testclient import TestClient
11
- from sqlmodel import Session, SQLModel, delete, select
12
-
13
- from src.core.db import engine, init_db
14
- from src.main import app
15
- from src.schemas.items import ItemBase
16
-
17
-
18
- @pytest.fixture(scope="session", autouse=True)
19
- def db() -> Generator[Session, None, None]:
20
- """
21
- Session-scoped database fixture that sets up the test database
22
- and cleans it up after all tests are done.
23
-
24
- This fixture:
25
- 1. Initializes the database with test data
26
- 2. Yields the session for test use
27
- 3. Cleans up all data after tests complete
28
-
29
- The autouse=True parameter ensures this fixture runs automatically
30
- for all tests in the session.
31
- """
32
- with Session(engine) as session:
33
- # Initialize database with test data
34
- init_db(session)
35
- yield session
36
-
37
- # Clean up - delete all records from tables after tests
38
- statement = delete(ItemBase)
39
- session.execute(statement)
40
- session.commit()
41
-
42
-
43
- @pytest.fixture(name="client")
44
- def client_fixture(db: Session):
45
- """
46
- Create a FastAPI test client with dependency overrides.
47
-
48
- Args:
49
- db: Test database session from the db fixture
50
-
51
- Yields:
52
- FastAPI TestClient
53
- """
54
- def get_session_override():
55
- return db
56
-
57
- app.dependency_overrides = {}
58
- # Override the get_db dependency in routes to use the test session
59
- from src.api.routes.items import get_db
60
- app.dependency_overrides[get_db] = get_session_override
61
-
62
- with TestClient(app) as client:
63
- yield client
1
+ # --------------------------------------------------------------------------
2
+ # pytest runtime configuration module
3
+ # --------------------------------------------------------------------------
4
+ import json
5
+ import os
6
+ from collections.abc import Generator
7
+ from typing import Dict, List
8
+
9
+ import pytest
10
+ from fastapi.testclient import TestClient
11
+ from sqlmodel import Session, SQLModel, delete, select
12
+
13
+ from src.core.db import engine, init_db
14
+ from src.main import app
15
+ from src.schemas.items import ItemBase
16
+
17
+
18
+ @pytest.fixture(scope="session", autouse=True)
19
+ def db() -> Generator[Session, None, None]:
20
+ """
21
+ Session-scoped database fixture that sets up the test database
22
+ and cleans it up after all tests are done.
23
+
24
+ This fixture:
25
+ 1. Initializes the database with test data
26
+ 2. Yields the session for test use
27
+ 3. Cleans up all data after tests complete
28
+
29
+ The autouse=True parameter ensures this fixture runs automatically
30
+ for all tests in the session.
31
+ """
32
+ with Session(engine) as session:
33
+ # Initialize database with test data
34
+ init_db(session)
35
+ yield session
36
+
37
+ # Clean up - delete all records from tables after tests
38
+ statement = delete(ItemBase)
39
+ session.execute(statement)
40
+ session.commit()
41
+
42
+
43
+ @pytest.fixture(name="client")
44
+ def client_fixture(db: Session):
45
+ """
46
+ Create a FastAPI test client with dependency overrides.
47
+
48
+ Args:
49
+ db: Test database session from the db fixture
50
+
51
+ Yields:
52
+ FastAPI TestClient
53
+ """
54
+ def get_session_override():
55
+ return db
56
+
57
+ app.dependency_overrides = {}
58
+ # Override the get_db dependency in routes to use the test session
59
+ from src.api.routes.items import get_db
60
+ app.dependency_overrides[get_db] = get_session_override
61
+
62
+ with TestClient(app) as client:
63
+ yield client
@@ -1,44 +1,44 @@
1
- # --------------------------------------------------------------------------
2
- # Item endpoint testcases
3
- # --------------------------------------------------------------------------
4
- import json
5
-
6
- import pytest
7
-
8
-
9
- def test_read_all_items(client):
10
- response = client.get("/items")
11
- assert response.status_code == 200
12
- assert len(response.json()) == 2
13
-
14
-
15
- def test_read_item_success(client):
16
- response = client.get("/items/1")
17
- assert response.status_code == 200
18
- assert response.json()["name"] == "Test Item 1"
19
-
20
-
21
- def test_read_item_not_found(client):
22
- response = client.get("/items/999")
23
- assert response.status_code == 404
24
-
25
-
26
- def test_create_item(client):
27
- new_item = {"name": "New Item", "price": 30.0, "category": "new"}
28
- response = client.post("/items", json=new_item)
29
- assert response.status_code == 201
30
- assert response.json()["id"] == 3
31
-
32
-
33
- def test_update_item(client):
34
- updated_data = {"name": "Updated Item", "price": 15.0, "category": "updated"}
35
- response = client.put("/items/1", json=updated_data)
36
- assert response.status_code == 200
37
- assert response.json()["name"] == "Updated Item"
38
-
39
-
40
- def test_delete_item(client):
41
- response = client.delete("/items/1")
42
- assert response.status_code == 200
43
- response = client.get("/items/1")
44
- assert response.status_code == 404
1
+ # --------------------------------------------------------------------------
2
+ # Item endpoint testcases
3
+ # --------------------------------------------------------------------------
4
+ import json
5
+
6
+ import pytest
7
+
8
+
9
+ def test_read_all_items(client):
10
+ response = client.get("/items")
11
+ assert response.status_code == 200
12
+ assert len(response.json()) == 2
13
+
14
+
15
+ def test_read_item_success(client):
16
+ response = client.get("/items/1")
17
+ assert response.status_code == 200
18
+ assert response.json()["name"] == "Test Item 1"
19
+
20
+
21
+ def test_read_item_not_found(client):
22
+ response = client.get("/items/999")
23
+ assert response.status_code == 404
24
+
25
+
26
+ def test_create_item(client):
27
+ new_item = {"name": "New Item", "price": 30.0, "category": "new"}
28
+ response = client.post("/items", json=new_item)
29
+ assert response.status_code == 201
30
+ assert response.json()["id"] == 3
31
+
32
+
33
+ def test_update_item(client):
34
+ updated_data = {"name": "Updated Item", "price": 15.0, "category": "updated"}
35
+ response = client.put("/items/1", json=updated_data)
36
+ assert response.status_code == 200
37
+ assert response.json()["name"] == "Updated Item"
38
+
39
+
40
+ def test_delete_item(client):
41
+ response = client.delete("/items/1")
42
+ assert response.status_code == 200
43
+ response = client.get("/items/1")
44
+ assert response.status_code == 404
@@ -1,64 +1,64 @@
1
- # --------------------------------------------------------------------------
2
- # <new_route> CRUD Endpoint
3
- # --------------------------------------------------------------------------
4
- from fastapi import APIRouter
5
-
6
- from src.crud.<new_route> import *
7
- from src.schemas.<new_route> import *
8
-
9
- router = APIRouter()
10
-
11
-
12
- @router.get("/")
13
- def get_route():
14
- result = read_crud()
15
-
16
- # Add Presentation Layer logics here
17
-
18
- return result
19
-
20
-
21
- @router.post("/")
22
- def post_route():
23
- result = create_crud()
24
-
25
- # Add Presentation Layer logics here
26
-
27
- return result
28
-
29
-
30
- @router.put("/")
31
- def put_route():
32
- result = edit_crud()
33
-
34
- # Add Presentation Layer logics here
35
-
36
- return result
37
-
38
-
39
- @router.patch("/")
40
- def patch_route():
41
- result = edit_crud()
42
-
43
- # Add Presentation Layer logics here
44
-
45
- return result
46
-
47
-
48
- @router.delete("/")
49
- def delete_route():
50
- result = remove_crud()
51
-
52
- # Add Presentation Layer logics here
53
-
54
- return result
55
-
56
-
57
- """Add other routers here
58
-
59
- For more information, please refer to the following link:
60
-
61
- https://fastapi.tiangolo.com/tutorial/first-steps/#operation
62
- https://fastapi.tiangolo.com/tutorial/bigger-applications/?h=apirouter#another-module-with-apirouter
63
- https://fastapi.tiangolo.com/tutorial/body/?h=pydantic
64
- """
1
+ # --------------------------------------------------------------------------
2
+ # <new_route> CRUD Endpoint
3
+ # --------------------------------------------------------------------------
4
+ from fastapi import APIRouter
5
+
6
+ from src.crud.<new_route> import *
7
+ from src.schemas.<new_route> import *
8
+
9
+ router = APIRouter()
10
+
11
+
12
+ @router.get("/")
13
+ def get_route():
14
+ result = read_crud()
15
+
16
+ # Add Presentation Layer logics here
17
+
18
+ return result
19
+
20
+
21
+ @router.post("/")
22
+ def post_route():
23
+ result = create_crud()
24
+
25
+ # Add Presentation Layer logics here
26
+
27
+ return result
28
+
29
+
30
+ @router.put("/")
31
+ def put_route():
32
+ result = edit_crud()
33
+
34
+ # Add Presentation Layer logics here
35
+
36
+ return result
37
+
38
+
39
+ @router.patch("/")
40
+ def patch_route():
41
+ result = edit_crud()
42
+
43
+ # Add Presentation Layer logics here
44
+
45
+ return result
46
+
47
+
48
+ @router.delete("/")
49
+ def delete_route():
50
+ result = remove_crud()
51
+
52
+ # Add Presentation Layer logics here
53
+
54
+ return result
55
+
56
+
57
+ """Add other routers here
58
+
59
+ For more information, please refer to the following link:
60
+
61
+ https://fastapi.tiangolo.com/tutorial/first-steps/#operation
62
+ https://fastapi.tiangolo.com/tutorial/bigger-applications/?h=apirouter#another-module-with-apirouter
63
+ https://fastapi.tiangolo.com/tutorial/body/?h=pydantic
64
+ """