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.

81 lines
3.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(PUSHOVER_API_TOKEN="token", PUSHOVER_SUBSCRIPTION_URL="http://example.org")
  5. class AddPushoverTestCase(BaseTestCase):
  6. @override_settings(PUSHOVER_API_TOKEN=None)
  7. def test_it_requires_api_token(self):
  8. self.client.login(username="[email protected]", password="password")
  9. r = self.client.get("/integrations/add_pushover/")
  10. self.assertEqual(r.status_code, 404)
  11. def test_instructions_work_without_login(self):
  12. r = self.client.get("/integrations/add_pushover/")
  13. self.assertContains(r, "Setup Guide")
  14. def test_it_shows_form(self):
  15. self.client.login(username="[email protected]", password="password")
  16. r = self.client.get("/integrations/add_pushover/")
  17. self.assertContains(r, "Subscribe with Pushover")
  18. def test_post_redirects(self):
  19. self.client.login(username="[email protected]", password="password")
  20. payload = {"po_priority": 2}
  21. r = self.client.post("/integrations/add_pushover/", form=payload)
  22. self.assertEqual(r.status_code, 302)
  23. def test_post_requires_authenticated_user(self):
  24. payload = {"po_priority": 2}
  25. r = self.client.post("/integrations/add_pushover/", form=payload)
  26. self.assertEqual(r.status_code, 200)
  27. self.assertContains(r, "Setup Guide")
  28. def test_it_adds_channel(self):
  29. self.client.login(username="[email protected]", password="password")
  30. session = self.client.session
  31. session["pushover"] = "foo"
  32. session.save()
  33. params = "pushover_user_key=a&state=foo&prio=0&prio_up=-1"
  34. r = self.client.get("/integrations/add_pushover/?%s" % params)
  35. self.assertEqual(r.status_code, 302)
  36. channel = Channel.objects.get()
  37. self.assertEqual(channel.value, "a|0|-1")
  38. self.assertEqual(channel.project, self.project)
  39. def test_it_validates_priority(self):
  40. self.client.login(username="[email protected]", password="password")
  41. session = self.client.session
  42. session["pushover"] = "foo"
  43. session.save()
  44. params = "pushover_user_key=a&state=foo&prio=abc"
  45. r = self.client.get("/integrations/add_pushover/?%s" % params)
  46. self.assertEqual(r.status_code, 400)
  47. def test_it_validates_priority_up(self):
  48. self.client.login(username="[email protected]", password="password")
  49. session = self.client.session
  50. session["pushover"] = "foo"
  51. session.save()
  52. params = "pushover_user_key=a&state=foo&prio_up=abc"
  53. r = self.client.get("/integrations/add_pushover/?%s" % params)
  54. self.assertEqual(r.status_code, 400)
  55. def test_it_validates_state(self):
  56. self.client.login(username="[email protected]", password="password")
  57. session = self.client.session
  58. session["pushover"] = "foo"
  59. session.save()
  60. params = "pushover_user_key=a&state=INVALID&prio=0"
  61. r = self.client.get("/integrations/add_pushover/?%s" % params)
  62. self.assertEqual(r.status_code, 400)