mirror of
https://github.com/healthchecks/healthchecks.git
synced 2025-04-08 06:30:05 +00:00
Fix type warnings
This commit is contained in:
parent
aecdbfb017
commit
23eadc5e64
4 changed files with 20 additions and 8 deletions
hc
|
@ -181,7 +181,7 @@ class Profile(models.Model):
|
|||
|
||||
emails.call_limit(self.user.email, ctx)
|
||||
|
||||
def projects(self) -> list["Project"]:
|
||||
def projects(self):
|
||||
"""Return a queryset of all projects we have access to."""
|
||||
|
||||
is_owner = Q(owner_id=self.user_id)
|
||||
|
|
|
@ -29,6 +29,7 @@ class PingTestCase(BaseTestCase):
|
|||
|
||||
self.check.refresh_from_db()
|
||||
self.assertEqual(self.check.status, "up")
|
||||
assert self.check.last_ping
|
||||
expected_aa = self.check.last_ping + td(days=1, hours=1)
|
||||
self.assertEqual(self.check.alert_after, expected_aa)
|
||||
|
||||
|
@ -65,6 +66,7 @@ class PingTestCase(BaseTestCase):
|
|||
|
||||
ping = Ping.objects.get()
|
||||
self.assertEqual(ping.method, "POST")
|
||||
assert ping.body_raw
|
||||
self.assertEqual(bytes(ping.body_raw), b"hello world")
|
||||
|
||||
def test_head_works(self) -> None:
|
||||
|
@ -154,7 +156,7 @@ class PingTestCase(BaseTestCase):
|
|||
|
||||
def test_it_never_caches(self) -> None:
|
||||
r = self.client.get(self.url)
|
||||
assert "no-cache" in r.get("Cache-Control")
|
||||
assert "no-cache" in r["Cache-Control"]
|
||||
|
||||
def test_it_updates_confirmation_flag(self) -> None:
|
||||
payload = "Please Confirm ..."
|
||||
|
@ -222,6 +224,7 @@ class PingTestCase(BaseTestCase):
|
|||
self.assertEqual(r.status_code, 200)
|
||||
|
||||
self.check.refresh_from_db()
|
||||
assert self.check.last_duration
|
||||
self.assertTrue(self.check.last_duration.total_seconds() >= 10)
|
||||
|
||||
def test_it_does_not_update_last_ping_on_rid_mismatch(self) -> None:
|
||||
|
@ -249,6 +252,7 @@ class PingTestCase(BaseTestCase):
|
|||
|
||||
self.check.refresh_from_db()
|
||||
self.assertIsNone(self.check.last_start)
|
||||
assert self.check.last_duration
|
||||
self.assertTrue(self.check.last_duration.total_seconds() >= 10)
|
||||
|
||||
def test_it_clears_last_ping_if_rid_is_absent(self) -> None:
|
||||
|
@ -297,6 +301,7 @@ class PingTestCase(BaseTestCase):
|
|||
|
||||
ping = Ping.objects.get()
|
||||
self.assertEqual(ping.method, "POST")
|
||||
assert ping.body_raw
|
||||
self.assertEqual(bytes(ping.body_raw), b"hello")
|
||||
|
||||
@override_settings(PING_BODY_LIMIT=None)
|
||||
|
@ -305,6 +310,7 @@ class PingTestCase(BaseTestCase):
|
|||
self.assertNotIn("Ping-Body-Limit", r.headers)
|
||||
|
||||
ping = Ping.objects.get()
|
||||
assert ping.body_raw
|
||||
self.assertEqual(len(ping.body_raw), 20000)
|
||||
|
||||
def test_it_handles_manual_resume_flag(self) -> None:
|
||||
|
@ -355,6 +361,7 @@ class PingTestCase(BaseTestCase):
|
|||
|
||||
ping = Ping.objects.get()
|
||||
self.assertEqual(ping.method, "POST")
|
||||
assert ping.body_raw
|
||||
self.assertEqual(bytes(ping.body_raw), b"Hello \xe9 World")
|
||||
|
||||
@override_settings(S3_BUCKET="test-bucket", PING_BODY_LIMIT=None)
|
||||
|
@ -383,6 +390,7 @@ class PingTestCase(BaseTestCase):
|
|||
|
||||
ping = Ping.objects.get()
|
||||
self.assertEqual(ping.kind, "log")
|
||||
assert ping.body_raw
|
||||
self.assertEqual(bytes(ping.body_raw), b"hello")
|
||||
|
||||
self.assertFalse(Flip.objects.exists())
|
||||
|
|
|
@ -28,6 +28,7 @@ class PingBySlugTestCase(BaseTestCase):
|
|||
|
||||
ping = Ping.objects.get()
|
||||
self.assertEqual(ping.method, "POST")
|
||||
assert ping.body_raw
|
||||
self.assertEqual(bytes(ping.body_raw), b"hello world")
|
||||
|
||||
def test_head_works(self) -> None:
|
||||
|
@ -38,7 +39,7 @@ class PingBySlugTestCase(BaseTestCase):
|
|||
|
||||
def test_it_never_caches(self) -> None:
|
||||
r = self.client.get(self.url)
|
||||
assert "no-cache" in r.get("Cache-Control")
|
||||
assert "no-cache" in r["Cache-Control"]
|
||||
|
||||
def test_fail_endpoint_works(self) -> None:
|
||||
r = self.client.get(self.url + "/fail")
|
||||
|
|
|
@ -804,17 +804,20 @@ def _get_events(check: Check, page_limit: int, start=None, end=None):
|
|||
for ping in pings:
|
||||
ping.duration = None
|
||||
|
||||
alerts = Notification.objects.select_related("channel")
|
||||
alerts = alerts.filter(owner=check, check_status="down")
|
||||
alerts: list[Notification]
|
||||
q = Notification.objects.select_related("channel")
|
||||
q = q.filter(owner=check, check_status="down")
|
||||
if start and end:
|
||||
alerts = alerts.filter(created__gte=start, created__lte=end)
|
||||
q = q.filter(created__gte=start, created__lte=end)
|
||||
alerts = list(q)
|
||||
elif len(pings):
|
||||
cutoff = pings[-1].created
|
||||
alerts = alerts.filter(created__gt=cutoff)
|
||||
q = q.filter(created__gt=cutoff)
|
||||
alerts = list(q)
|
||||
else:
|
||||
alerts = []
|
||||
|
||||
events = pings + list(alerts)
|
||||
events = pings + alerts
|
||||
events.sort(key=lambda el: el.created, reverse=True)
|
||||
return events
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue