0
0
Fork 0
mirror of https://github.com/healthchecks/healthchecks.git synced 2025-04-08 06:30:05 +00:00

Update email integration to use Ping.get_kind_display()

This commit is contained in:
Pēteris Caune 2023-10-23 11:39:37 +03:00
parent 6c7f5881a7
commit c9540f8ddd
No known key found for this signature in database
GPG key ID: E28D7679E9A9EDE2
2 changed files with 16 additions and 16 deletions
hc/api/tests
templates/emails

View file

@ -180,7 +180,7 @@ class NotifyEmailTestCase(BaseTestCase):
self.assertNotIn("Projects Overview", email.body)
self.assertNotIn("Projects Overview", html)
def test_email_transport_handles_json_value(self) -> None:
def test_it_handles_json_value(self) -> None:
payload = {"value": "alice@example.org", "up": True, "down": True}
self.channel.value = json.dumps(payload)
self.channel.save()
@ -203,7 +203,7 @@ class NotifyEmailTestCase(BaseTestCase):
n = Notification.objects.get()
self.assertEqual(n.error, "Email not verified")
def test_email_checks_up_down_flags(self) -> None:
def test_it_checks_up_down_flags(self) -> None:
payload = {"value": "alice@example.org", "up": True, "down": False}
self.channel.value = json.dumps(payload)
self.channel.save()
@ -214,7 +214,7 @@ class NotifyEmailTestCase(BaseTestCase):
self.assertEqual(Notification.objects.count(), 0)
self.assertEqual(len(mail.outbox), 0)
def test_email_handles_amperstand(self) -> None:
def test_it_handles_amperstand(self) -> None:
self.check.name = "Foo & Bar"
self.check.save()
@ -263,6 +263,18 @@ class NotifyEmailTestCase(BaseTestCase):
self.assertIn("Log", email.body)
self.assertIn("Log", html)
def test_it_handles_last_ping_exitstatus(self) -> None:
self.ping.kind = "fail"
self.ping.exitstatus = 123
self.ping.save()
self.channel.notify(self.check)
email = mail.outbox[0]
html = self.get_html(email)
self.assertIn("Exit status 123", email.body)
self.assertIn("Exit status 123", html)
@override_settings(EMAIL_MAIL_FROM_TMPL="%s@bounces.example.org")
def test_it_sets_custom_mail_from(self) -> None:
self.channel.notify(self.check)

View file

@ -39,19 +39,7 @@
{% if ping %}
{% line %}Last ping: {{ ping.created|naturaltime }}{% if ping.remote_addr %}, from {{ ping.remote_addr }}{% endif %}{% endline %}
{% if ping.kind == "ign" %}
{% line %}Last ping type: Ignored{% endline %}
{% elif ping.exitstatus >= 0 %}
{% line %}Last ping type: Exit status {{ ping.exitstatus }}{% endline %}
{% elif ping.kind == "fail" %}
{% line %}Last ping type: Failure{% endline %}
{% elif ping.kind == "start" %}
{% line %}Last ping type: Started{% endline %}
{% elif ping.kind == "log" %}
{% line %}Last ping type: Log{% endline %}
{% else %}
{% line %}Last ping type: Success{% endline %}
{% endif %}
{% line %}Last ping type: {{ ping.get_kind_display }}{% endline %}
{% if ping.has_body %}
{% line %}{% endline %}