diff --git a/apps/devops/tests/routes/test_hello_world.py b/apps/devops/tests/routes/test_hello_world.py deleted file mode 100644 index 285d174..0000000 --- a/apps/devops/tests/routes/test_hello_world.py +++ /dev/null @@ -1,9 +0,0 @@ -from fastapi.testclient import TestClient -from app.main import app # Adjust this import if your app is in a different location - -client = TestClient(app) - -def test_hello_world(): - response = client.get("/api/hello_world/") - assert response.status_code == 200 - assert response.json() == {"message": "Hello, World!"} # Update if your endpoint returns different data \ No newline at end of file diff --git a/apps/devops/README.md b/apps/helloworld/README.md similarity index 92% rename from apps/devops/README.md rename to apps/helloworld/README.md index 588044f..2fb84b3 100644 --- a/apps/devops/README.md +++ b/apps/helloworld/README.md @@ -1,6 +1,6 @@ This is a template backend service based on fastapi + mongodb app -To start development in local, go to the root directory of the project YOUR_WORKSPACE_PATH/devops/ +To start development in local, go to the root directory of the project YOUR_WORKSPACE_PATH/helloworld/ ```bash docker compose -f app/scripts/mongodb/docker-compose.yml up -d ``` diff --git a/apps/devops/app/__init__.py b/apps/helloworld/app/__init__.py similarity index 100% rename from apps/devops/app/__init__.py rename to apps/helloworld/app/__init__.py diff --git a/apps/devops/app/bootstrap/__init__.py b/apps/helloworld/app/bootstrap/__init__.py similarity index 100% rename from apps/devops/app/bootstrap/__init__.py rename to apps/helloworld/app/bootstrap/__init__.py diff --git a/apps/devops/app/bootstrap/application.py b/apps/helloworld/app/bootstrap/application.py similarity index 100% rename from apps/devops/app/bootstrap/application.py rename to apps/helloworld/app/bootstrap/application.py diff --git a/apps/devops/app/common/__init__.py b/apps/helloworld/app/common/__init__.py similarity index 100% rename from apps/devops/app/common/__init__.py rename to apps/helloworld/app/common/__init__.py diff --git a/apps/devops/app/common/config/__init__.py b/apps/helloworld/app/common/config/__init__.py similarity index 100% rename from apps/devops/app/common/config/__init__.py rename to apps/helloworld/app/common/config/__init__.py diff --git a/apps/devops/app/common/config/app_settings.py b/apps/helloworld/app/common/config/app_settings.py similarity index 100% rename from apps/devops/app/common/config/app_settings.py rename to apps/helloworld/app/common/config/app_settings.py diff --git a/apps/devops/app/common/config/log_settings.py b/apps/helloworld/app/common/config/log_settings.py similarity index 100% rename from apps/devops/app/common/config/log_settings.py rename to apps/helloworld/app/common/config/log_settings.py diff --git a/apps/devops/app/common/config/site_settings.py b/apps/helloworld/app/common/config/site_settings.py similarity index 100% rename from apps/devops/app/common/config/site_settings.py rename to apps/helloworld/app/common/config/site_settings.py diff --git a/apps/devops/app/common/daos/__init__.py b/apps/helloworld/app/common/daos/__init__.py similarity index 100% rename from apps/devops/app/common/daos/__init__.py rename to apps/helloworld/app/common/daos/__init__.py diff --git a/apps/devops/app/common/daos/hello_world/__init__.py b/apps/helloworld/app/common/daos/hello_world/__init__.py similarity index 59% rename from apps/devops/app/common/daos/hello_world/__init__.py rename to apps/helloworld/app/common/daos/hello_world/__init__.py index b953163..463a9cb 100644 --- a/apps/devops/app/common/daos/hello_world/__init__.py +++ b/apps/helloworld/app/common/daos/hello_world/__init__.py @@ -1,3 +1,6 @@ from app.common.daos.hello_world.hello_world_dao import HelloWorldDao hello_world_dao = HelloWorldDao() + +def get_hello_world_dao() -> HelloWorldDao: + return hello_world_dao diff --git a/apps/devops/app/common/daos/hello_world/hello_world_dao.py b/apps/helloworld/app/common/daos/hello_world/hello_world_dao.py similarity index 100% rename from apps/devops/app/common/daos/hello_world/hello_world_dao.py rename to apps/helloworld/app/common/daos/hello_world/hello_world_dao.py diff --git a/apps/devops/app/common/log/__init__.py b/apps/helloworld/app/common/log/__init__.py similarity index 100% rename from apps/devops/app/common/log/__init__.py rename to apps/helloworld/app/common/log/__init__.py diff --git a/apps/devops/app/common/log/application_logger.py b/apps/helloworld/app/common/log/application_logger.py similarity index 100% rename from apps/devops/app/common/log/application_logger.py rename to apps/helloworld/app/common/log/application_logger.py diff --git a/apps/devops/app/common/log/base_logger.py b/apps/helloworld/app/common/log/base_logger.py similarity index 100% rename from apps/devops/app/common/log/base_logger.py rename to apps/helloworld/app/common/log/base_logger.py diff --git a/apps/devops/app/common/log/json_sink.py b/apps/helloworld/app/common/log/json_sink.py similarity index 100% rename from apps/devops/app/common/log/json_sink.py rename to apps/helloworld/app/common/log/json_sink.py diff --git a/apps/devops/app/common/models/__init__.py b/apps/helloworld/app/common/models/__init__.py similarity index 100% rename from apps/devops/app/common/models/__init__.py rename to apps/helloworld/app/common/models/__init__.py diff --git a/apps/devops/app/common/models/hello_world/__init__.py b/apps/helloworld/app/common/models/hello_world/__init__.py similarity index 100% rename from apps/devops/app/common/models/hello_world/__init__.py rename to apps/helloworld/app/common/models/hello_world/__init__.py diff --git a/apps/devops/app/common/models/hello_world/hello_world.py b/apps/helloworld/app/common/models/hello_world/hello_world.py similarity index 100% rename from apps/devops/app/common/models/hello_world/hello_world.py rename to apps/helloworld/app/common/models/hello_world/hello_world.py diff --git a/apps/devops/app/common/probes/__init__.py b/apps/helloworld/app/common/probes/__init__.py similarity index 100% rename from apps/devops/app/common/probes/__init__.py rename to apps/helloworld/app/common/probes/__init__.py diff --git a/apps/devops/app/common/probes/adapters.py b/apps/helloworld/app/common/probes/adapters.py similarity index 100% rename from apps/devops/app/common/probes/adapters.py rename to apps/helloworld/app/common/probes/adapters.py diff --git a/apps/devops/app/envs/alpha.yml b/apps/helloworld/app/envs/alpha.yml similarity index 100% rename from apps/devops/app/envs/alpha.yml rename to apps/helloworld/app/envs/alpha.yml diff --git a/apps/devops/app/envs/prod.yml b/apps/helloworld/app/envs/prod.yml similarity index 100% rename from apps/devops/app/envs/prod.yml rename to apps/helloworld/app/envs/prod.yml diff --git a/apps/devops/app/main.py b/apps/helloworld/app/main.py similarity index 100% rename from apps/devops/app/main.py rename to apps/helloworld/app/main.py diff --git a/apps/devops/app/providers/__init__.py b/apps/helloworld/app/providers/__init__.py similarity index 100% rename from apps/devops/app/providers/__init__.py rename to apps/helloworld/app/providers/__init__.py diff --git a/apps/devops/app/providers/common.py b/apps/helloworld/app/providers/common.py similarity index 100% rename from apps/devops/app/providers/common.py rename to apps/helloworld/app/providers/common.py diff --git a/apps/devops/app/providers/database.py b/apps/helloworld/app/providers/database.py similarity index 100% rename from apps/devops/app/providers/database.py rename to apps/helloworld/app/providers/database.py diff --git a/apps/devops/app/providers/exception_handler.py b/apps/helloworld/app/providers/exception_handler.py similarity index 100% rename from apps/devops/app/providers/exception_handler.py rename to apps/helloworld/app/providers/exception_handler.py diff --git a/apps/devops/app/providers/logger.py b/apps/helloworld/app/providers/logger.py similarity index 100% rename from apps/devops/app/providers/logger.py rename to apps/helloworld/app/providers/logger.py diff --git a/apps/devops/app/providers/metrics.py b/apps/helloworld/app/providers/metrics.py similarity index 100% rename from apps/devops/app/providers/metrics.py rename to apps/helloworld/app/providers/metrics.py diff --git a/apps/devops/app/providers/probes.py b/apps/helloworld/app/providers/probes.py similarity index 100% rename from apps/devops/app/providers/probes.py rename to apps/helloworld/app/providers/probes.py diff --git a/apps/devops/app/providers/router.py b/apps/helloworld/app/providers/router.py similarity index 100% rename from apps/devops/app/providers/router.py rename to apps/helloworld/app/providers/router.py diff --git a/apps/devops/app/providers/scheduler.py b/apps/helloworld/app/providers/scheduler.py similarity index 100% rename from apps/devops/app/providers/scheduler.py rename to apps/helloworld/app/providers/scheduler.py diff --git a/apps/devops/app/routes/__init__.py b/apps/helloworld/app/routes/__init__.py similarity index 100% rename from apps/devops/app/routes/__init__.py rename to apps/helloworld/app/routes/__init__.py diff --git a/apps/devops/app/routes/hello_world/__init__.py b/apps/helloworld/app/routes/hello_world/__init__.py similarity index 100% rename from apps/devops/app/routes/hello_world/__init__.py rename to apps/helloworld/app/routes/hello_world/__init__.py diff --git a/apps/devops/app/routes/hello_world/apis.py b/apps/helloworld/app/routes/hello_world/apis.py similarity index 53% rename from apps/devops/app/routes/hello_world/apis.py rename to apps/helloworld/app/routes/hello_world/apis.py index dfb8cf0..9f4902a 100644 --- a/apps/devops/app/routes/hello_world/apis.py +++ b/apps/helloworld/app/routes/hello_world/apis.py @@ -1,7 +1,7 @@ -from fastapi import APIRouter +from fastapi import APIRouter, Depends from loguru import logger -from app.common.daos.hello_world import hello_world_dao +from app.common.daos.hello_world import get_hello_world_dao, HelloWorldDao router = APIRouter() @@ -12,11 +12,14 @@ async def hello_world(): @router.post("/insert") -async def insert_hello_world(msg: str): +async def insert_hello_world(msg: str, dao: HelloWorldDao = Depends(get_hello_world_dao)): """ Insert a HelloWorld document into the database. """ - hello_world = await hello_world_dao.create_hello_world(msg, 1) + hello_world = await dao.create_hello_world(msg, 1) return hello_world + + + diff --git a/apps/devops/app/scripts/mongodb/docker-compose.yml b/apps/helloworld/app/scripts/mongodb/docker-compose.yml similarity index 100% rename from apps/devops/app/scripts/mongodb/docker-compose.yml rename to apps/helloworld/app/scripts/mongodb/docker-compose.yml diff --git a/apps/devops/requirements.txt b/apps/helloworld/requirements.txt similarity index 100% rename from apps/devops/requirements.txt rename to apps/helloworld/requirements.txt diff --git a/apps/devops/tests/__init__.py b/apps/helloworld/tests/__init__.py similarity index 100% rename from apps/devops/tests/__init__.py rename to apps/helloworld/tests/__init__.py diff --git a/apps/devops/tests/routes/__init__.py b/apps/helloworld/tests/routes/__init__.py similarity index 100% rename from apps/devops/tests/routes/__init__.py rename to apps/helloworld/tests/routes/__init__.py diff --git a/apps/helloworld/tests/routes/test_hello_world.py b/apps/helloworld/tests/routes/test_hello_world.py new file mode 100644 index 0000000..638a4b2 --- /dev/null +++ b/apps/helloworld/tests/routes/test_hello_world.py @@ -0,0 +1,27 @@ +from unittest.mock import AsyncMock, patch +from fastapi.testclient import TestClient +from app.main import app +from app.routes.hello_world.apis import get_hello_world_dao + + +def test_hello_world(): + with TestClient(app) as client: + response = client.get("/api/hello_world/") + assert response.status_code == 200 + assert response.json() == {"message": "Hello, World!"} + + +# mock out initiate_database so it doesn’t run during tests +@patch("app.providers.database.initiate_database", new_callable=AsyncMock) +def test_insert_hello_world(mock_db_init): + + class MockHelloWorldDao: + async def create_hello_world(self, msg: str, user_id: int): + return {"message": msg, "user_id": user_id} + + app.dependency_overrides[get_hello_world_dao] = lambda: MockHelloWorldDao() + with TestClient(app) as client: + response = client.post("/api/hello_world/insert", params={"msg": "Test Message"}) + assert response.status_code == 200 + assert response.json() == {"message": "Test Message", "user_id": 1} + app.dependency_overrides.clear() diff --git a/apps/devops/test_main.http b/apps/helloworld/tests/test_main.http similarity index 100% rename from apps/devops/test_main.http rename to apps/helloworld/tests/test_main.http