From 5cbfe8b851f6ac5d904602d8e55192d659ac5b19 Mon Sep 17 00:00:00 2001 From: Tingirica Robert Date: Thu, 10 Apr 2014 17:19:28 +0300 Subject: [PATCH] Removed static values from plugins tests Replaced assertions with the value codes for execution from plugins/base.py and removed mock for WMI method in osutils module windows.py --- cloudbaseinit/tests/osutils/test_windows.py | 1 - cloudbaseinit/tests/plugins/windows/test_networkconfig.py | 3 ++- cloudbaseinit/tests/plugins/windows/test_sshpublickeys.py | 4 +++- .../tests/plugins/windows/test_winrmcertificateauth.py | 8 +++++--- cloudbaseinit/tests/plugins/windows/test_winrmlistener.py | 6 ++++-- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/cloudbaseinit/tests/osutils/test_windows.py b/cloudbaseinit/tests/osutils/test_windows.py index 972c4431..4a55cc8f 100644 --- a/cloudbaseinit/tests/osutils/test_windows.py +++ b/cloudbaseinit/tests/osutils/test_windows.py @@ -402,7 +402,6 @@ class WindowsUtilsTest(unittest.TestCase): @mock.patch('ctypes.windll.kernel32.SetComputerNameExW') def _test_set_host_name(self, mock_SetComputerNameExW, ret_value): - wmi.WMI = mock.MagicMock(return_value=self._conn) mock_SetComputerNameExW.return_value = ret_value if not ret_value: self.assertRaises(Exception, self._winutils.set_host_name, diff --git a/cloudbaseinit/tests/plugins/windows/test_networkconfig.py b/cloudbaseinit/tests/plugins/windows/test_networkconfig.py index 12183654..244dba56 100644 --- a/cloudbaseinit/tests/plugins/windows/test_networkconfig.py +++ b/cloudbaseinit/tests/plugins/windows/test_networkconfig.py @@ -20,6 +20,7 @@ import unittest from oslo.config import cfg +from cloudbaseinit.plugins import base from cloudbaseinit.plugins.windows import networkconfig from cloudbaseinit.tests.metadata import fake_json_response @@ -67,7 +68,7 @@ class NetworkConfigPluginPluginTests(unittest.TestCase): search_result.group('broadcast'), search_result.group('gateway'), search_result.group('dnsnameservers').strip().split(' ')) - self.assertEqual(response, (1, False)) + self.assertEqual(response, (base.PLUGIN_EXECUTION_DONE, False)) def test_execute(self): m = mock.MagicMock() diff --git a/cloudbaseinit/tests/plugins/windows/test_sshpublickeys.py b/cloudbaseinit/tests/plugins/windows/test_sshpublickeys.py index cd22edab..68fc4307 100644 --- a/cloudbaseinit/tests/plugins/windows/test_sshpublickeys.py +++ b/cloudbaseinit/tests/plugins/windows/test_sshpublickeys.py @@ -20,6 +20,7 @@ import unittest from oslo.config import cfg +from cloudbaseinit.plugins import base from cloudbaseinit.plugins.windows import sshpublickeys from cloudbaseinit.tests.metadata import fake_json_response @@ -61,7 +62,8 @@ class SetUserSSHPublicKeysPluginTests(unittest.TestCase): self.assertEqual(mock_os_path.join.call_count, 2) mock_os_makedirs.assert_called_once_with(mock_os_path.join()) - self.assertEqual(response, (1, False)) + self.assertEqual(response, (base.PLUGIN_EXECUTION_DONE, + False)) def test_execute_with_user_home(self): fake_user_home = os.path.join('fake', 'home') diff --git a/cloudbaseinit/tests/plugins/windows/test_winrmcertificateauth.py b/cloudbaseinit/tests/plugins/windows/test_winrmcertificateauth.py index 18df1250..650c4b7d 100644 --- a/cloudbaseinit/tests/plugins/windows/test_winrmcertificateauth.py +++ b/cloudbaseinit/tests/plugins/windows/test_winrmcertificateauth.py @@ -19,9 +19,11 @@ import mock import sys import unittest -from oslo.config import cfg +from cloudbaseinit.plugins import base from cloudbaseinit.plugins import constants +from oslo.config import cfg + CONF = cfg.CONF _ctypes_mock = mock.MagicMock() _win32com_mock = mock.MagicMock() @@ -88,7 +90,7 @@ class ConfigWinRMCertificateAuthPluginTests(unittest.TestCase): shared_data='fake data') mock_service.get_client_auth_certs.assert_called_once_with() if not cert_data: - self.assertEqual(response, (1, False)) + self.assertEqual(response, (base.PLUGIN_EXECUTION_DONE, False)) else: mock_get_credentials.assert_called_once_with('fake data') mock_import_cert.assert_called_once_with( @@ -103,7 +105,7 @@ class ConfigWinRMCertificateAuthPluginTests(unittest.TestCase): mock_WinRMConfig().create_cert_mapping.assert_called_once_with( mock_cert_thumprint, cert_upn, 'fake user', 'fake password') - self.assertEqual(response, (1, False)) + self.assertEqual(response, (base.PLUGIN_EXECUTION_DONE, False)) def test_execute(self): cert_data = 'fake cert data' diff --git a/cloudbaseinit/tests/plugins/windows/test_winrmlistener.py b/cloudbaseinit/tests/plugins/windows/test_winrmlistener.py index 863b881b..5ec5b08b 100644 --- a/cloudbaseinit/tests/plugins/windows/test_winrmlistener.py +++ b/cloudbaseinit/tests/plugins/windows/test_winrmlistener.py @@ -19,6 +19,7 @@ import mock import sys import unittest +from cloudbaseinit.plugins import base from oslo.config import cfg CONF = cfg.CONF @@ -97,7 +98,8 @@ class ConfigWinRMListenerPluginTests(unittest.TestCase): mock_check_winrm_service.assert_called_once_with(mock_osutils) if not service_status: - self.assertEqual(response, (2, False)) + self.assertEqual(response, (base.PLUGIN_EXECUTE_ON_NEXT_BOOT, + service_status)) else: mock_WinRMConfig().set_auth_config.assert_called_once_with( basic=CONF.winrm_enable_basic_auth) @@ -113,7 +115,7 @@ class ConfigWinRMListenerPluginTests(unittest.TestCase): mock_listener_config.get.assert_called_once_with("Port") mock_osutils.firewall_create_rule.assert_called_once_with( "WinRM HTTPS", 9999, mock_osutils.PROTOCOL_TCP) - self.assertEqual(response, (1, False)) + self.assertEqual(response, (base.PLUGIN_EXECUTION_DONE, False)) def test_execute(self): self._test_execute(service_status=True)