|
|
@ -7,10 +7,14 @@ from hc.test import BaseTestCase |
|
|
|
PUSHOVER_API_TOKEN="token", PUSHOVER_SUBSCRIPTION_URL="http://example.org" |
|
|
|
) |
|
|
|
class AddPushoverTestCase(BaseTestCase): |
|
|
|
def setUp(self): |
|
|
|
super(AddPushoverTestCase, self).setUp() |
|
|
|
self.url = "/projects/%s/add_pushover/" % self.project.code |
|
|
|
|
|
|
|
@override_settings(PUSHOVER_API_TOKEN=None) |
|
|
|
def test_it_requires_api_token(self): |
|
|
|
self.client.login(username="[email protected]", password="password") |
|
|
|
r = self.client.get("/integrations/add_pushover/") |
|
|
|
r = self.client.get(self.url) |
|
|
|
self.assertEqual(r.status_code, 404) |
|
|
|
|
|
|
|
def test_instructions_work_without_login(self): |
|
|
@ -19,20 +23,18 @@ class AddPushoverTestCase(BaseTestCase): |
|
|
|
|
|
|
|
def test_it_shows_form(self): |
|
|
|
self.client.login(username="[email protected]", password="password") |
|
|
|
r = self.client.get("/integrations/add_pushover/") |
|
|
|
r = self.client.get(self.url) |
|
|
|
self.assertContains(r, "Subscribe with Pushover") |
|
|
|
|
|
|
|
def test_post_redirects(self): |
|
|
|
self.client.login(username="[email protected]", password="password") |
|
|
|
payload = {"po_priority": 2} |
|
|
|
r = self.client.post("/integrations/add_pushover/", form=payload) |
|
|
|
r = self.client.post(self.url, form=payload) |
|
|
|
self.assertEqual(r.status_code, 302) |
|
|
|
|
|
|
|
def test_post_requires_authenticated_user(self): |
|
|
|
payload = {"po_priority": 2} |
|
|
|
r = self.client.post("/integrations/add_pushover/", form=payload) |
|
|
|
self.assertEqual(r.status_code, 200) |
|
|
|
self.assertContains(r, "Setup Guide") |
|
|
|
def test_it_requires_authenticated_user(self): |
|
|
|
r = self.client.get(self.url) |
|
|
|
self.assertRedirects(r, "/accounts/login/?next=" + self.url) |
|
|
|
|
|
|
|
def test_it_adds_channel(self): |
|
|
|
self.client.login(username="[email protected]", password="password") |
|
|
@ -41,9 +43,9 @@ class AddPushoverTestCase(BaseTestCase): |
|
|
|
session["pushover"] = "foo" |
|
|
|
session.save() |
|
|
|
|
|
|
|
params = "pushover_user_key=a&state=foo&prio=0&prio_up=-1" |
|
|
|
r = self.client.get("/integrations/add_pushover/?%s" % params) |
|
|
|
self.assertEqual(r.status_code, 302) |
|
|
|
params = "?pushover_user_key=a&state=foo&prio=0&prio_up=-1" |
|
|
|
r = self.client.get(self.url + params, follow=True) |
|
|
|
self.assertRedirects(r, self.channels_url) |
|
|
|
|
|
|
|
channel = Channel.objects.get() |
|
|
|
self.assertEqual(channel.value, "a|0|-1") |
|
|
@ -56,8 +58,8 @@ class AddPushoverTestCase(BaseTestCase): |
|
|
|
session["pushover"] = "foo" |
|
|
|
session.save() |
|
|
|
|
|
|
|
params = "pushover_user_key=a&state=foo&prio=abc" |
|
|
|
r = self.client.get("/integrations/add_pushover/?%s" % params) |
|
|
|
params = "?pushover_user_key=a&state=foo&prio=abc" |
|
|
|
r = self.client.get(self.url + params) |
|
|
|
self.assertEqual(r.status_code, 400) |
|
|
|
|
|
|
|
def test_it_validates_priority_up(self): |
|
|
@ -67,8 +69,8 @@ class AddPushoverTestCase(BaseTestCase): |
|
|
|
session["pushover"] = "foo" |
|
|
|
session.save() |
|
|
|
|
|
|
|
params = "pushover_user_key=a&state=foo&prio_up=abc" |
|
|
|
r = self.client.get("/integrations/add_pushover/?%s" % params) |
|
|
|
params = "?pushover_user_key=a&state=foo&prio_up=abc" |
|
|
|
r = self.client.get(self.url + params) |
|
|
|
self.assertEqual(r.status_code, 400) |
|
|
|
|
|
|
|
def test_it_validates_state(self): |
|
|
@ -78,6 +80,6 @@ class AddPushoverTestCase(BaseTestCase): |
|
|
|
session["pushover"] = "foo" |
|
|
|
session.save() |
|
|
|
|
|
|
|
params = "pushover_user_key=a&state=INVALID&prio=0" |
|
|
|
r = self.client.get("/integrations/add_pushover/?%s" % params) |
|
|
|
self.assertEqual(r.status_code, 400) |
|
|
|
params = "?pushover_user_key=a&state=INVALID&prio=0" |
|
|
|
r = self.client.get(self.url + params) |
|
|
|
self.assertEqual(r.status_code, 403) |