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.

54 lines
2.0 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="url")
  5. class AddPushoverTestCase(BaseTestCase):
  6. def test_instructions_work(self):
  7. self.client.login(username="[email protected]", password="password")
  8. r = self.client.get("/integrations/add_pushover/")
  9. self.assertContains(r, "Subscribe with Pushover")
  10. def test_it_adds_channel(self):
  11. self.client.login(username="[email protected]", password="password")
  12. session = self.client.session
  13. session["po_nonce"] = "n"
  14. session.save()
  15. params = "pushover_user_key=a&nonce=n&prio=0"
  16. r = self.client.get("/integrations/add_pushover/?%s" % params)
  17. assert r.status_code == 302
  18. channels = list(Channel.objects.all())
  19. assert len(channels) == 1
  20. assert channels[0].value == "a|0"
  21. @override_settings(PUSHOVER_API_TOKEN=None)
  22. def test_it_requires_api_token(self):
  23. self.client.login(username="[email protected]", password="password")
  24. r = self.client.get("/integrations/add_pushover/")
  25. self.assertEqual(r.status_code, 404)
  26. def test_it_validates_priority(self):
  27. self.client.login(username="[email protected]", password="password")
  28. session = self.client.session
  29. session["po_nonce"] = "n"
  30. session.save()
  31. params = "pushover_user_key=a&nonce=n&prio=abc"
  32. r = self.client.get("/integrations/add_pushover/?%s" % params)
  33. assert r.status_code == 400
  34. def test_it_validates_nonce(self):
  35. self.client.login(username="[email protected]", password="password")
  36. session = self.client.session
  37. session["po_nonce"] = "n"
  38. session.save()
  39. params = "pushover_user_key=a&nonce=INVALID&prio=0"
  40. r = self.client.get("/integrations/add_pushover/?%s" % params)
  41. assert r.status_code == 403