1
0
mirror of https://gitlab.com/2-chainz/2chainz.git synced 2025-08-02 03:31:25 +00:00

clean up test

This commit is contained in:
2025-05-23 12:04:51 -06:00
parent e488f979c1
commit 5687871b86

View File

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