diff --git a/my_tiny_service/api/routers/root.py b/my_tiny_service/api/routers/root.py index 598433d..01418ec 100644 --- a/my_tiny_service/api/routers/root.py +++ b/my_tiny_service/api/routers/root.py @@ -1,3 +1,6 @@ +from datetime import datetime +from datetime import datetime +from datetime import datetime import fastapi from my_tiny_service.api.dependencies import get_api_settings @@ -19,3 +22,14 @@ def get_root( not matter. """ return f"{api_settings.title}, version {api_settings.version}" + + +@router.get("/timestamp") +def get_current_timestamp() -> str: + """Endpoint to return the current timestamp in ISO format.""" + return datetime.now().isoformat() + +@router.get("/timestamp", summary="Get current timestamp in ISO format") +def get_timestamp() -> str: + """Get the current timestamp in ISO format.""" + return datetime.now().isoformat() diff --git a/tests/test_api.py b/tests/test_api.py index faf1b23..73df1d0 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -50,3 +50,17 @@ def test_divide_by_zero(client: starlette.testclient.TestClient) -> None: # THEN the status code should be 400 (Bad request) assert response.status_code == 400 + + +def test_timestamp_endpoint(client: starlette.testclient.TestClient) -> None: + """Test that the timestamp endpoint returns the current timestamp in ISO format.""" + response = client.get("/timestamp") + assert response.status_code == 200 + # The response should be a valid ISO format timestamp + # This is a basic check, in a real scenario, more robust validation would be needed + assert "T" in response.json() + +def test_get_timestamp(client: starlette.testclient.TestClient) -> None: + response = client.get("/timestamp") + assert response.status_code == 200 + # Additional checks can be added to validate the timestamp format