@ -3,14 +3,15 @@ import json | |||
from django.core import mail | |||
from django.test.utils import override_settings | |||
from hc.api.models import Channel | |||
from hc.api.models import Channel, Check | |||
from hc.test import BaseTestCase | |||
class AddEmailTestCase(BaseTestCase): | |||
def setUp(self): | |||
super().setUp() | |||
self.url = "/projects/%s/add_email/" % self.project.code | |||
self.check = Check.objects.create(project=self.project) | |||
self.url = f"/projects/{self.project.code}/add_email/" | |||
def test_instructions_work(self): | |||
self.client.login(username="[email protected]", password="password") | |||
@ -41,6 +42,9 @@ class AddEmailTestCase(BaseTestCase): | |||
# Make sure we're sending to an email address, not a JSON string: | |||
self.assertEqual(email.to[0], "[email protected]") | |||
# Make sure it calls assign_all_checks | |||
self.assertEqual(c.checks.count(), 1) | |||
def test_team_access_works(self): | |||
form = {"value": "[email protected]", "down": "true", "up": "true"} | |||
@ -1,12 +1,13 @@ | |||
from django.test.utils import override_settings | |||
from hc.api.models import Channel | |||
from hc.api.models import Channel, Check | |||
from hc.test import BaseTestCase | |||
class AddWebhookTestCase(BaseTestCase): | |||
def setUp(self): | |||
super().setUp() | |||
self.url = "/projects/%s/add_webhook/" % self.project.code | |||
self.check = Check.objects.create(project=self.project) | |||
self.url = f"/projects/{self.project.code}/add_webhook/" | |||
def test_instructions_work(self): | |||
self.client.login(username="[email protected]", password="password") | |||
@ -29,6 +30,9 @@ class AddWebhookTestCase(BaseTestCase): | |||
c = Channel.objects.get() | |||
self.assertEqual(c.name, "Call foo.com") | |||
# Make sure it calls assign_all_checks | |||
self.assertEqual(c.checks.count(), 1) | |||
def test_it_adds_two_webhook_urls_and_redirects(self): | |||
form = { | |||
"method_down": "GET", | |||
@ -3,7 +3,7 @@ import json | |||
from django.core import mail | |||
from django.test.utils import override_settings | |||
from hc.api.models import Channel | |||
from hc.api.models import Channel, Check | |||
from hc.test import BaseTestCase | |||
@ -11,6 +11,8 @@ class EditEmailTestCase(BaseTestCase): | |||
def setUp(self): | |||
super().setUp() | |||
self.check = Check.objects.create(project=self.project) | |||
self.channel = Channel(project=self.project, kind="email") | |||
self.channel.value = json.dumps( | |||
{"value": "[email protected]", "up": True, "down": True} | |||
@ -18,7 +20,7 @@ class EditEmailTestCase(BaseTestCase): | |||
self.channel.email_verified = True | |||
self.channel.save() | |||
self.url = "/integrations/%s/edit/" % self.channel.code | |||
self.url = f"/integrations/{self.channel.code}/edit/" | |||
def test_it_shows_form(self): | |||
self.client.login(username="[email protected]", password="password") | |||
@ -44,6 +46,9 @@ class EditEmailTestCase(BaseTestCase): | |||
self.assertTrue(email.subject.startswith("Verify email address on")) | |||
self.assertEqual(email.to[0], "[email protected]") | |||
# Make sure it does not call assign_all_checks | |||
self.assertFalse(self.channel.checks.exists()) | |||
def test_it_skips_verification_if_email_unchanged(self): | |||
form = {"value": "[email protected]", "down": "false", "up": "true"} | |||
@ -1,6 +1,6 @@ | |||
import json | |||
from hc.api.models import Channel | |||
from hc.api.models import Channel, Check | |||
from hc.test import BaseTestCase | |||
@ -8,6 +8,8 @@ class EditWebhookTestCase(BaseTestCase): | |||
def setUp(self): | |||
super().setUp() | |||
self.check = Check.objects.create(project=self.project) | |||
definition = { | |||
"method_down": "GET", | |||
"url_down": "http://example.org/down", | |||
@ -24,7 +26,7 @@ class EditWebhookTestCase(BaseTestCase): | |||
self.channel.value = json.dumps(definition) | |||
self.channel.save() | |||
self.url = "/integrations/%s/edit/" % self.channel.code | |||
self.url = f"/integrations/{self.channel.code}/edit/" | |||
def test_it_shows_form(self): | |||
self.client.login(username="[email protected]", password="password") | |||
@ -74,6 +76,9 @@ class EditWebhookTestCase(BaseTestCase): | |||
self.assertEqual(up_spec["body"], "going up") | |||
self.assertEqual(up_spec["headers"], {"Content-Type": "text/plain"}) | |||
# Make sure it does not call assign_all_checks | |||
self.assertFalse(self.channel.checks.exists()) | |||
def test_it_requires_kind_webhook(self): | |||
self.channel.kind = "sms" | |||
self.channel.value = "[email protected]" | |||