This repository has been archived by the owner on Jan 31, 2018. It is now read-only.
/
test_healthchecks.py
59 lines (48 loc) · 1.88 KB
/
test_healthchecks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from django.core import mail
from fjord.base.tests import TestCase
from fjord.heartbeat.healthchecks import (
CheckAnyAnswers,
email_healthchecks,
run_healthchecks,
SEVERITY_LOW,
SEVERITY_HIGH,
)
from fjord.heartbeat.tests import AnswerFactory
from fjord.mailinglist.tests import MailingListFactory
class TestCheckAnyAnswers(TestCase):
def test_good(self):
"""One or more answers is fine"""
AnswerFactory.create_batch(2)
result = CheckAnyAnswers.check()
assert result.severity == SEVERITY_LOW
assert result.summary == '2 answers in last 24 hours.'
assert result.output == '2'
def test_bad(self):
"""No answers is very bad"""
result = CheckAnyAnswers.check()
assert result.severity == SEVERITY_HIGH
assert result.summary == '0 answers in last 24 hours.'
assert result.output == '0'
class TestRunHealthChecks(TestCase):
def test_basic(self):
results = run_healthchecks()
# Note: You'll need to update this any time we add a health check.
assert len(results) == 2
class TestEmailHealthChecks(TestCase):
def test_no_recipients(self):
"""If there are no recipients, no email is sent"""
email_healthchecks(run_healthchecks())
assert len(mail.outbox) == 0
# FIXME: test that something got logged?
def test_with_recipients(self):
"""If there are recipients, then email is sent"""
MailingListFactory(
name='heartbeat_health',
members=u'foo@example.com'
)
email_healthchecks(run_healthchecks())
assert len(mail.outbox) == 1
assert mail.outbox[0].to == [u'foo@example.com']
# Severity should be RED ALERT since there's no hb items--at least
# one of the checks should be all like, "OMG! RED ALERT!"
assert 'RED ALERT' in mail.outbox[0].subject