freeleaps-service-hub/apps/devops/tests/routes/test_hello_world.py
2025-05-18 22:23:44 -07:00

28 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 doesnt 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()