forked from GithubBackups/healthchecks
Upgrade link in alert emails.
This commit is contained in:
parent
84ecac633c
commit
8ba981cb52
@ -1,6 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from django.core import mail
|
from django.core import mail
|
||||||
|
from django.test import override_settings
|
||||||
from hc.api.models import Channel, Check, Notification
|
from hc.api.models import Channel, Check, Notification
|
||||||
from hc.test import BaseTestCase
|
from hc.test import BaseTestCase
|
||||||
from mock import patch
|
from mock import patch
|
||||||
@ -12,6 +13,7 @@ class NotifyTestCase(BaseTestCase):
|
|||||||
def _setup_data(self, kind, value, status="down", email_verified=True):
|
def _setup_data(self, kind, value, status="down", email_verified=True):
|
||||||
self.check = Check()
|
self.check = Check()
|
||||||
self.check.status = status
|
self.check.status = status
|
||||||
|
self.check.user = self.alice
|
||||||
self.check.save()
|
self.check.save()
|
||||||
|
|
||||||
self.channel = Channel(user=self.alice)
|
self.channel = Channel(user=self.alice)
|
||||||
@ -127,6 +129,23 @@ class NotifyTestCase(BaseTestCase):
|
|||||||
self.assertEqual(n.error, "Email not verified")
|
self.assertEqual(n.error, "Email not verified")
|
||||||
self.assertEqual(len(mail.outbox), 0)
|
self.assertEqual(len(mail.outbox), 0)
|
||||||
|
|
||||||
|
@override_settings(USE_PAYMENTS=True)
|
||||||
|
def test_email_contains_upgrade_notice(self):
|
||||||
|
self._setup_data("email", "alice@example.org", status="up")
|
||||||
|
self.profile.team_access_allowed = False
|
||||||
|
self.profile.save()
|
||||||
|
|
||||||
|
self.channel.notify(self.check)
|
||||||
|
|
||||||
|
n = Notification.objects.get()
|
||||||
|
self.assertEqual(n.error, "")
|
||||||
|
|
||||||
|
# Check is up, payments are enabled, and the user does not have team
|
||||||
|
# access: the email should contain upgrade note
|
||||||
|
message = mail.outbox[0]
|
||||||
|
html, _ = message.alternatives[0]
|
||||||
|
assert "/pricing/" in html
|
||||||
|
|
||||||
@patch("hc.api.transports.requests.request")
|
@patch("hc.api.transports.requests.request")
|
||||||
def test_pd(self, mock_post):
|
def test_pd(self, mock_post):
|
||||||
self._setup_data("pd", "123")
|
self._setup_data("pd", "123")
|
||||||
|
@ -46,10 +46,16 @@ class Email(Transport):
|
|||||||
if not self.channel.email_verified:
|
if not self.channel.email_verified:
|
||||||
return "Email not verified"
|
return "Email not verified"
|
||||||
|
|
||||||
|
show_upgrade_note = False
|
||||||
|
if settings.USE_PAYMENTS and check.status == "up":
|
||||||
|
if not check.user.profile.team_access_allowed:
|
||||||
|
show_upgrade_note = True
|
||||||
|
|
||||||
ctx = {
|
ctx = {
|
||||||
"check": check,
|
"check": check,
|
||||||
"checks": self.checks(),
|
"checks": self.checks(),
|
||||||
"now": timezone.now()
|
"now": timezone.now(),
|
||||||
|
"show_upgrade_note": show_upgrade_note
|
||||||
}
|
}
|
||||||
emails.alert(self.channel.value, ctx)
|
emails.alert(self.channel.value, ctx)
|
||||||
|
|
||||||
|
@ -13,5 +13,12 @@
|
|||||||
|
|
||||||
{% include "emails/summary-html.html" %}
|
{% include "emails/summary-html.html" %}
|
||||||
|
|
||||||
|
{% if show_upgrade_note %}
|
||||||
|
<p><strong>P.S.</strong>
|
||||||
|
Find this service useful? Support it by upgrading to
|
||||||
|
a <a href="https://healthchecks.io/pricing/">premium account</a>!
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<p>Thanks,<br>The Healthchecks<span>.</span>io Team</p>
|
<p>Thanks,<br>The Healthchecks<span>.</span>io Team</p>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user