2018-07-16 01:30:13 +00:00
|
|
|
import os
|
|
|
|
from unittest.mock import patch
|
|
|
|
|
2018-04-10 18:06:42 +00:00
|
|
|
from minitor.main import call_output
|
2018-07-16 01:30:13 +00:00
|
|
|
from minitor.main import Minitor
|
2018-04-10 18:06:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestMinitor(object):
|
|
|
|
|
|
|
|
def test_call_output(self):
|
|
|
|
# valid command should have result and no exception
|
|
|
|
output, ex = call_output(['echo', 'test'])
|
|
|
|
assert output == b'test'
|
|
|
|
assert ex is None
|
|
|
|
|
|
|
|
output, ex = call_output(['ls', '--not-a-real-flag'])
|
2018-04-11 17:03:05 +00:00
|
|
|
assert output.startswith(b'ls: ')
|
2018-04-10 18:06:42 +00:00
|
|
|
assert ex is not None
|
2018-07-16 01:30:13 +00:00
|
|
|
|
|
|
|
def test_run(self):
|
|
|
|
"""Doesn't really check much, but a simple integration sanity test"""
|
|
|
|
test_loop_count = 5
|
|
|
|
os.environ.update({
|
|
|
|
'MAILGUN_API_KEY': 'test-mg-key',
|
|
|
|
'AVAILABLE_NUMBER': '555-555-5050',
|
|
|
|
'MY_PHONE': '555-555-0505',
|
|
|
|
'ACCOUNT_SID': 'test-account-id',
|
|
|
|
'ACCOUNT_TOKEN': 'test-account-token',
|
|
|
|
})
|
|
|
|
args = '--config ./sample-config.yml'.split(' ')
|
|
|
|
minitor = Minitor()
|
|
|
|
with patch.object(minitor, '_loop'):
|
|
|
|
minitor.run(args)
|
|
|
|
# Skip the loop, but run a single check
|
|
|
|
for _ in range(test_loop_count):
|
|
|
|
minitor._check()
|