forked from GithubBackups/healthchecks
Upgrade link in alert emails.
This commit is contained in:
parent
84ecac633c
commit
8ba981cb52
@ -1,6 +1,7 @@
|
||||
import json
|
||||
|
||||
from django.core import mail
|
||||
from django.test import override_settings
|
||||
from hc.api.models import Channel, Check, Notification
|
||||
from hc.test import BaseTestCase
|
||||
from mock import patch
|
||||
@ -12,6 +13,7 @@ class NotifyTestCase(BaseTestCase):
|
||||
def _setup_data(self, kind, value, status="down", email_verified=True):
|
||||
self.check = Check()
|
||||
self.check.status = status
|
||||
self.check.user = self.alice
|
||||
self.check.save()
|
||||
|
||||
self.channel = Channel(user=self.alice)
|
||||
@ -127,6 +129,23 @@ class NotifyTestCase(BaseTestCase):
|
||||
self.assertEqual(n.error, "Email not verified")
|
||||
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")
|
||||
def test_pd(self, mock_post):
|
||||
self._setup_data("pd", "123")
|
||||
|
@ -46,10 +46,16 @@ class Email(Transport):
|
||||
if not self.channel.email_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 = {
|
||||
"check": check,
|
||||
"checks": self.checks(),
|
||||
"now": timezone.now()
|
||||
"now": timezone.now(),
|
||||
"show_upgrade_note": show_upgrade_note
|
||||
}
|
||||
emails.alert(self.channel.value, ctx)
|
||||
|
||||
|
@ -13,5 +13,12 @@
|
||||
|
||||
{% 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>
|
||||
{% endblock %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user