Initial attempt at creating incidents when an URL becomes unhealthy. Missing to actually call it from the scheduler. #3

This commit is contained in:
Mitsuo Takaki
2016-05-16 01:31:53 -07:00
parent 9c8c89c1dd
commit 0f53ff8678
6 changed files with 129 additions and 53 deletions

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
import cachet_url_monitor.status
import mock
import unittest
import sys
@@ -37,7 +38,7 @@ class ConfigurationTest(unittest.TestCase):
sys.modules['requests'].request = request
self.configuration.evaluate()
assert self.configuration.status == 1
assert self.configuration.status == cachet_url_monitor.status.COMPONENT_STATUS_OPERATIONAL
def test_evaluate_with_failure(self):
def total_seconds():
@@ -54,7 +55,7 @@ class ConfigurationTest(unittest.TestCase):
sys.modules['requests'].request = request
self.configuration.evaluate()
assert self.configuration.status == 3
assert self.configuration.status == cachet_url_monitor.status.COMPONENT_STATUS_PARTIAL_OUTAGE
def test_evaluate_with_timeout(self):
def request(method, url, timeout=None):
@@ -67,7 +68,7 @@ class ConfigurationTest(unittest.TestCase):
sys.modules['requests'].request = request
self.configuration.evaluate()
assert self.configuration.status == 3
assert self.configuration.status == cachet_url_monitor.status.COMPONENT_STATUS_PERFORMANCE_ISSUES
self.mock_logger.warning.assert_called_with('Request timed out')
def test_evaluate_with_connection_error(self):

View File

@@ -77,11 +77,11 @@ class RegexTest(unittest.TestCase):
self.expectation = Regex({'type': 'REGEX', 'regex': '.*(find stuff).*'})
def test_init(self):
assert self.expectation.regex == re.compile('.*(find stuff).*')
assert self.expectation.regex == re.compile('.*(find stuff).*', re.UNICODE + re.DOTALL)
def test_get_status_healthy(self):
request = mock.Mock()
request.text = 'We could find stuff in this body.'
request.text = 'We could find stuff\n in this body.'
assert self.expectation.get_status(request) == 1