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.

59 lines
2.1 KiB

  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 AddCallTestCase(BaseTestCase):
  6. def setUp(self):
  7. super(AddCallTestCase, self).setUp()
  8. self.url = "/projects/%s/add_call/" % self.project.code
  9. def test_instructions_work(self):
  10. self.client.login(username="[email protected]", password="password")
  11. r = self.client.get(self.url)
  12. self.assertContains(r, "Get a phone call")
  13. @override_settings(USE_PAYMENTS=True)
  14. def test_it_warns_about_limits(self):
  15. self.profile.sms_limit = 0
  16. self.profile.save()
  17. self.client.login(username="[email protected]", password="password")
  18. r = self.client.get(self.url)
  19. self.assertContains(r, "upgrade to a")
  20. def test_it_creates_channel(self):
  21. form = {"label": "My Phone", "value": "+1234567890"}
  22. self.client.login(username="[email protected]", password="password")
  23. r = self.client.post(self.url, form)
  24. self.assertRedirects(r, self.channels_url)
  25. c = Channel.objects.get()
  26. self.assertEqual(c.kind, "call")
  27. self.assertEqual(c.sms_number, "+1234567890")
  28. self.assertEqual(c.name, "My Phone")
  29. self.assertEqual(c.project, self.project)
  30. def test_it_rejects_bad_number(self):
  31. form = {"value": "not a phone number"}
  32. self.client.login(username="[email protected]", password="password")
  33. r = self.client.post(self.url, form)
  34. self.assertContains(r, "Invalid phone number format.")
  35. def test_it_trims_whitespace(self):
  36. form = {"value": " +1234567890 "}
  37. self.client.login(username="[email protected]", password="password")
  38. self.client.post(self.url, form)
  39. c = Channel.objects.get()
  40. self.assertEqual(c.sms_number, "+1234567890")
  41. @override_settings(TWILIO_AUTH=None)
  42. def test_it_requires_credentials(self):
  43. self.client.login(username="[email protected]", password="password")
  44. r = self.client.get(self.url)
  45. self.assertEqual(r.status_code, 404)