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