Browse Source

Fix assign_all_checks() usage, add tests for it

pull/563/head
Pēteris Caune 3 years ago
parent
commit
c2e00f2105
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
5 changed files with 29 additions and 9 deletions
  1. +6
    -2
      hc/front/tests/test_add_email.py
  2. +6
    -2
      hc/front/tests/test_add_webhook.py
  3. +7
    -2
      hc/front/tests/test_edit_email.py
  4. +7
    -2
      hc/front/tests/test_edit_webhook.py
  5. +3
    -1
      hc/front/views.py

+ 6
- 2
hc/front/tests/test_add_email.py View File

@ -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"}


+ 6
- 2
hc/front/tests/test_add_webhook.py View File

@ -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",


+ 7
- 2
hc/front/tests/test_edit_email.py View File

@ -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"}


+ 7
- 2
hc/front/tests/test_edit_webhook.py View File

@ -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]"


+ 3
- 1
hc/front/views.py View File

@ -1031,7 +1031,9 @@ def webhook_form(request, channel=None, code=None):
channel.value = form.get_value()
channel.save()
channel.assign_all_checks()
if is_new:
channel.assign_all_checks()
return redirect("hc-channels", channel.project.code)
elif is_new:


Loading…
Cancel
Save