|
@ -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", "[email protected]", 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") |
|
|