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.

62 lines
2.1 KiB

  1. import json
  2. from django.test.utils import override_settings
  3. from hc.api.models import Channel, Check
  4. from hc.test import BaseTestCase
  5. @override_settings(SIGNAL_CLI_ENABLED=True)
  6. class EditSignalTestCase(BaseTestCase):
  7. def setUp(self):
  8. super().setUp()
  9. self.check = Check.objects.create(project=self.project)
  10. self.channel = Channel(project=self.project, kind="signal")
  11. self.channel.value = json.dumps(
  12. {"value": "+12345678", "up": True, "down": True}
  13. )
  14. self.channel.save()
  15. self.url = f"/integrations/{self.channel.code}/edit/"
  16. def test_instructions_work(self):
  17. self.client.login(username="[email protected]", password="password")
  18. r = self.client.get(self.url)
  19. self.assertContains(r, "Signal Settings")
  20. self.assertContains(r, "Get a Signal message")
  21. self.assertContains(r, "+12345678")
  22. def test_it_updates_channel(self):
  23. form = {
  24. "label": "My Phone",
  25. "phone": "+1234567890",
  26. "down": "true",
  27. "up": "false",
  28. }
  29. self.client.login(username="[email protected]", password="password")
  30. r = self.client.post(self.url, form)
  31. self.assertRedirects(r, self.channels_url)
  32. self.channel.refresh_from_db()
  33. self.assertEqual(self.channel.phone_number, "+1234567890")
  34. self.assertEqual(self.channel.name, "My Phone")
  35. self.assertTrue(self.channel.signal_notify_down)
  36. self.assertFalse(self.channel.signal_notify_up)
  37. # Make sure it does not call assign_all_checks
  38. self.assertFalse(self.channel.checks.exists())
  39. @override_settings(SIGNAL_CLI_ENABLED=False)
  40. def test_it_handles_disabled_integration(self):
  41. self.client.login(username="[email protected]", password="password")
  42. r = self.client.get(self.url)
  43. self.assertEqual(r.status_code, 404)
  44. def test_it_requires_rw_access(self):
  45. self.bobs_membership.role = "r"
  46. self.bobs_membership.save()
  47. self.client.login(username="[email protected]", password="password")
  48. r = self.client.get(self.url)
  49. self.assertEqual(r.status_code, 403)