Add tests for since timestamp accuracy in ban_service
- test_since_unix_returns_utc_epoch: validates since_unix('24h') returns UTC epoch
- test_ban_trend_since_is_within_expected_range: validates 23h-ago ban falls in 24h+slack window
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -134,3 +134,15 @@ class TestSinceUnix:
|
||||
# The slack should be ~60 seconds
|
||||
assert actual_slack >= TIME_RANGE_SLACK_SECONDS - 1
|
||||
assert actual_slack <= TIME_RANGE_SLACK_SECONDS + 1
|
||||
|
||||
def test_since_unix_returns_utc_epoch(self) -> None:
|
||||
"""``since_unix('24h')`` returns a value within 24h + 60s of ``time.time()``."""
|
||||
before = int(time.time())
|
||||
result = since_unix("24h")
|
||||
after = int(time.time())
|
||||
|
||||
# Allow 2 second tolerance for execution time
|
||||
expected_min = before - (24 * 3600) - TIME_RANGE_SLACK_SECONDS - 2
|
||||
expected_max = after - (24 * 3600) - TIME_RANGE_SLACK_SECONDS + 2
|
||||
|
||||
assert expected_min <= result <= expected_max
|
||||
|
||||
Reference in New Issue
Block a user