mirror of
https://gitlab.com/2-chainz/2chainz.git
synced 2025-06-15 09:26:39 +00:00
Accidentally didn't push this stuff and deleted it last night lol
This commit is contained in:
parent
9725f84268
commit
e488f979c1
@ -1,22 +1,27 @@
|
||||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
|
||||
// README at: https://github.com/devcontainers/templates/tree/main/src/debian
|
||||
{
|
||||
"name": "Debian",
|
||||
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
|
||||
"image": "mcr.microsoft.com/devcontainers/base:bullseye",
|
||||
"features": {
|
||||
"ghcr.io/va-h/devcontainers-features/uv:1": {}
|
||||
}
|
||||
"name": "Debian",
|
||||
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
|
||||
"image": "mcr.microsoft.com/devcontainers/base:bullseye",
|
||||
"features": {
|
||||
"ghcr.io/va-h/devcontainers-features/uv:1": {}
|
||||
},
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": ["tamasfe.even-better-toml"]
|
||||
}
|
||||
}
|
||||
|
||||
// Features to add to the dev container. More info: https://containers.dev/features.
|
||||
// "features": {},
|
||||
// Features to add to the dev container. More info: https://containers.dev/features.
|
||||
// "features": {},
|
||||
|
||||
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||
// "forwardPorts": [],
|
||||
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||
// "forwardPorts": [],
|
||||
|
||||
// Configure tool-specific properties.
|
||||
// "customizations": {},
|
||||
// Configure tool-specific properties.
|
||||
// "customizations": {},
|
||||
|
||||
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
|
||||
// "remoteUser": "root"
|
||||
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
|
||||
// "remoteUser": "root"
|
||||
}
|
||||
|
40
src/test/test_api.py
Normal file
40
src/test/test_api.py
Normal file
@ -0,0 +1,40 @@
|
||||
from fastapi.testclient import TestClient
|
||||
from datetime import datetime
|
||||
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
|
||||
|
||||
data = response.json()
|
||||
assert "status" in data
|
||||
assert data["status"] == "ok"
|
||||
assert "timestamp" in data
|
||||
assert "uptime_seconds" in data
|
||||
|
||||
# Validate timestamp format (ISO format)
|
||||
try:
|
||||
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", [
|
||||
(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
|
22
src/two_chainz/__init__.py
Normal file
22
src/two_chainz/__init__.py
Normal file
@ -0,0 +1,22 @@
|
||||
import time
|
||||
from datetime import datetime
|
||||
from fastapi import FastAPI
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
|
||||
|
||||
|
||||
|
||||
app = FastAPI()
|
||||
start_time = time.time()
|
||||
|
||||
@app.get("/api/")
|
||||
async def ping():
|
||||
return {
|
||||
"status": "ok",
|
||||
"timestamp": datetime.now().isoformat(),
|
||||
"uptime_seconds": round(time.time() - start_time, 2),
|
||||
}
|
||||
|
||||
|
||||
# Mount static files
|
||||
app.mount("/", StaticFiles(directory="website", html=True), name="static")
|
Loading…
x
Reference in New Issue
Block a user