diff --git a/hc/api/tests/test_notify_email.py b/hc/api/tests/test_notify_email.py index ea22c0cf..1624a9d8 100644 --- a/hc/api/tests/test_notify_email.py +++ b/hc/api/tests/test_notify_email.py @@ -24,7 +24,9 @@ class NotifyEmailTestCase(BaseTestCase): self.check.name = "Daily Backup" self.check.desc = "Line 1\nLine2" self.check.tags = "foo bar" - self.check.status = "down" + # Transport classes should use flip.new_status, + # so the status "paused" should not appear anywhere + self.check.status = "paused" self.check.last_ping = now() - td(minutes=61) self.check.n_pings = 112233 self.check.save() @@ -64,6 +66,7 @@ class NotifyEmailTestCase(BaseTestCase): self.assertEqual(len(mail.outbox), 1) email = mail.outbox[0] + self.assertEqual(email.subject, "DOWN | Daily Backup") self.assertEqual(email.to[0], "alice@example.org") self.assertNotIn("X-Bounce-ID", email.extra_headers) self.assertTrue("List-Unsubscribe" in email.extra_headers) @@ -71,9 +74,9 @@ class NotifyEmailTestCase(BaseTestCase): self.assertTrue(email.extra_headers["Message-ID"].endswith("@example.org>")) html = self.get_html(email) - # Name - self.assertIn("Daily Backup", email.body) - self.assertIn("Daily Backup", html) + # Message + self.assertIn("""The check "Daily Backup" has gone down.""", email.body) + self.assertIn(""""Daily Backup" is DOWN.""", html) # Description self.assertIn("Line 1\nLine2", email.body) diff --git a/hc/api/transports.py b/hc/api/transports.py index e6ffc895..9c8e16e7 100644 --- a/hc/api/transports.py +++ b/hc/api/transports.py @@ -144,7 +144,7 @@ class RemovedTransport(Transport): class Email(Transport): - def notify(self, check: Check, notification: Notification) -> None: + def notify_flip(self, flip: Flip, notification: Notification) -> None: if not self.channel.email_verified: raise TransportError("Email not verified") @@ -166,7 +166,7 @@ class Email(Transport): except Profile.DoesNotExist: projects = None - ping = self.last_ping(check) + ping = self.last_ping(flip.owner) body = get_ping_body(ping) subject = None if ping is not None and ping.scheme == "email" and body: @@ -175,7 +175,8 @@ class Email(Transport): subject = parsed.get("subject", "") ctx = { - "check": check, + "flip": flip, + "check": flip.owner, "ping": ping, "body": body, "subject": subject, diff --git a/templates/emails/alert-body-html.html b/templates/emails/alert-body-html.html index 0b56c9bc..060a6a62 100644 --- a/templates/emails/alert-body-html.html +++ b/templates/emails/alert-body-html.html @@ -2,7 +2,7 @@ {% load hc_extras humanize %} <p> - "{{ check.name_then_code }}" is {{ check.status|upper }}. + "{{ check.name_then_code }}" is {{ flip.new_status|upper }}. <a href="{{ check.cloaked_url }}">View on {% site_name %}…</a> </p> diff --git a/templates/emails/alert-body-text.html b/templates/emails/alert-body-text.html index 21743bcb..a78851be 100644 --- a/templates/emails/alert-body-text.html +++ b/templates/emails/alert-body-text.html @@ -1,6 +1,6 @@ {% load hc_extras humanize linemode %}{% linemode %} -{% line %}The check "{{ check.name_then_code|safe }}" has gone {{ check.status }}.{% endline %} +{% line %}The check "{{ check.name_then_code|safe }}" has gone {{ flip.new_status }}.{% endline %} {% line %}{% endline %} {% line %}View on {% site_name %}:{% endline %} diff --git a/templates/emails/alert-subject.html b/templates/emails/alert-subject.html index a4ea9b14..60e77f1b 100644 --- a/templates/emails/alert-subject.html +++ b/templates/emails/alert-subject.html @@ -1,2 +1,2 @@ -{{ check.status|upper }} | {{ check.name_then_code|safe }} +{{ flip.new_status|upper }} | {{ check.name_then_code|safe }}