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.

57 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(TWILIO_ACCOUNT="foo", TWILIO_AUTH="foo", TWILIO_FROM="123")
  6. class EditSmsTestCase(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="sms")
  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, "SMS Settings")
  20. self.assertContains(r, "Get a SMS message")
  21. self.assertContains(r, "+12345678")
  22. def test_it_updates_channel(self):
  23. form = {"label": "My Phone", "phone": "+1234567890", "down": True}
  24. self.client.login(username="[email protected]", password="password")
  25. r = self.client.post(self.url, form)
  26. self.assertRedirects(r, self.channels_url)
  27. self.channel.refresh_from_db()
  28. self.assertEqual(self.channel.phone_number, "+1234567890")
  29. self.assertEqual(self.channel.name, "My Phone")
  30. self.assertTrue(self.channel.sms_notify_down)
  31. self.assertFalse(self.channel.sms_notify_up)
  32. # Make sure it does not call assign_all_checks
  33. self.assertFalse(self.channel.checks.exists())
  34. @override_settings(TWILIO_AUTH=None)
  35. def test_it_requires_credentials(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)