From 35457ca796b53b9479c12acd0cad5ed3c773eab3 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Mon, 1 Jun 2026 14:50:16 -0500 Subject: [PATCH] add tests --- frigate/test/http_api/test_http_media.py | 72 +++++++++++++++++++++++ frigate/test/http_api/test_http_review.py | 11 ++-- 2 files changed, 76 insertions(+), 7 deletions(-) diff --git a/frigate/test/http_api/test_http_media.py b/frigate/test/http_api/test_http_media.py index 6af3dd9724..58f9f92477 100644 --- a/frigate/test/http_api/test_http_media.py +++ b/frigate/test/http_api/test_http_media.py @@ -403,3 +403,75 @@ class TestHttpMedia(BaseTestHttp): assert len(summary) == 1 assert "2024-03-10" in summary assert summary["2024-03-10"] is True + + def test_recordings_unavailable_reports_gap_between_recordings(self): + """A gap between two recordings is reported as an unavailable segment.""" + with AuthTestClient(self.app) as client: + # Two recordings with a 20s gap (1010-1030) between them. + Recordings.insert( + id="rec_a", + path="/media/recordings/a.mp4", + camera="front_door", + start_time=1000, + end_time=1010, + duration=10, + motion=0, + ).execute() + Recordings.insert( + id="rec_b", + path="/media/recordings/b.mp4", + camera="front_door", + start_time=1030, + end_time=1040, + duration=10, + motion=0, + ).execute() + + response = client.get( + "/recordings/unavailable", + params={ + "after": 1000, + "before": 1040, + "scale": 5, + "cameras": "front_door", + }, + ) + + assert response.status_code == 200 + assert response.json() == [{"start_time": 1010, "end_time": 1030}] + + def test_recordings_unavailable_merges_overlapping_recordings(self): + """Overlapping recordings are merged so no false gap is reported.""" + with AuthTestClient(self.app) as client: + # Overlapping recordings spanning the whole requested range. + Recordings.insert( + id="rec_a", + path="/media/recordings/a.mp4", + camera="front_door", + start_time=1000, + end_time=1020, + duration=20, + motion=0, + ).execute() + Recordings.insert( + id="rec_b", + path="/media/recordings/b.mp4", + camera="front_door", + start_time=1010, + end_time=1030, + duration=20, + motion=0, + ).execute() + + response = client.get( + "/recordings/unavailable", + params={ + "after": 1000, + "before": 1030, + "scale": 5, + "cameras": "front_door", + }, + ) + + assert response.status_code == 200 + assert response.json() == [] diff --git a/frigate/test/http_api/test_http_review.py b/frigate/test/http_api/test_http_review.py index ca73c87064..d13a7bd273 100644 --- a/frigate/test/http_api/test_http_review.py +++ b/frigate/test/http_api/test_http_review.py @@ -610,19 +610,16 @@ class TestHttpReview(BaseTestHttp): response = client.get("/review/activity/motion", params=params) assert response.status_code == 200 response_json = response.json() - assert len(response_json) == 61 + # Only buckets with an actual recording are returned. Empty + # gap-fill buckets between the two recordings are dropped. + assert len(response_json) == 2 self.assertDictEqual( {"motion": 50.5, "camera": "front_door", "start_time": now + 1}, response_json[0], ) - for item in response_json[1:-1]: - self.assertDictEqual( - {"motion": 0.0, "camera": "", "start_time": item["start_time"]}, - item, - ) self.assertDictEqual( {"motion": 100.0, "camera": "front_door", "start_time": one_m + 1}, - response_json[len(response_json) - 1], + response_json[1], ) ####################################################################################################################