Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions my_tiny_service/api/routers/root.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
14 changes: 14 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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