You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.5 KiB

4 years ago
  1. from django.test.utils import override_settings
  2. from hc.api.models import Channel, Check
  3. from hc.test import BaseTestCase
  4. @override_settings(SIGNAL_CLI_ENABLED=True)
  5. class AddSignalTestCase(BaseTestCase):
  6. def setUp(self):
  7. super().setUp()
  8. self.check = Check.objects.create(project=self.project)
  9. self.url = f"/projects/{self.project.code}/add_signal/"
  10. def test_instructions_work(self):
  11. self.client.login(username="[email protected]", password="password")
  12. r = self.client.get(self.url)
  13. self.assertContains(r, "Add Signal Integration")
  14. self.assertContains(r, "Get a Signal message")
  15. def test_it_creates_channel(self):
  16. form = {
  17. "label": "My Phone",
  18. "phone": "+1234567890",
  19. "down": "true",
  20. "up": "true",
  21. }
  22. self.client.login(username="[email protected]", password="password")
  23. r = self.client.post(self.url, form)
  24. self.assertRedirects(r, self.channels_url)
  25. c = Channel.objects.get()
  26. self.assertEqual(c.kind, "signal")
  27. self.assertEqual(c.phone_number, "+1234567890")
  28. self.assertEqual(c.name, "My Phone")
  29. self.assertTrue(c.signal_notify_down)
  30. self.assertTrue(c.signal_notify_up)
  31. self.assertEqual(c.project, self.project)
  32. # Make sure it calls assign_all_checks
  33. self.assertEqual(c.checks.count(), 1)
  34. @override_settings(SIGNAL_CLI_ENABLED=False)
  35. def test_it_handles_disabled_integration(self):
  36. self.client.login(username="[email protected]", password="password")
  37. r = self.client.get(self.url)
  38. self.assertEqual(r.status_code, 404)
  39. def test_it_requires_rw_access(self):
  40. self.bobs_membership.role = "r"
  41. self.bobs_membership.save()
  42. self.client.login(username="[email protected]", password="password")
  43. r = self.client.get(self.url)
  44. self.assertEqual(r.status_code, 403)
  45. def test_it_handles_down_false_up_true(self):
  46. form = {"phone": "+1234567890", "up": True}
  47. self.client.login(username="[email protected]", password="password")
  48. self.client.post(self.url, form)
  49. c = Channel.objects.get()
  50. self.assertFalse(c.signal_notify_down)
  51. self.assertTrue(c.signal_notify_up)
  52. def test_it_rejects_unchecked_up_and_down(self):
  53. form = {"phone": "+1234567890"}
  54. self.client.login(username="[email protected]", password="password")
  55. r = self.client.post(self.url, form)
  56. self.assertContains(r, "Please select at least one.")