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

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.name, "My Phone")
  27. self.assertEqual(c.project, self.project)
  28. def test_it_rejects_bad_number(self):
  29. form = {"value": "not a phone number address"}
  30. self.client.login(username="[email protected]", password="password")
  31. r = self.client.post(self.url, form)
  32. self.assertContains(r, "Invalid phone number format.")
  33. def test_it_trims_whitespace(self):
  34. form = {"value": " +1234567890 "}
  35. self.client.login(username="[email protected]", password="password")
  36. self.client.post(self.url, form)
  37. c = Channel.objects.get()
  38. self.assertEqual(c.sms_number, "+1234567890")
  39. @override_settings(TWILIO_AUTH=None)
  40. def test_it_requires_credentials(self):
  41. self.client.login(username="[email protected]", password="password")
  42. r = self.client.get("/integrations/add_sms/")
  43. self.assertEqual(r.status_code, 404)