Working state, settings are fixed

This commit is contained in:
Moritz Graf
2026-01-01 23:28:58 +01:00
parent bf744b30dc
commit d369ac4232
4 changed files with 70 additions and 9 deletions
+2 -1
View File
@@ -109,7 +109,8 @@ async def get_settings_status():
return {
"garmin": {
"configured": bool(os.getenv("GARMIN_EMAIL") and os.getenv("GARMIN_PASSWORD"))
"configured": bool(os.getenv("GARMIN_EMAIL") and os.getenv("GARMIN_PASSWORD")),
"email": os.getenv("GARMIN_EMAIL")
},
"withings": {
"configured": bool(os.getenv("WITHINGS_CLIENT_ID") and os.getenv("WITHINGS_CLIENT_SECRET"))
+11 -6
View File
@@ -184,9 +184,11 @@ def test_update_settings_gemini_missing():
assert response.status_code == 400
def test_auth_status_not_configured(monkeypatch):
monkeypatch.setenv("GARMIN_EMAIL", "")
response = client.get("/auth/status")
assert response.json()["authenticated"] is False
# Mock load_service_env to prevent reloading from file
with patch("main.env.load_service_env"):
monkeypatch.setenv("GARMIN_EMAIL", "")
response = client.get("/auth/status")
assert response.json()["authenticated"] is False
def test_sync_full_success(mock_sync):
with patch("main.GarminClient") as mock_client:
@@ -269,9 +271,12 @@ def test_trigger_sync_endpoint_fail():
response = client.post("/sync")
assert response.status_code == 401
def test_login_credentials_missing():
response = client.post("/auth/login", json={"email": ""})
assert response.status_code == 400
def test_login_credentials_missing(monkeypatch):
with patch("main.env.load_service_env"):
monkeypatch.setenv("GARMIN_EMAIL", "")
monkeypatch.setenv("GARMIN_PASSWORD", "")
response = client.post("/auth/login", json={"email": ""})
assert response.status_code == 400
def test_login_failed_error():
with patch("main.GarminClient") as mock_client:
+6 -2
View File
@@ -71,7 +71,9 @@ def test_login_mfa_complete_no_client_in_state(mock_sso, mock_garmin):
assert client.login(mfa_code="123456") == "SUCCESS"
mock_garth.client.configure.assert_called_once()
def test_login_mfa_required_no_creds(mock_garmin):
def test_login_mfa_required_no_creds(mock_garmin, monkeypatch):
monkeypatch.setenv("GARMIN_EMAIL", "")
monkeypatch.setenv("GARMIN_PASSWORD", "")
client = GarminClient(email="", password="")
GarminClient._temp_client_state = {"some": "state"}
with patch("os.path.exists", return_value=False):
@@ -135,7 +137,9 @@ def test_login_json_error_cleanup(mock_garmin):
assert client.login() == "FAILURE"
assert mock_remove.called
def test_login_missing_creds(mock_garmin):
def test_login_missing_creds(mock_garmin, monkeypatch):
monkeypatch.setenv("GARMIN_EMAIL", "")
monkeypatch.setenv("GARMIN_PASSWORD", "")
client = GarminClient(email="", password="")
with patch("os.path.exists", return_value=False):
assert client.login() == "FAILURE"