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.

58 lines
2.0 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 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(PUSHOVER_API_TOKEN="token", PUSHOVER_SUBSCRIPTION_URL="url")
  5. class AddChannelTestCase(BaseTestCase):
  6. def test_it_adds_email(self):
  7. url = "/integrations/add/"
  8. form = {"kind": "email", "value": "[email protected]"}
  9. self.client.login(username="[email protected]", password="password")
  10. r = self.client.post(url, form)
  11. self.assertRedirects(r, "/integrations/")
  12. assert Channel.objects.count() == 1
  13. def test_team_access_works(self):
  14. url = "/integrations/add/"
  15. form = {"kind": "email", "value": "[email protected]"}
  16. self.client.login(username="[email protected]", password="password")
  17. self.client.post(url, form)
  18. ch = Channel.objects.get()
  19. # Added by bob, but should belong to alice (bob has team access)
  20. self.assertEqual(ch.user, self.alice)
  21. def test_it_trims_whitespace(self):
  22. """ Leading and trailing whitespace should get trimmed. """
  23. url = "/integrations/add/"
  24. form = {"kind": "email", "value": " [email protected] "}
  25. self.client.login(username="[email protected]", password="password")
  26. self.client.post(url, form)
  27. q = Channel.objects.filter(value="[email protected]")
  28. self.assertEqual(q.count(), 1)
  29. def test_it_rejects_bad_kind(self):
  30. url = "/integrations/add/"
  31. form = {"kind": "dog", "value": "Lassie"}
  32. self.client.login(username="[email protected]", password="password")
  33. r = self.client.post(url, form)
  34. assert r.status_code == 400, r.status_code
  35. def test_instructions_work(self):
  36. self.client.login(username="[email protected]", password="password")
  37. kinds = ("email", "webhook", "pd", "pushover", "hipchat", "victorops")
  38. for frag in kinds:
  39. url = "/integrations/add_%s/" % frag
  40. r = self.client.get(url)
  41. self.assertContains(r, "Integration Settings", status_code=200)