forked from GithubBackups/healthchecks
Testcases for the new code.
This commit is contained in:
parent
3ecd6bd422
commit
97b3b52df5
@ -85,14 +85,24 @@ def num_down_title(num_down):
|
|||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def down_title(check):
|
def down_title(check):
|
||||||
|
""" Prepare title tag for the Details page.
|
||||||
|
|
||||||
|
If the check is down, return "DOWN - Name - site_name".
|
||||||
|
Otherwise, return "Name - site_name".
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
s = "%s – %s" % (check.name_then_code(), settings.SITE_NAME)
|
s = "%s – %s" % (check.name_then_code(), settings.SITE_NAME)
|
||||||
if check.get_status() == "down":
|
if check.get_status() == "down":
|
||||||
s = "DOWN – " + s
|
s = "DOWN – " + s
|
||||||
|
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def break_underscore(s):
|
def break_underscore(s):
|
||||||
|
""" Add non-breaking-space characters after underscores. """
|
||||||
|
|
||||||
if len(s) > 30:
|
if len(s) > 30:
|
||||||
s = s.replace("_", "_\u200b")
|
s = s.replace("_", "_\u200b")
|
||||||
|
|
||||||
|
38
hc/front/tests/test_details.py
Normal file
38
hc/front/tests/test_details.py
Normal file
@ -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="alice@example.org", 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="charlie@example.org", 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="alice@example.org", 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="alice@example.org", password="password")
|
self.client.login(username="alice@example.org", 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="charlie@example.org", password="password")
|
self.client.login(username="charlie@example.org", 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)
|
||||||
|
48
hc/front/tests/test_status_single.py
Normal file
48
hc/front/tests/test_status_single.py
Normal file
@ -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="alice@example.org", 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="alice@example.org", 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="alice@example.org", password="password")
|
||||||
|
r = self.client.get(url)
|
||||||
|
doc = r.json()
|
||||||
|
|
||||||
|
self.assertFalse("events" in doc)
|
46
hc/front/tests/test_switch_channel.py
Normal file
46
hc/front/tests/test_switch_channel.py
Normal file
@ -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 = "alice@example.org"
|
||||||
|
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="alice@example.org", 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="alice@example.org", 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="charlie@example.org", 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="charlie@example.org", password="password")
|
||||||
|
r = self.client.post(self.url, {"state": "on"})
|
||||||
|
self.assertEqual(r.status_code, 403)
|
Loading…
x
Reference in New Issue
Block a user