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.

72 lines
2.5 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. def setUp(self):
  13. super(AddWhatsAppTestCase, self).setUp()
  14. self.url = "/projects/%s/add_whatsapp/" % self.project.code
  15. def test_instructions_work(self):
  16. self.client.login(username="[email protected]", password="password")
  17. r = self.client.get(self.url)
  18. self.assertContains(r, "Get a WhatsApp message")
  19. @override_settings(USE_PAYMENTS=True)
  20. def test_it_warns_about_limits(self):
  21. self.profile.sms_limit = 0
  22. self.profile.save()
  23. self.client.login(username="[email protected]", password="password")
  24. r = self.client.get(self.url)
  25. self.assertContains(r, "upgrade to a")
  26. def test_it_creates_channel(self):
  27. form = {
  28. "label": "My Phone",
  29. "value": "+1234567890",
  30. "down": "true",
  31. "up": "true",
  32. }
  33. self.client.login(username="[email protected]", password="password")
  34. r = self.client.post(self.url, form)
  35. self.assertRedirects(r, self.channels_url)
  36. c = Channel.objects.get()
  37. self.assertEqual(c.kind, "whatsapp")
  38. self.assertEqual(c.phone_number, "+1234567890")
  39. self.assertEqual(c.name, "My Phone")
  40. self.assertTrue(c.whatsapp_notify_down)
  41. self.assertTrue(c.whatsapp_notify_up)
  42. self.assertEqual(c.project, self.project)
  43. def test_it_obeys_up_down_flags(self):
  44. form = {"label": "My Phone", "value": "+1234567890"}
  45. self.client.login(username="[email protected]", password="password")
  46. r = self.client.post(self.url, form)
  47. self.assertRedirects(r, self.channels_url)
  48. c = Channel.objects.get()
  49. self.assertEqual(c.kind, "whatsapp")
  50. self.assertEqual(c.phone_number, "+1234567890")
  51. self.assertEqual(c.name, "My Phone")
  52. self.assertFalse(c.whatsapp_notify_down)
  53. self.assertFalse(c.whatsapp_notify_up)
  54. self.assertEqual(c.project, self.project)
  55. @override_settings(TWILIO_USE_WHATSAPP=False)
  56. def test_it_obeys_use_whatsapp_flag(self):
  57. self.client.login(username="[email protected]", password="password")
  58. r = self.client.get(self.url)
  59. self.assertEqual(r.status_code, 404)