mirror of
https://github.com/mtan93/cachet-url-monitor.git
synced 2026-03-08 05:31:58 +00:00
Initial attempt at creating incidents when an URL becomes unhealthy. Missing to actually call it from the scheduler. #3
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user