mirror of
https://github.com/healthchecks/healthchecks.git
synced 2025-03-15 04:34:49 +00:00
Fix the email integration to use Flip.new_status
This commit is contained in:
parent
28fdfd1362
commit
8372abf019
5 changed files with 14 additions and 10 deletions
hc/api
templates/emails
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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>
|
||||
|
||||
|
|
|
@ -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 %}
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
{{ check.status|upper }} | {{ check.name_then_code|safe }}
|
||||
{{ flip.new_status|upper }} | {{ check.name_then_code|safe }}
|
||||
|
||||
|
|
Loading…
Reference in a new issue