diff --git a/src/test/test_api.py b/src/test/test_api.py index 4fca645..043c2c8 100644 --- a/src/test/test_api.py +++ b/src/test/test_api.py @@ -4,37 +4,32 @@ import time import pytest from unittest.mock import patch -# Import your app here from two_chainz import app client = TestClient(app) -def test_api_endpoint(): - # Test the API endpoint returns 200 and correct structure - response = client.get("/api/") - assert response.status_code == 200 +class TestApi: - data = response.json() - assert "status" in data - assert data["status"] == "ok" - assert "timestamp" in data - assert "uptime_seconds" in data + def test_api_endpoint(self): + response = client.get("/api/") + assert response.status_code == 200 - # Validate timestamp format (ISO format) - try: - datetime.fromisoformat(data["timestamp"]) - is_valid_timestamp = True - except ValueError: - is_valid_timestamp = False + data = response.json() - assert is_valid_timestamp + assert "status" in data + assert data["status"] == "ok" + assert "timestamp" in data + assert "uptime_seconds" in data -@pytest.mark.parametrize("mocked_time,start_time,expected", [ - (100, 50, 50), # 100 - 50 = 50 seconds uptime - (200, 100, 100), # 200 - 100 = 100 seconds uptime -]) -def test_api_uptime_calculation(mocked_time, start_time, expected): - with patch('time.time', return_value=mocked_time): - with patch('two_chainz.start_time', start_time): - response = client.get("/api/") - assert response.json()["uptime_seconds"] == expected + # Validate timestamp format (ISO format) + assert datetime.fromisoformat(data["timestamp"]) + + @pytest.mark.parametrize("mocked_time,start_time,expected", [ + (100, 50, 50), # 100 - 50 = 50 seconds uptime + (200, 100, 100), # 200 - 100 = 100 seconds uptime + ]) + def test_api_uptime_calculation(self, mocked_time, start_time, expected): + with patch('time.time', return_value=mocked_time): + with patch('two_chainz.start_time', start_time): + response = client.get("/api/") + assert response.json()["uptime_seconds"] == expected