mirror of
https://github.com/mtan93/cachet-url-monitor.git
synced 2026-03-08 05:31:58 +00:00
#38 - Adding support to milliseconds and different units for latency and changing http status to a range, instead of a single value.
This commit is contained in:
@@ -2,10 +2,11 @@
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
import cachet_url_monitor.status
|
||||
import mock
|
||||
from requests import ConnectionError, HTTPError, Timeout
|
||||
|
||||
import cachet_url_monitor.status
|
||||
|
||||
sys.modules['requests'] = mock.Mock()
|
||||
sys.modules['logging'] = mock.Mock()
|
||||
from cachet_url_monitor.configuration import Configuration
|
||||
@@ -38,7 +39,7 @@ class ConfigurationTest(unittest.TestCase):
|
||||
sys.modules['requests'].HTTPError = HTTPError
|
||||
|
||||
def test_init(self):
|
||||
self.assertEqual(len(self.configuration.data), 3, 'Configuration data size is incorrect')
|
||||
self.assertEqual(len(self.configuration.data), 4, 'Number of root elements in config.yml is incorrect')
|
||||
self.assertEquals(len(self.configuration.expectations), 3, 'Number of expectations read from file is incorrect')
|
||||
self.assertDictEqual(self.configuration.headers, {'X-Cachet-Token': 'token2'}, 'Header was not set correctly')
|
||||
self.assertEquals(self.configuration.api_url, 'https://demo.cachethq.io/api/v1',
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#!/usr/bin/env python
|
||||
import re
|
||||
import unittest
|
||||
|
||||
import mock
|
||||
import re
|
||||
import pytest
|
||||
|
||||
from cachet_url_monitor.configuration import HttpStatus, Regex
|
||||
from cachet_url_monitor.configuration import Latency
|
||||
|
||||
@@ -51,10 +53,21 @@ class LatencyTest(unittest.TestCase):
|
||||
|
||||
class HttpStatusTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.expectation = HttpStatus({'type': 'HTTP_STATUS', 'status': 200})
|
||||
self.expectation = HttpStatus({'type': 'HTTP_STATUS', 'status_range': "200-300"})
|
||||
|
||||
def test_init(self):
|
||||
assert self.expectation.status == 200
|
||||
assert self.expectation.status_range == (200, 300)
|
||||
|
||||
def test_init_with_one_status(self):
|
||||
"""With only one value, we still expect a valid tuple"""
|
||||
self.expectation = HttpStatus({'type': 'HTTP_STATUS', 'status_range': "200"})
|
||||
|
||||
assert self.expectation.status_range == (200, 201)
|
||||
|
||||
def test_init_with_invalid_number(self):
|
||||
"""Invalid values should just fail with a ValueError, as we can't convert it to int."""
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
self.expectation = HttpStatus({'type': 'HTTP_STATUS', 'status_range': "foo"})
|
||||
|
||||
def test_get_status_healthy(self):
|
||||
request = mock.Mock()
|
||||
|
||||
18
tests/test_latency_unit.py
Normal file
18
tests/test_latency_unit.py
Normal file
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env python
|
||||
import unittest
|
||||
|
||||
from cachet_url_monitor.latency_unit import convert_to_unit
|
||||
|
||||
|
||||
class ConfigurationTest(unittest.TestCase):
|
||||
def test_convert_to_unit_ms(self):
|
||||
assert convert_to_unit("ms", 1) == 1000
|
||||
|
||||
def test_convert_to_unit_s(self):
|
||||
assert convert_to_unit("s", 20) == 20
|
||||
|
||||
def test_convert_to_unit_m(self):
|
||||
assert convert_to_unit("m", 3) == float(3) / 60
|
||||
|
||||
def test_convert_to_unit_h(self):
|
||||
assert convert_to_unit("h", 7200) == 2
|
||||
Reference in New Issue
Block a user