mirror of
https://gitlab.com/2-chainz/2chainz.git
synced 2025-06-16 01:46:39 +00:00
clean up test
This commit is contained in:
parent
e488f979c1
commit
5687871b86
@ -4,37 +4,32 @@ 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
|
|
||||||
response = client.get("/api/")
|
|
||||||
assert response.status_code == 200
|
|
||||||
|
|
||||||
data = response.json()
|
def test_api_endpoint(self):
|
||||||
assert "status" in data
|
response = client.get("/api/")
|
||||||
assert data["status"] == "ok"
|
assert response.status_code == 200
|
||||||
assert "timestamp" in data
|
|
||||||
assert "uptime_seconds" in data
|
|
||||||
|
|
||||||
# Validate timestamp format (ISO format)
|
data = response.json()
|
||||||
try:
|
|
||||||
datetime.fromisoformat(data["timestamp"])
|
|
||||||
is_valid_timestamp = True
|
|
||||||
except ValueError:
|
|
||||||
is_valid_timestamp = False
|
|
||||||
|
|
||||||
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", [
|
# Validate timestamp format (ISO format)
|
||||||
(100, 50, 50), # 100 - 50 = 50 seconds uptime
|
assert datetime.fromisoformat(data["timestamp"])
|
||||||
(200, 100, 100), # 200 - 100 = 100 seconds uptime
|
|
||||||
])
|
@pytest.mark.parametrize("mocked_time,start_time,expected", [
|
||||||
def test_api_uptime_calculation(mocked_time, start_time, expected):
|
(100, 50, 50), # 100 - 50 = 50 seconds uptime
|
||||||
with patch('time.time', return_value=mocked_time):
|
(200, 100, 100), # 200 - 100 = 100 seconds uptime
|
||||||
with patch('two_chainz.start_time', start_time):
|
])
|
||||||
response = client.get("/api/")
|
def test_api_uptime_calculation(self, mocked_time, start_time, expected):
|
||||||
assert response.json()["uptime_seconds"] == 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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user