0
0
Fork 0
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:
Pēteris Caune 2024-04-12 14:05:44 +03:00
parent 28fdfd1362
commit 8372abf019
No known key found for this signature in database
GPG key ID: E28D7679E9A9EDE2
5 changed files with 14 additions and 10 deletions

View file

@ -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)

View file

@ -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,

View file

@ -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 %}&hellip;</a>
</p>

View file

@ -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 %}

View file

@ -1,2 +1,2 @@
{{ check.status|upper }} | {{ check.name_then_code|safe }}
{{ flip.new_status|upper }} | {{ check.name_then_code|safe }}