Improved code quality with more idiomatic Python patterns.
CD / Build (push) Successful in 7s
CI / Formatting (push) Successful in 5s
CI / Linting (push) Successful in 5s
CI / Tests (push) Successful in 11s
CI / Type Checking (push) Successful in 20s
CI / Spelling (push) Successful in 32s

This commit is contained in:
2026-03-24 11:02:13 -04:00
parent 653c27c97c
commit 295a8c90a9
10 changed files with 201 additions and 292 deletions
+2 -1
View File
@@ -22,7 +22,8 @@ from typing import TYPE_CHECKING
import pytest
from aioresponses import aioresponses
from owncastsentry.health_checker import HealthChecker, HealthStatus, UpdateResult
from owncastsentry.health_checker import HealthChecker, HealthStatus
from owncastsentry.models import UpdateResult
from owncastsentry.owncast_client import OwncastClient
if TYPE_CHECKING:
+3 -3
View File
@@ -62,7 +62,7 @@ class TestCanNotify:
service = _make_service(
client=_StubMatrixClient(), subscription_repo=subscription_repo
)
service.notification_timers_cache["example.com"] = time.time()
service.notification_timers_cache["example.com"] = time.monotonic()
assert service._can_notify("example.com") is False
def test_after_cooldown_allowed(
@@ -74,7 +74,7 @@ class TestCanNotify:
)
# Subtract an extra second to ensure the cooldown has fully elapsed
service.notification_timers_cache["example.com"] = (
time.time() - SECONDS_BETWEEN_NOTIFICATIONS - 1
time.monotonic() - SECONDS_BETWEEN_NOTIFICATIONS - 1
)
assert service._can_notify("example.com") is True
@@ -253,7 +253,7 @@ class TestNotifyStreamLive:
"""Skip sending when the domain is within the rate-limit cooldown."""
client = _StubMatrixClient()
service = _make_service(client=client, subscription_repo=subscription_repo)
service.notification_timers_cache["example.com"] = time.time()
service.notification_timers_cache["example.com"] = time.monotonic()
await stream_repo.create("example.com")
await subscription_repo.add("example.com", "!room1:matrix.org")
+7 -7
View File
@@ -337,7 +337,7 @@ class TestUpdateStreamBriefOffline:
)
# Recently offline (within cooldown)
monitor.offline_timer_cache["brief.com"] = time.time() - 60
monitor.offline_timer_cache["brief.com"] = time.monotonic() - 60
result = await monitor.update_stream("brief.com")
assert result is True
@@ -375,7 +375,7 @@ class TestUpdateStreamBriefOffline:
)
# Recently offline (within cooldown)
monitor.offline_timer_cache["brief.com"] = time.time() - 60
monitor.offline_timer_cache["brief.com"] = time.monotonic() - 60
result = await monitor.update_stream("brief.com")
assert result is True
@@ -424,7 +424,7 @@ class TestUpdateStreamTitleChange:
monitor.offline_timer_cache["title.com"] = 0
# Subtract an extra second to ensure the cooldown has fully elapsed
notification_service.notification_timers_cache["title.com"] = (
time.time() - SECONDS_BETWEEN_NOTIFICATIONS - 1
time.monotonic() - SECONDS_BETWEEN_NOTIFICATIONS - 1
)
result = await monitor.update_stream("title.com")
@@ -473,7 +473,7 @@ class TestUpdateStreamTitleChange:
monitor.offline_timer_cache["title.com"] = 0
# Subtract an extra second to ensure the cooldown has fully elapsed
notification_service.notification_timers_cache["title.com"] = (
time.time() - SECONDS_BETWEEN_NOTIFICATIONS - 1
time.monotonic() - SECONDS_BETWEEN_NOTIFICATIONS - 1
)
result = await monitor.update_stream("title.com")
@@ -518,7 +518,7 @@ class TestUpdateStreamTitleChange:
# Offline timer is MORE recent than last notification,
# and both are old enough to pass rate limiting
now = time.time()
now = time.monotonic()
monitor.offline_timer_cache["title.com"] = (
now - SECONDS_BETWEEN_NOTIFICATIONS - 100
)
@@ -571,9 +571,9 @@ class TestUpdateStreamGoesOffline:
)
monitor.offline_timer_cache["offline.com"] = 0
before = time.time()
before = time.monotonic()
result = await monitor.update_stream("offline.com")
after = time.time()
after = time.monotonic()
assert result is True
assert before <= monitor.offline_timer_cache["offline.com"] <= after