Updated charts for glucose data and profile chart
This commit is contained in:
@@ -168,6 +168,50 @@ def test_fetch_treatments_range_filters_to_date_boundaries(monkeypatch):
|
||||
assert result.iloc[0]["insulin"] == pytest.approx(4.0)
|
||||
|
||||
|
||||
def test_fetch_entries_for_day_scopes_to_a_single_calendar_day(monkeypatch):
|
||||
monkeypatch.setenv("NIGHTSCOUT_URL", "https://example.com")
|
||||
monkeypatch.delenv("NIGHTSCOUT_TOKEN", raising=False)
|
||||
monkeypatch.delenv("NIGHTSCOUT_API_SECRET", raising=False)
|
||||
|
||||
payload = [
|
||||
{"date": int(datetime(2026, 1, 15, 12, 0, tzinfo=timezone.utc).timestamp() * 1000), "sgv": 126},
|
||||
{"date": int(datetime(2026, 1, 16, 12, 0, tzinfo=timezone.utc).timestamp() * 1000), "sgv": 100},
|
||||
]
|
||||
monkeypatch.setattr(ns.requests, "get", lambda *a, **k: FakeResponse(payload))
|
||||
|
||||
result = ns.fetch_entries_for_day(date(2026, 1, 15))
|
||||
assert len(result) == 1
|
||||
assert result.iloc[0]["timestamp"].date() == date(2026, 1, 15)
|
||||
|
||||
|
||||
def test_fetch_treatments_for_day_includes_lookback_before_midnight(monkeypatch):
|
||||
"""Een Temp Basal die net vóór middernacht is gestart moet toch meekomen
|
||||
(zie de docstring bij fetch_treatments_for_day) — zonder lookback-marge
|
||||
zou effective_basal_series() de vroege ochtenduren fout berekenen."""
|
||||
monkeypatch.setenv("NIGHTSCOUT_URL", "https://example.com")
|
||||
payload = [
|
||||
{"created_at": "2026-01-14T22:00:00Z", "eventType": "Temp Basal", "absolute": 1.2, "duration": 480},
|
||||
{"created_at": "2026-01-15T12:00:00Z", "eventType": "Meal Bolus", "insulin": 4.0, "carbs": 40},
|
||||
{"created_at": "2026-01-10T08:00:00Z", "eventType": "Meal Bolus", "insulin": 3.0, "carbs": 30},
|
||||
]
|
||||
monkeypatch.setattr(ns.requests, "get", lambda *a, **k: FakeResponse(payload))
|
||||
|
||||
result = ns.fetch_treatments_for_day(date(2026, 1, 15), lookback_hours=6)
|
||||
assert len(result) == 2 # de 10 januari-bolus valt buiten de lookback-marge
|
||||
assert set(result["eventType"]) == {"Temp Basal", "Meal Bolus"}
|
||||
|
||||
|
||||
def test_fetch_treatments_for_day_excludes_treatments_before_the_lookback_window(monkeypatch):
|
||||
monkeypatch.setenv("NIGHTSCOUT_URL", "https://example.com")
|
||||
payload = [
|
||||
{"created_at": "2026-01-14T12:00:00Z", "eventType": "Meal Bolus", "insulin": 4.0, "carbs": 40},
|
||||
]
|
||||
monkeypatch.setattr(ns.requests, "get", lambda *a, **k: FakeResponse(payload))
|
||||
|
||||
result = ns.fetch_treatments_for_day(date(2026, 1, 15), lookback_hours=6)
|
||||
assert result.empty
|
||||
|
||||
|
||||
def _entry(dt, sgv=100):
|
||||
return {"date": int(dt.timestamp() * 1000), "sgv": sgv, "dateString": dt.isoformat()}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user