1
0
mirror of https://gitlab.com/2-chainz/2chainz.git synced 2025-06-15 17:36:39 +00:00

clean up test

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

View File

@ -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