58 lines
1.9 KiB
Python
58 lines
1.9 KiB
Python
from __future__ import annotations
|
|
|
|
import importlib
|
|
|
|
from fastapi.testclient import TestClient
|
|
|
|
|
|
def test_first_launch_setup_login_and_health(tmp_path, monkeypatch) -> None:
|
|
monkeypatch.setenv("DATA_DIR", str(tmp_path))
|
|
monkeypatch.setenv("APP_PASSWORD", "change-me")
|
|
monkeypatch.setenv("APP_SECRET_KEY", "test-secret")
|
|
module = importlib.import_module("garmin_coach_clone.app")
|
|
app = module.create_app()
|
|
|
|
with TestClient(app) as client:
|
|
health = client.get("/healthz")
|
|
assert health.status_code == 200
|
|
assert health.json()["app_configured"] is False
|
|
|
|
response = client.post(
|
|
"/setup",
|
|
data={
|
|
"username": "owner",
|
|
"password": "very-secret",
|
|
"confirm_password": "very-secret",
|
|
},
|
|
follow_redirects=False,
|
|
)
|
|
assert response.status_code == 303
|
|
assert "gcc_session" in response.headers["set-cookie"]
|
|
|
|
dashboard = client.get("/")
|
|
assert dashboard.status_code == 200
|
|
assert "Dashboard" in dashboard.text
|
|
|
|
search = client.get("/search")
|
|
assert search.status_code == 200
|
|
assert "Garmin credentials are not configured" in search.text
|
|
|
|
|
|
def test_env_bootstrap_login(tmp_path, monkeypatch) -> None:
|
|
monkeypatch.setenv("DATA_DIR", str(tmp_path))
|
|
monkeypatch.setenv("APP_USERNAME", "admin")
|
|
monkeypatch.setenv("APP_PASSWORD", "boot-secret")
|
|
monkeypatch.setenv("APP_SECRET_KEY", "test-secret")
|
|
module = importlib.import_module("garmin_coach_clone.app")
|
|
app = module.create_app()
|
|
|
|
with TestClient(app) as client:
|
|
health = client.get("/healthz")
|
|
assert health.json()["app_configured"] is True
|
|
response = client.post(
|
|
"/login",
|
|
data={"username": "admin", "password": "boot-secret"},
|
|
follow_redirects=False,
|
|
)
|
|
assert response.status_code == 303
|