Mock the right object

This commit is contained in:
Pedro Algarvio 2014-11-20 02:57:04 +00:00
parent 862fa2706f
commit 8ecd85edcc

View File

@ -1,17 +1,14 @@
# -*- 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
from salttesting import skipIf, TestCase
from salttesting.helpers import ensure_in_syspath
from salttesting.mock import NO_MOCK, NO_MOCK_REASON, Mock, patch
from salt.modules import nginx
ensure_in_syspath('../../')
# Import Salt Module
from salt.modules import nginx
MOCK_STATUS_OUTPUT = """Active connections: 7
server accepts handled requests
46756 46756 89318
@ -31,10 +28,10 @@ class MockUrllibStatus(object):
@patch('salt.utils.which', Mock(return_value='/usr/bin/nginx'))
class NginxTestCase(TestCase):
@patch('urlopen', Mock(return_value=MockUrllibStatus()))
@patch('salt.modules.nginx._urlopen', Mock(return_value=MockUrllibStatus()))
def test_nginx_status(self):
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, {
'active connections': 7,
'accepted': 46756,
@ -45,11 +42,11 @@ class NginxTestCase(TestCase):
'waiting': 0,
})
@patch('urlopen', Mock(return_value=MockUrllibStatus()))
@patch('salt.modules.nginx._urlopen', Mock(return_value=MockUrllibStatus()))
def test_nginx_status_with_arg(self):
other_path = 'http://localhost/path'
result = nginx.status(other_path)
urlopen.assert_called_once_with(other_path)
nginx._urlopen.assert_called_once_with(other_path)
if __name__ == '__main__':