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.

83 lines
2.9 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
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_works(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_it_trims_whitespace(self):
  14. """ Leading and trailing whitespace should get trimmed. """
  15. url = "/integrations/add/"
  16. form = {"kind": "email", "value": " [email protected] "}
  17. self.client.login(username="[email protected]", password="password")
  18. self.client.post(url, form)
  19. q = Channel.objects.filter(value="[email protected]")
  20. self.assertEqual(q.count(), 1)
  21. def test_it_rejects_bad_kind(self):
  22. url = "/integrations/add/"
  23. form = {"kind": "dog", "value": "Lassie"}
  24. self.client.login(username="[email protected]", password="password")
  25. r = self.client.post(url, form)
  26. assert r.status_code == 400, r.status_code
  27. def test_instructions_work(self):
  28. self.client.login(username="[email protected]", password="password")
  29. for frag in ("email", "webhook", "pd", "pushover", "slack", "hipchat"):
  30. url = "/integrations/add_%s/" % frag
  31. r = self.client.get(url)
  32. self.assertContains(r, "Integration Settings", status_code=200)
  33. def test_it_adds_pushover_channel(self):
  34. self.client.login(username="[email protected]", password="password")
  35. session = self.client.session
  36. session["po_nonce"] = "n"
  37. session.save()
  38. params = "pushover_user_key=a&nonce=n&prio=0"
  39. r = self.client.get("/integrations/add_pushover/?%s" % params)
  40. assert r.status_code == 302
  41. channels = list(Channel.objects.all())
  42. assert len(channels) == 1
  43. assert channels[0].value == "a|0"
  44. def test_it_validates_pushover_priority(self):
  45. self.client.login(username="[email protected]", password="password")
  46. session = self.client.session
  47. session["po_nonce"] = "n"
  48. session.save()
  49. params = "pushover_user_key=a&nonce=n&prio=abc"
  50. r = self.client.get("/integrations/add_pushover/?%s" % params)
  51. assert r.status_code == 400
  52. def test_it_validates_pushover_nonce(self):
  53. self.client.login(username="[email protected]", password="password")
  54. session = self.client.session
  55. session["po_nonce"] = "n"
  56. session.save()
  57. params = "pushover_user_key=a&nonce=INVALID&prio=0"
  58. r = self.client.get("/integrations/add_pushover/?%s" % params)
  59. assert r.status_code == 403