Skip to content

Commit

Permalink
Fix type warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
cuu508 committed Sep 2, 2023
1 parent aecdbfb commit 23eadc5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion hc/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def send_call_limit_notice(self):

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)
Expand Down
10 changes: 9 additions & 1 deletion hc/api/tests/test_ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def test_it_works(self) -> None:

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)

Expand Down Expand Up @@ -65,6 +66,7 @@ def test_post_works(self) -> None:

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:
Expand Down Expand Up @@ -154,7 +156,7 @@ def test_it_reads_forwarded_protocol(self) -> None:

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 ..."
Expand Down Expand Up @@ -222,6 +224,7 @@ def test_it_sets_last_duration(self) -> None:
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:
Expand Down Expand Up @@ -249,6 +252,7 @@ def test_it_clears_last_ping_and_sets_last_duration_if_rid_matches(self) -> None

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:
Expand Down Expand Up @@ -297,6 +301,7 @@ def test_it_chops_long_body(self) -> None:

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)
Expand All @@ -305,6 +310,7 @@ def test_it_allows_unlimited_body(self) -> None:
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:
Expand Down Expand Up @@ -355,6 +361,7 @@ def test_it_accepts_bad_unicode(self) -> None:

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)
Expand Down Expand Up @@ -383,6 +390,7 @@ def test_log_endpoint_works(self) -> None:

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())
Expand Down
3 changes: 2 additions & 1 deletion hc/api/tests/test_ping_by_slug.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def test_post_works(self) -> None:

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:
Expand All @@ -38,7 +39,7 @@ def test_head_works(self) -> None:

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")
Expand Down
13 changes: 8 additions & 5 deletions hc/front/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 23eadc5

Please sign in to comment.