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.

70 lines
2.4 KiB

  1. from django.test.utils import override_settings
  2. from hc.api.models import Channel
  3. from hc.test import BaseTestCase
  4. TEST_CREDENTIALS = {
  5. "TWILIO_ACCOUNT": "foo",
  6. "TWILIO_AUTH": "foo",
  7. "TWILIO_FROM": "123",
  8. "TWILIO_USE_WHATSAPP": True,
  9. }
  10. @override_settings(**TEST_CREDENTIALS)
  11. class AddWhatsAppTestCase(BaseTestCase):
  12. url = "/integrations/add_whatsapp/"
  13. def test_instructions_work(self):
  14. self.client.login(username="[email protected]", password="password")
  15. r = self.client.get(self.url)
  16. self.assertContains(r, "Get a WhatsApp message")
  17. @override_settings(USE_PAYMENTS=True)
  18. def test_it_warns_about_limits(self):
  19. self.profile.sms_limit = 0
  20. self.profile.save()
  21. self.client.login(username="[email protected]", password="password")
  22. r = self.client.get(self.url)
  23. self.assertContains(r, "upgrade to a")
  24. def test_it_creates_channel(self):
  25. form = {
  26. "label": "My Phone",
  27. "value": "+1234567890",
  28. "down": "true",
  29. "up": "true",
  30. }
  31. self.client.login(username="[email protected]", password="password")
  32. r = self.client.post(self.url, form)
  33. self.assertRedirects(r, "/integrations/")
  34. c = Channel.objects.get()
  35. self.assertEqual(c.kind, "whatsapp")
  36. self.assertEqual(c.sms_number, "+1234567890")
  37. self.assertEqual(c.name, "My Phone")
  38. self.assertTrue(c.whatsapp_notify_down)
  39. self.assertTrue(c.whatsapp_notify_up)
  40. self.assertEqual(c.project, self.project)
  41. def test_it_obeys_up_down_flags(self):
  42. form = {"label": "My Phone", "value": "+1234567890"}
  43. self.client.login(username="[email protected]", password="password")
  44. r = self.client.post(self.url, form)
  45. self.assertRedirects(r, "/integrations/")
  46. c = Channel.objects.get()
  47. self.assertEqual(c.kind, "whatsapp")
  48. self.assertEqual(c.sms_number, "+1234567890")
  49. self.assertEqual(c.name, "My Phone")
  50. self.assertFalse(c.whatsapp_notify_down)
  51. self.assertFalse(c.whatsapp_notify_up)
  52. self.assertEqual(c.project, self.project)
  53. @override_settings(TWILIO_USE_WHATSAPP=False)
  54. def test_it_obeys_use_whatsapp_flag(self):
  55. self.client.login(username="[email protected]", password="password")
  56. r = self.client.get(self.url)
  57. self.assertEqual(r.status_code, 404)