@ -0,0 +1,19 @@ | |||
# Generated by Django 3.0.7 on 2020-07-01 10:07 | |||
from django.db import migrations, models | |||
import django.db.models.deletion | |||
class Migration(migrations.Migration): | |||
dependencies = [ | |||
('api', '0071_check_manual_resume'), | |||
] | |||
operations = [ | |||
migrations.AlterField( | |||
model_name='notification', | |||
name='owner', | |||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Check'), | |||
), | |||
] |
@ -327,14 +327,13 @@ class NotifyTestCase(BaseTestCase): | |||
email = mail.outbox[0] | |||
self.assertEqual(email.to[0], "[email protected]") | |||
def test_it_skips_unverified_email(self): | |||
def test_it_reports_unverified_email(self): | |||
self._setup_data("email", "[email protected]", email_verified=False) | |||
self.channel.notify(self.check) | |||
# If an email is not verified, it should be skipped over | |||
# without logging a notification: | |||
self.assertEqual(Notification.objects.count(), 0) | |||
self.assertEqual(len(mail.outbox), 0) | |||
# If an email is not verified, it should say so in the notification: | |||
n = Notification.objects.get() | |||
self.assertEqual(n.error, "Email not verified") | |||
def test_email_checks_up_down_flags(self): | |||
payload = {"value": "[email protected]", "up": True, "down": False} | |||
@ -57,22 +57,6 @@ class ChannelsTestCase(BaseTestCase): | |||
self.assertEqual(r.status_code, 200) | |||
self.assertContains(r, "(normal priority)") | |||
def test_it_shows_disabled_email(self): | |||
check = Check(project=self.project, status="up") | |||
check.save() | |||
channel = Channel(project=self.project, kind="email") | |||
channel.value = "[email protected]" | |||
channel.save() | |||
n = Notification(owner=check, channel=channel, error="Invalid address") | |||
n.save() | |||
self.client.login(username="[email protected]", password="password") | |||
r = self.client.get(self.channels_url) | |||
self.assertEqual(r.status_code, 200) | |||
self.assertContains(r, "Disabled") | |||
def test_it_shows_unconfirmed_email(self): | |||
channel = Channel(project=self.project, kind="email") | |||
channel.value = "[email protected]" | |||
@ -2,7 +2,7 @@ import json | |||
from unittest.mock import patch | |||
from django.core import mail | |||
from hc.api.models import Channel | |||
from hc.api.models import Channel, Notification | |||
from hc.test import BaseTestCase | |||
@ -31,6 +31,34 @@ class SendTestNotificationTestCase(BaseTestCase): | |||
self.assertTrue("X-Bounce-Url" in email.extra_headers) | |||
self.assertTrue("List-Unsubscribe" in email.extra_headers) | |||
# It should create a notification | |||
n = Notification.objects.get() | |||
self.assertEqual(n.channel, self.channel) | |||
self.assertEqual(n.error, "") | |||
def test_it_clears_channel_last_error(self): | |||
self.channel.last_error = "Something went wrong" | |||
self.channel.save() | |||
self.client.login(username="[email protected]", password="password") | |||
self.client.post(self.url, {}) | |||
self.channel.refresh_from_db() | |||
self.assertEqual(self.channel.last_error, "") | |||
def test_it_sets_channel_last_error(self): | |||
self.channel.email_verified = False | |||
self.channel.save() | |||
self.client.login(username="[email protected]", password="password") | |||
r = self.client.post(self.url, {}, follow=True) | |||
self.assertContains(r, "Could not send a test notification") | |||
self.assertContains(r, "Email not verified") | |||
self.channel.refresh_from_db() | |||
self.assertEqual(self.channel.last_error, "Email not verified") | |||
@patch("hc.api.transports.requests.request") | |||
def test_it_handles_webhooks_with_no_down_url(self, mock_get): | |||
mock_get.return_value.status_code = 200 | |||