-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_alerting.py
More file actions
39 lines (28 loc) · 1.24 KB
/
test_alerting.py
File metadata and controls
39 lines (28 loc) · 1.24 KB
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
import unittest
from monitor import Monitor, Alert
class TestAlerting(unittest.TestCase):
def setUp(self):
self.threshold = 10
self.monitor = Monitor(log_path=None, hit_threshold=self.threshold)
def test_no_alerts_when_below_threshold(self):
self.monitor.recent_hits = self.threshold
for x in xrange(10):
self.monitor.check_alerts()
self.assertEquals(self.monitor.alerts, [])
def test_single_alert_created_above_threshold(self):
self.monitor.recent_hits = self.threshold + 1
for x in xrange(10):
self.monitor.check_alerts()
self.monitor.recent_hits += 1
self.assertEquals(len(self.monitor.alerts), 1)
self.assertIsInstance(self.monitor.alerts[0], Alert)
self.assertIn('WARN', str(self.monitor.alerts[0]))
def test_two_alerts_above_then_below_threshold(self):
self.monitor.recent_hits = self.threshold + 1
self.monitor.check_alerts()
self.monitor.recent_hits -= 1
for x in xrange(10):
self.monitor.check_alerts()
self.assertEquals(len(self.monitor.alerts), 2)
self.assertIn('WARN', str(self.monitor.alerts[0]))
self.assertIn('INFO', str(self.monitor.alerts[1]))