-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonitor_test.py
46 lines (32 loc) · 1.15 KB
/
monitor_test.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
#!/usr/bin/env python
import unittest
from monitor import Client, Emailer, SiteWatcher, Site
import logging
log = logging.getLogger("site-watcher")
log.setLevel(logging.ERROR)
class FailyClient(Client):
"""Always behaves like Site is down"""
def __init__(self, *args):
pass
def get_url(self, url):
return False, "faily client"
class MockEmailer(Emailer):
def __init__(self):
self.mock_calls = []
def send_message(self, *args):
self.mock_calls.append(args)
class TestWatcher(unittest.TestCase):
def setUp(self):
self.client = FailyClient()
self.site = Site("TestSite", "http://testsite.com", 2, "[email protected]")
self.emailer = MockEmailer()
self.watcher = SiteWatcher(self.site, self.client, self.emailer,
fork=False)
def test_email_sent(self):
self.watcher.run_check()
email_args = ("[email protected]",
"Site <Site TestSite url: http://testsite.com> down",
"faily client")
self.assertIn(email_args, self.emailer.mock_calls)
if __name__ == '__main__':
unittest.main()