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.

56 lines
2.0 KiB

7 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(TWILIO_ACCOUNT="foo", TWILIO_AUTH="foo", TWILIO_FROM="123")
  5. class AddSmsTestCase(BaseTestCase):
  6. url = "/integrations/add_sms/"
  7. def test_instructions_work(self):
  8. self.client.login(username="[email protected]", password="password")
  9. r = self.client.get(self.url)
  10. self.assertContains(r, "Get a SMS message")
  11. @override_settings(USE_PAYMENTS=True)
  12. def test_it_warns_about_limits(self):
  13. self.profile.sms_limit = 0
  14. self.profile.save()
  15. self.client.login(username="[email protected]", password="password")
  16. r = self.client.get(self.url)
  17. self.assertContains(r, "upgrade to a")
  18. def test_it_creates_channel(self):
  19. form = {"label": "My Phone", "value": "+1234567890"}
  20. self.client.login(username="[email protected]", password="password")
  21. r = self.client.post(self.url, form)
  22. self.assertRedirects(r, "/integrations/")
  23. c = Channel.objects.get()
  24. self.assertEqual(c.kind, "sms")
  25. self.assertEqual(c.sms_number, "+1234567890")
  26. self.assertEqual(c.sms_label, "My Phone")
  27. def test_it_rejects_bad_number(self):
  28. form = {"value": "not a phone number address"}
  29. self.client.login(username="[email protected]", password="password")
  30. r = self.client.post(self.url, form)
  31. self.assertContains(r, "Invalid phone number format.")
  32. def test_it_trims_whitespace(self):
  33. form = {"value": " +1234567890 "}
  34. self.client.login(username="[email protected]", password="password")
  35. self.client.post(self.url, form)
  36. c = Channel.objects.get()
  37. self.assertEqual(c.sms_number, "+1234567890")
  38. @override_settings(TWILIO_AUTH=None)
  39. def test_it_requires_credentials(self):
  40. self.client.login(username="[email protected]", password="password")
  41. r = self.client.get("/integrations/add_sms/")
  42. self.assertEqual(r.status_code, 404)