mirror of
https://github.com/mtan93/cachet-url-monitor.git
synced 2026-05-12 22:06:46 +01:00
Fixing failing test. Using @mock.path decorator, instead of overriding the sys.modules.
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
#!/usr/bin/env python
|
||||
import unittest
|
||||
|
||||
import mock
|
||||
import re
|
||||
import unittest
|
||||
from cachet_url_monitor.configuration import Expectaction,Latency
|
||||
from cachet_url_monitor.configuration import HttpStatus,Regex
|
||||
from cachet_url_monitor.configuration import HttpStatus, Regex
|
||||
from cachet_url_monitor.configuration import Latency
|
||||
|
||||
|
||||
class LatencyTest(unittest.TestCase):
|
||||
@@ -16,6 +17,7 @@ class LatencyTest(unittest.TestCase):
|
||||
def test_get_status_healthy(self):
|
||||
def total_seconds():
|
||||
return 0.1
|
||||
|
||||
request = mock.Mock()
|
||||
elapsed = mock.Mock()
|
||||
request.elapsed = elapsed
|
||||
@@ -26,6 +28,7 @@ class LatencyTest(unittest.TestCase):
|
||||
def test_get_status_unhealthy(self):
|
||||
def total_seconds():
|
||||
return 2
|
||||
|
||||
request = mock.Mock()
|
||||
elapsed = mock.Mock()
|
||||
request.elapsed = elapsed
|
||||
@@ -36,13 +39,14 @@ class LatencyTest(unittest.TestCase):
|
||||
def test_get_message(self):
|
||||
def total_seconds():
|
||||
return 0.1
|
||||
|
||||
request = mock.Mock()
|
||||
elapsed = mock.Mock()
|
||||
request.elapsed = elapsed
|
||||
elapsed.total_seconds = total_seconds
|
||||
|
||||
assert self.expectation.get_message(request) == ('Latency above '
|
||||
'threshold: 0.1000 seconds')
|
||||
'threshold: 0.1000 seconds')
|
||||
|
||||
|
||||
class HttpStatusTest(unittest.TestCase):
|
||||
@@ -69,7 +73,7 @@ class HttpStatusTest(unittest.TestCase):
|
||||
request.status_code = 400
|
||||
|
||||
assert self.expectation.get_message(request) == ('Unexpected HTTP '
|
||||
'status (400)')
|
||||
'status (400)')
|
||||
|
||||
|
||||
class RegexTest(unittest.TestCase):
|
||||
@@ -96,4 +100,4 @@ class RegexTest(unittest.TestCase):
|
||||
request.text = 'We will not find it here'
|
||||
|
||||
assert self.expectation.get_message(request) == ('Regex did not match '
|
||||
'anything in the body')
|
||||
'anything in the body')
|
||||
|
||||
Reference in New Issue
Block a user