Emby-Historie für 30 und 90 Tage stabilisieren #45
1 changed files with 54 additions and 0 deletions
|
|
@ -216,6 +216,60 @@ def test_emby_account_sharing_endpoint_is_read_only_and_filterable(monkeypatch):
|
|||
assert payload["users"][0]["username"] == "Alice"
|
||||
|
||||
|
||||
def test_emby_history_step_stays_below_prometheus_resolution_limit():
|
||||
assert app._emby_history_step(7) == 60
|
||||
for days in (7, 30, 90):
|
||||
step = app._emby_history_step(days)
|
||||
assert step % 60 == 0
|
||||
assert (days * 86400) / step <= 10_500
|
||||
|
||||
|
||||
def test_emby_history_fetch_chunks_90_days_and_merges_equal_series(monkeypatch):
|
||||
calls = []
|
||||
|
||||
class FakeResponse:
|
||||
def __init__(self, params):
|
||||
self.params = params
|
||||
|
||||
def raise_for_status(self):
|
||||
return None
|
||||
|
||||
def json(self):
|
||||
start = self.params["start"]
|
||||
end = self.params["end"]
|
||||
return {"status": "success", "data": {"result": [{
|
||||
"metric": {"job": "emby-sascha", "username": "Alice", "remoteEndPoint": "8.8.8.8"},
|
||||
"values": [[start, "1"], [end, "1"]],
|
||||
}]}}
|
||||
|
||||
class FakeClient:
|
||||
def __init__(self, **_kwargs):
|
||||
pass
|
||||
|
||||
async def __aenter__(self):
|
||||
return self
|
||||
|
||||
async def __aexit__(self, *_args):
|
||||
return None
|
||||
|
||||
async def get(self, _url, params, headers, cookies):
|
||||
calls.append(params)
|
||||
return FakeResponse(params)
|
||||
|
||||
monkeypatch.setattr(app, "SERVICES", {"grafana": {"url": "http://grafana", "auth": "none"}})
|
||||
monkeypatch.setattr(app.httpx, "AsyncClient", FakeClient)
|
||||
monkeypatch.setattr(app.time, "time", lambda: 10_000_000)
|
||||
|
||||
series, step = asyncio.run(app._fetch_emby_session_history(90, "all"))
|
||||
|
||||
assert len(calls) == 3
|
||||
assert all(call["end"] - call["start"] <= 30 * 86400 for call in calls)
|
||||
assert step == 780
|
||||
assert len(series) == 1
|
||||
timestamps = [value[0] for value in series[0]["values"]]
|
||||
assert timestamps == sorted(set(timestamps))
|
||||
|
||||
|
||||
def test_capabilities_is_live_machine_readable_safety_map():
|
||||
with TestClient(app.app) as client:
|
||||
response = client.get(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue