From 43bdf9debe5377216aed0086bff2aad864f6ba82 Mon Sep 17 00:00:00 2001 From: Ɓukasz 'sil2100' Zemczak Date: Mon, 3 Jul 2017 13:44:00 +0200 Subject: Import patches-unapplied version 2.2.14-0ubuntu1 to ubuntu/artful-proposed Imported using git-ubuntu import. Changelog parent: 4fb0b5a09b26135ade285844da5d7dfe582a8d4c New changelog entries: * New upstream release (LP: #1701350). * debian/copyright: - Refreshed copyright content. --- tests/pa/test_deprovision.py | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'tests/pa') diff --git a/tests/pa/test_deprovision.py b/tests/pa/test_deprovision.py index c4cd9b4..b2f7f0c 100644 --- a/tests/pa/test_deprovision.py +++ b/tests/pa/test_deprovision.py @@ -15,6 +15,7 @@ # Requires Python 2.4+ and Openssl 1.0+ # +import signal import tempfile import azurelinuxagent.common.utils.fileutil as fileutil @@ -25,16 +26,44 @@ from tests.tools import * class TestDeprovision(AgentTestCase): + @patch('signal.signal') + @patch('azurelinuxagent.common.osutil.get_osutil') + @patch('azurelinuxagent.common.protocol.get_protocol_util') + @patch('azurelinuxagent.pa.deprovision.default.read_input') + def test_confirmation(self, + mock_read, mock_protocol, mock_util, mock_signal): + dh = DeprovisionHandler() + + dh.setup = Mock() + dh.setup.return_value = ([], []) + dh.do_actions = Mock() + + # Do actions if confirmed + mock_read.return_value = "y" + dh.run() + self.assertEqual(1, dh.do_actions.call_count) + + # Skip actions if not confirmed + mock_read.return_value = "n" + dh.run() + self.assertEqual(1, dh.do_actions.call_count) + + # Do actions if forced + mock_read.return_value = "n" + dh.run(force=True) + self.assertEqual(2, dh.do_actions.call_count) + @patch("azurelinuxagent.pa.deprovision.default.DeprovisionHandler.cloud_init_dirs") @patch("azurelinuxagent.pa.deprovision.default.DeprovisionHandler.cloud_init_files") def test_del_cloud_init_without_once(self, mock_files, mock_dirs): deprovision_handler = get_deprovision_handler("","","") - deprovision_handler.del_cloud_init([], [], include_once=False) + deprovision_handler.del_cloud_init([], [], + include_once=False, deluser=False) mock_dirs.assert_called_with(include_once=False) - mock_files.assert_called_with(include_once=False) + mock_files.assert_called_with(include_once=False, deluser=False) @patch("signal.signal") @patch("azurelinuxagent.common.protocol.get_protocol_util") @@ -59,10 +88,11 @@ class TestDeprovision(AgentTestCase): mock_files.return_value = files deprovision_handler = get_deprovision_handler("","","") - deprovision_handler.del_cloud_init(warnings, actions) + deprovision_handler.del_cloud_init(warnings, actions, + deluser=True) mock_dirs.assert_called_with(include_once=True) - mock_files.assert_called_with(include_once=True) + mock_files.assert_called_with(include_once=True, deluser=True) self.assertEqual(len(warnings), 0) self.assertEqual(len(actions), 2) -- cgit v1.2.3