Fixing failing test. Using @mock.path decorator, instead of overriding the sys.modules.

This commit is contained in:
Mitsuo Takaki
2016-05-19 08:26:18 -07:00
parent ca358eab2b
commit a83abfd1d3
4 changed files with 35 additions and 22 deletions
+10 -6
View File
@@ -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')