@ -0,0 +1,38 @@ | |||||
from hc.api.models import Check, Ping | |||||
from hc.test import BaseTestCase | |||||
class DetailsTestCase(BaseTestCase): | |||||
def setUp(self): | |||||
super(DetailsTestCase, self).setUp() | |||||
self.check = Check(user=self.alice) | |||||
self.check.save() | |||||
ping = Ping(owner=self.check) | |||||
ping.save() | |||||
# Older MySQL versions don't store microseconds. This makes sure | |||||
# the ping is older than any notifications we may create later: | |||||
ping.created = "2000-01-01T00:00:00+00:00" | |||||
ping.save() | |||||
self.url = "/checks/%s/details/" % self.check.code | |||||
def test_it_works(self): | |||||
self.client.login(username="[email protected]", password="password") | |||||
r = self.client.get(self.url) | |||||
self.assertContains(r, "How To Ping", status_code=200) | |||||
def test_it_checks_ownership(self): | |||||
self.client.login(username="[email protected]", password="password") | |||||
r = self.client.get(self.url) | |||||
assert r.status_code == 403 | |||||
def test_it_shows_cron_expression(self): | |||||
self.check.kind = "cron" | |||||
self.check.save() | |||||
self.client.login(username="[email protected]", password="password") | |||||
r = self.client.get(self.url) | |||||
self.assertContains(r, "Cron Expression", status_code=200) |
@ -46,13 +46,13 @@ class LogTestCase(BaseTestCase): | |||||
self.client.login(username="[email protected]", password="password") | self.client.login(username="[email protected]", password="password") | ||||
r = self.client.get(url) | r = self.client.get(url) | ||||
assert r.status_code == 404 | |||||
self.assertEqual(r.status_code, 404) | |||||
def test_it_checks_ownership(self): | def test_it_checks_ownership(self): | ||||
url = "/checks/%s/log/" % self.check.code | url = "/checks/%s/log/" % self.check.code | ||||
self.client.login(username="[email protected]", password="password") | self.client.login(username="[email protected]", password="password") | ||||
r = self.client.get(url) | r = self.client.get(url) | ||||
assert r.status_code == 403 | |||||
self.assertEqual(r.status_code, 403) | |||||
def test_it_shows_pushover_notifications(self): | def test_it_shows_pushover_notifications(self): | ||||
ch = Channel(kind="po", user=self.alice) | ch = Channel(kind="po", user=self.alice) | ||||
@ -0,0 +1,48 @@ | |||||
from hc.api.models import Check, Ping | |||||
from hc.test import BaseTestCase | |||||
class StatusSingleTestCase(BaseTestCase): | |||||
def setUp(self): | |||||
super(StatusSingleTestCase, self).setUp() | |||||
self.check = Check(user=self.alice, name="Alice Was Here") | |||||
self.check.save() | |||||
def test_it_works(self): | |||||
self.client.login(username="[email protected]", password="password") | |||||
r = self.client.get("/checks/%s/status/" % self.check.code) | |||||
doc = r.json() | |||||
self.assertEqual(doc["status"], "new") | |||||
self.assertTrue("never received a ping" in doc["status_text"]) | |||||
self.assertTrue("not received any pings yet" in doc["events"]) | |||||
def test_it_returns_events(self): | |||||
p = Ping.objects.create(owner=self.check, ua="test-user-agent", n=1) | |||||
self.check.status = "up" | |||||
self.check.last_ping = p.created | |||||
self.check.save() | |||||
self.client.login(username="[email protected]", password="password") | |||||
r = self.client.get("/checks/%s/status/" % self.check.code) | |||||
doc = r.json() | |||||
self.assertEqual(doc["status"], "up") | |||||
self.assertEqual(doc["updated"], p.created.strftime("%s.%f")) | |||||
self.assertTrue("test-user-agent" in doc["events"]) | |||||
def test_it_omits_events(self): | |||||
p = Ping.objects.create(owner=self.check, ua="test-user-agent", n=1) | |||||
self.check.status = "up" | |||||
self.check.last_ping = p.created | |||||
self.check.save() | |||||
timestamp = p.created.strftime("%s.%f") | |||||
url = "/checks/%s/status/?u=%s" % (self.check.code, timestamp) | |||||
self.client.login(username="[email protected]", password="password") | |||||
r = self.client.get(url) | |||||
doc = r.json() | |||||
self.assertFalse("events" in doc) |
@ -0,0 +1,46 @@ | |||||
from hc.api.models import Channel, Check | |||||
from hc.test import BaseTestCase | |||||
class SwitchChannelTestCase(BaseTestCase): | |||||
def setUp(self): | |||||
super(SwitchChannelTestCase, self).setUp() | |||||
self.check = Check(user=self.alice) | |||||
self.check.save() | |||||
self.channel = Channel(user=self.alice, kind="email") | |||||
self.channel.value = "[email protected]" | |||||
self.channel.save() | |||||
self.url = "/checks/%s/channels/%s/enabled" % (self.check.code, self.channel.code) | |||||
def test_it_enables(self): | |||||
self.client.login(username="[email protected]", password="password") | |||||
self.client.post(self.url, {"state": "on"}) | |||||
self.assertTrue(self.channel in self.check.channel_set.all()) | |||||
def test_it_disables(self): | |||||
self.check.channel_set.add(self.channel) | |||||
self.client.login(username="[email protected]", password="password") | |||||
self.client.post(self.url, {"state": "off"}) | |||||
self.assertFalse(self.channel in self.check.channel_set.all()) | |||||
def test_it_checks_ownership(self): | |||||
self.client.login(username="[email protected]", password="password") | |||||
r = self.client.post(self.url, {"state": "on"}) | |||||
self.assertEqual(r.status_code, 403) | |||||
def test_it_checks_channels_ownership(self): | |||||
cc = Check(user=self.charlie) | |||||
cc.save() | |||||
# Charlie will try to assign Alice's channel to his check: | |||||
self.url = "/checks/%s/channels/%s/enabled" % (cc.code, self.channel.code) | |||||
self.client.login(username="[email protected]", password="password") | |||||
r = self.client.post(self.url, {"state": "on"}) | |||||
self.assertEqual(r.status_code, 403) |