mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Mock the right object
This commit is contained in:
parent
862fa2706f
commit
8ecd85edcc
@ -1,17 +1,14 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Import 3rd-party libs
|
|
||||||
from salt.ext.six.moves.urllib.request import urlopen # pylint: disable=no-name-in-module,import-error
|
|
||||||
|
|
||||||
# Import Salt Testing libs
|
# Import Salt Testing libs
|
||||||
from salttesting import skipIf, TestCase
|
from salttesting import skipIf, TestCase
|
||||||
from salttesting.helpers import ensure_in_syspath
|
from salttesting.helpers import ensure_in_syspath
|
||||||
from salttesting.mock import NO_MOCK, NO_MOCK_REASON, Mock, patch
|
from salttesting.mock import NO_MOCK, NO_MOCK_REASON, Mock, patch
|
||||||
|
|
||||||
from salt.modules import nginx
|
|
||||||
|
|
||||||
ensure_in_syspath('../../')
|
ensure_in_syspath('../../')
|
||||||
|
|
||||||
|
# Import Salt Module
|
||||||
|
from salt.modules import nginx
|
||||||
|
|
||||||
MOCK_STATUS_OUTPUT = """Active connections: 7
|
MOCK_STATUS_OUTPUT = """Active connections: 7
|
||||||
server accepts handled requests
|
server accepts handled requests
|
||||||
46756 46756 89318
|
46756 46756 89318
|
||||||
@ -31,10 +28,10 @@ class MockUrllibStatus(object):
|
|||||||
@patch('salt.utils.which', Mock(return_value='/usr/bin/nginx'))
|
@patch('salt.utils.which', Mock(return_value='/usr/bin/nginx'))
|
||||||
class NginxTestCase(TestCase):
|
class NginxTestCase(TestCase):
|
||||||
|
|
||||||
@patch('urlopen', Mock(return_value=MockUrllibStatus()))
|
@patch('salt.modules.nginx._urlopen', Mock(return_value=MockUrllibStatus()))
|
||||||
def test_nginx_status(self):
|
def test_nginx_status(self):
|
||||||
result = nginx.status()
|
result = nginx.status()
|
||||||
urlopen.assert_called_once_with('http://127.0.0.1/status')
|
nginx._urlopen.assert_called_once_with('http://127.0.0.1/status')
|
||||||
self.assertEqual(result, {
|
self.assertEqual(result, {
|
||||||
'active connections': 7,
|
'active connections': 7,
|
||||||
'accepted': 46756,
|
'accepted': 46756,
|
||||||
@ -45,11 +42,11 @@ class NginxTestCase(TestCase):
|
|||||||
'waiting': 0,
|
'waiting': 0,
|
||||||
})
|
})
|
||||||
|
|
||||||
@patch('urlopen', Mock(return_value=MockUrllibStatus()))
|
@patch('salt.modules.nginx._urlopen', Mock(return_value=MockUrllibStatus()))
|
||||||
def test_nginx_status_with_arg(self):
|
def test_nginx_status_with_arg(self):
|
||||||
other_path = 'http://localhost/path'
|
other_path = 'http://localhost/path'
|
||||||
result = nginx.status(other_path)
|
result = nginx.status(other_path)
|
||||||
urlopen.assert_called_once_with(other_path)
|
nginx._urlopen.assert_called_once_with(other_path)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user