mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-17 16:44:29 +03:00
Added tests for review summary endpoint (multiple days with alerts in the last month and edge case)
This commit is contained in:
parent
22408e9e48
commit
6ad57af9b1
@ -239,3 +239,66 @@ class TestHttpReview(BaseTestHttp):
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
self.assertEqual(review_summary_response, expected_response)
|
self.assertEqual(review_summary_response, expected_response)
|
||||||
|
|
||||||
|
def test_get_review_summary_multiple_days_edge_cases(self):
|
||||||
|
now = datetime.now()
|
||||||
|
five_days_ago = datetime.today() - timedelta(days=5)
|
||||||
|
twenty_days_ago = datetime.today() - timedelta(days=20)
|
||||||
|
one_month_ago = datetime.today() - timedelta(days=30)
|
||||||
|
|
||||||
|
with TestClient(self.app) as client:
|
||||||
|
super().insert_mock_review_segment("123456.random", now.timestamp())
|
||||||
|
super().insert_mock_review_segment("123457.random", five_days_ago.timestamp())
|
||||||
|
super().insert_mock_review_segment("123458.random", twenty_days_ago.timestamp(), None, SeverityEnum.detection)
|
||||||
|
# One month ago plus 5 seconds fits within the condition (review.start_time > month_ago). Assuming that the endpoint does not take more than 5 seconds to be invoked
|
||||||
|
super().insert_mock_review_segment("123459.random", one_month_ago.timestamp() + 5, None, SeverityEnum.detection)
|
||||||
|
# This won't appear in the output since it's within last month start_time clause (review.start_time > month_ago)
|
||||||
|
super().insert_mock_review_segment("123450.random", one_month_ago.timestamp() + 0)
|
||||||
|
review_summary_request = client.get("/review/summary")
|
||||||
|
assert review_summary_request.status_code == 200
|
||||||
|
review_summary_response = review_summary_request.json()
|
||||||
|
# e.g. '2024-11-24'
|
||||||
|
today_formatted = now.strftime("%Y-%m-%d")
|
||||||
|
# e.g. '2024-11-19'
|
||||||
|
five_days_ago_formatted = five_days_ago.strftime("%Y-%m-%d")
|
||||||
|
# e.g. '2024-11-04'
|
||||||
|
twenty_days_ago_formatted = five_days_ago.strftime("%Y-%m-%d")
|
||||||
|
# e.g. '2024-10-24'
|
||||||
|
one_month_ago_formatted = five_days_ago.strftime("%Y-%m-%d")
|
||||||
|
expected_response = {
|
||||||
|
"last24Hours": {
|
||||||
|
"reviewed_alert": 0,
|
||||||
|
"reviewed_detection": 0,
|
||||||
|
"total_alert": 1,
|
||||||
|
"total_detection": 0,
|
||||||
|
},
|
||||||
|
today_formatted: {
|
||||||
|
"day": today_formatted,
|
||||||
|
"reviewed_alert": 0,
|
||||||
|
"reviewed_detection": 0,
|
||||||
|
"total_alert": 1,
|
||||||
|
"total_detection": 0,
|
||||||
|
},
|
||||||
|
five_days_ago_formatted: {
|
||||||
|
"day": five_days_ago_formatted,
|
||||||
|
"reviewed_alert": 0,
|
||||||
|
"reviewed_detection": 0,
|
||||||
|
"total_alert": 1,
|
||||||
|
"total_detection": 0,
|
||||||
|
},
|
||||||
|
twenty_days_ago_formatted: {
|
||||||
|
"day": twenty_days_ago_formatted,
|
||||||
|
"reviewed_alert": 0,
|
||||||
|
"reviewed_detection": 0,
|
||||||
|
"total_alert": 0,
|
||||||
|
"total_detection": 1,
|
||||||
|
},
|
||||||
|
one_month_ago_formatted: {
|
||||||
|
"day": one_month_ago_formatted,
|
||||||
|
"reviewed_alert": 0,
|
||||||
|
"reviewed_detection": 0,
|
||||||
|
"total_alert": 0,
|
||||||
|
"total_detection": 1,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
self.assertEqual(review_summary_response, expected_response)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user