def test_validate_set_alarm_in(self): """ Validate set_alarm_in called with eventloop """ dc = Controller(ui=self.mock_ui, config=self.conf, loop=self.mock_loop) dc.initialize = MagicMock() self.conf.node_install_wait_interval = 1 dc.update(self.conf.node_install_wait_interval, ANY) self.mock_loop.set_alarm_in.assert_called_once_with(1, ANY)
def test_validate_redraw_screen_commit_placement(self): """ Validate redraw_screen on commit_placement """ self.conf.setopt('headless', False) dc = Controller(ui=self.mock_ui, config=self.conf, loop=self.mock_loop) dc.initialize = MagicMock() dc.commit_placement() self.mock_loop.redraw_screen.assert_called_once_with()
def test_validate_redraw_screen_enqueue(self): """ Validate redraw_screen on enqueue_deployed_charms """ self.conf.setopt('headless', False) dc = Controller(ui=self.mock_ui, config=self.conf, loop=self.mock_loop) dc.initialize = MagicMock() dc.enqueue_deployed_charms() self.mock_loop.redraw_screen.assert_called_once_with()
def test_hotkey_exit(self): ev = self.make_ev() dc = Controller(ui=self.mock_ui, config=self.conf, loop=ev) dc.initialize = MagicMock() with self.assertRaises(urwid.ExitMainLoop): dc.loop.header_hotkeys('q') self.assertEqual(ev.error_code, 0)
def test_validate_loop(self): """ Validate eventloop runs """ self.conf.setopt('headless', False) dc = Controller(ui=self.mock_ui, config=self.conf, loop=self.mock_loop) dc.initialize = MagicMock() dc.start() self.mock_loop.run.assert_called_once_with()
def test_validate_exit(self): """ Validate error code set with eventloop """ ev = self.make_ev() dc = Controller(ui=self.mock_ui, config=self.conf, loop=ev) dc.initialize = MagicMock() with self.assertRaises(urwid.ExitMainLoop): dc.loop.exit(1) self.assertEqual(ev.error_code, 1)
def test_repr_ev(self): """ Prints appropriate class string for eventloop """ ev = self.make_ev() dc = Controller( ui=self.mock_ui, config=self.conf, loop=ev) dc.initialize = MagicMock() self.assertEqual(str(ev), '<eventloop urwid based on select()>')
def test_repr_no_ev(self): """ Prints appropriate class string for no eventloop """ ev = self.make_ev(True) dc = Controller( ui=self.mock_ui, config=self.conf, loop=ev) dc.initialize = MagicMock() self.assertEqual(str(ev), '<eventloop disabled>')
def test_validate_exit_no_ev(self): """ Validate SystemExit with no eventloop """ ev = self.make_ev(True) dc = Controller(ui=self.mock_ui, config=self.conf, loop=ev) dc.initialize = MagicMock() with self.assertRaises(SystemExit) as cm: dc.loop.exit(1) exc = cm.exception self.assertEqual(ev.error_code, exc.code, "Found loop")
def test_hotkey_exit(self): ev = self.make_ev() dc = Controller( ui=self.mock_ui, config=self.conf, loop=ev) dc.initialize = MagicMock() with self.assertRaises(urwid.ExitMainLoop): dc.loop.header_hotkeys('q') self.assertEqual(ev.error_code, 0)
def test_validate_redraw_screen_enqueue(self): """ Validate redraw_screen on enqueue_deployed_charms """ self.conf.setopt('headless', False) dc = Controller( ui=self.mock_ui, config=self.conf, loop=self.mock_loop) dc.initialize = MagicMock() dc.enqueue_deployed_charms() self.mock_loop.redraw_screen.assert_called_once_with()
def test_validate_set_alarm_in(self): """ Validate set_alarm_in called with eventloop """ dc = Controller( ui=self.mock_ui, config=self.conf, loop=self.mock_loop) dc.initialize = MagicMock() self.conf.node_install_wait_interval = 1 dc.update(self.conf.node_install_wait_interval, ANY) self.mock_loop.set_alarm_in.assert_called_once_with(1, ANY)
def test_validate_loop(self): """ Validate eventloop runs """ self.conf.setopt('headless', False) dc = Controller( ui=self.mock_ui, config=self.conf, loop=self.mock_loop) dc.initialize = MagicMock() dc.start() self.mock_loop.run.assert_called_once_with()
def test_validate_redraw_screen_commit_placement(self): """ Validate redraw_screen on commit_placement """ self.conf.setopt('headless', False) dc = Controller( ui=self.mock_ui, config=self.conf, loop=self.mock_loop) dc.initialize = MagicMock() dc.commit_placement() self.mock_loop.redraw_screen.assert_called_once_with()
def test_validate_exit(self): """ Validate error code set with eventloop """ ev = self.make_ev() dc = Controller( ui=self.mock_ui, config=self.conf, loop=ev) dc.initialize = MagicMock() with self.assertRaises(urwid.ExitMainLoop): dc.loop.exit(1) self.assertEqual(ev.error_code, 1)
def test_validate_exit_no_ev(self): """ Validate SystemExit with no eventloop """ ev = self.make_ev(True) dc = Controller( ui=self.mock_ui, config=self.conf, loop=ev) dc.initialize = MagicMock() with self.assertRaises(SystemExit) as cm: dc.loop.exit(1) exc = cm.exception self.assertEqual(ev.error_code, exc.code, "Found loop")
def setUp(self): self.conf = Config({}) self.mock_ui = MagicMock(name='ui') self.mock_log = MagicMock(name='log') self.mock_loop = MagicMock(name='loop') self.conf.setopt('headless', False) self.dc = Controller( ui=self.mock_ui, config=self.conf, loop=self.mock_loop) self.dc.initialize = MagicMock() self.dc.juju_state = JujuState(juju=MagicMock()) self.dc.juju_state.all_agents_started = MagicMock()
class WaitForDeployedServicesReadyCoreTestCase(unittest.TestCase): """ Tests core.wait_for_deployed_services_ready to make sure waiting for services to start are handled properly. """ def setUp(self): self.conf = Config({}) self.mock_ui = MagicMock(name='ui') self.mock_log = MagicMock(name='log') self.mock_loop = MagicMock(name='loop') self.conf.setopt('headless', False) self.dc = Controller( ui=self.mock_ui, config=self.conf, loop=self.mock_loop) self.dc.initialize = MagicMock() self.dc.juju_state = JujuState(juju=MagicMock()) self.dc.juju_state.all_agents_started = MagicMock() def test_validate_services_ready(self): """ Verifies wait_for_deployed_services_ready time.sleep should not be called here as all services are in a started state. """ self.dc.juju_state.all_agents_started.return_value = True with patch('cloudinstall.core.time.sleep') as mock_sleep: self.dc.wait_for_deployed_services_ready() self.assertEqual(len(mock_sleep.mock_calls), 0) def test_validate_services_some_ready(self): """ Verifies wait_for_deployed_services_ready against some of the services in started state Here we test if time.sleep was called twice due to some services being in an installing and allocating state. """ self.dc.juju_state.all_agents_started.side_effect = [ False, False, True, True] with patch('cloudinstall.core.time.sleep') as mock_sleep: self.dc.wait_for_deployed_services_ready() print(mock_sleep.mock_calls) self.assertEqual(len(mock_sleep.mock_calls), 2)
def setUp(self): self.conf = Config({}, save_backups=False) self.mock_ui = MagicMock(name="ui") self.mock_log = MagicMock(name="log") self.mock_loop = MagicMock(name="loop") self.conf.setopt("headless", False) self.dc = Controller(ui=self.mock_ui, config=self.conf, loop=self.mock_loop) self.dc.initialize = MagicMock() self.dc.juju_state = JujuState(juju=MagicMock()) self.dc.juju_state.all_agents_started = MagicMock()
def test_repr_ev(self): """ Prints appropriate class string for eventloop """ ev = self.make_ev() dc = Controller(ui=self.mock_ui, config=self.conf, loop=ev) dc.initialize = MagicMock() self.assertEqual(str(ev), '<eventloop urwid based on tornado()>')
def test_repr_no_ev(self): """ Prints appropriate class string for no eventloop """ ev = self.make_ev(True) dc = Controller(ui=self.mock_ui, config=self.conf, loop=ev) dc.initialize = MagicMock() self.assertEqual(str(ev), '<eventloop disabled>')