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.

60 lines
2.1 KiB

4 years ago
  1. from django.test.utils import override_settings
  2. from hc.api.models import Channel
  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.url = "/projects/%s/add_signal/" % self.project.code
  9. def test_instructions_work(self):
  10. self.client.login(username="[email protected]", password="password")
  11. r = self.client.get(self.url)
  12. self.assertContains(r, "Get a Signal message")
  13. def test_it_creates_channel(self):
  14. form = {
  15. "label": "My Phone",
  16. "phone": "+1234567890",
  17. "down": "true",
  18. "up": "true",
  19. }
  20. self.client.login(username="[email protected]", password="password")
  21. r = self.client.post(self.url, form)
  22. self.assertRedirects(r, self.channels_url)
  23. c = Channel.objects.get()
  24. self.assertEqual(c.kind, "signal")
  25. self.assertEqual(c.phone_number, "+1234567890")
  26. self.assertEqual(c.name, "My Phone")
  27. self.assertTrue(c.signal_notify_down)
  28. self.assertTrue(c.signal_notify_up)
  29. self.assertEqual(c.project, self.project)
  30. def test_it_obeys_up_down_flags(self):
  31. form = {"label": "My Phone", "phone": "+1234567890"}
  32. self.client.login(username="[email protected]", password="password")
  33. r = self.client.post(self.url, form)
  34. self.assertRedirects(r, self.channels_url)
  35. c = Channel.objects.get()
  36. self.assertFalse(c.signal_notify_down)
  37. self.assertFalse(c.signal_notify_up)
  38. @override_settings(SIGNAL_CLI_ENABLED=False)
  39. def test_it_handles_disabled_integration(self):
  40. self.client.login(username="[email protected]", password="password")
  41. r = self.client.get(self.url)
  42. self.assertEqual(r.status_code, 404)
  43. def test_it_requires_rw_access(self):
  44. self.bobs_membership.role = "r"
  45. self.bobs_membership.save()
  46. self.client.login(username="[email protected]", password="password")
  47. r = self.client.get(self.url)
  48. self.assertEqual(r.status_code, 403)