class DeployGUIFinishTestCase(unittest.TestCase):
    def setUp(self):
        with patch.object(DeployController, 'init_machines_assignments'):
            self.controller = DeployController()

        self.controllers_patcher = patch(
            'conjureup.controllers.deploy.gui.controllers')
        self.mock_controllers = self.controllers_patcher.start()

        self.utils_patcher = patch('conjureup.controllers.deploy.gui.utils')
        self.mock_utils = self.utils_patcher.start()

        self.submit_patcher = patch(
            'conjureup.controllers.deploy.gui.async.submit')
        self.mock_submit = self.submit_patcher.start()
        self.mock_submit.return_value = sentinel.a_future

        self.juju_patcher = patch('conjureup.controllers.deploy.gui.juju')
        self.mock_juju = self.juju_patcher.start()

        self.render_patcher = patch(
            'conjureup.controllers.deploy.gui.DeployController.render')
        self.mock_render = self.render_patcher.start()
        self.app_patcher = patch('conjureup.controllers.deploy.gui.app')
        self.mock_app = self.app_patcher.start()
        self.mock_app.ui = MagicMock(name="app.ui")

    def tearDown(self):
        self.controllers_patcher.stop()
        self.utils_patcher.stop()
        self.submit_patcher.stop()
        self.juju_patcher.stop()
        self.render_patcher.stop()
        self.app_patcher.stop()

    def test_show_bootstrap_wait(self):
        "Go to bootstrap wait controller if bootstrap pending"
        self.mock_app.bootstrap = MagicMock(name="bootstrap")
        self.mock_app.bootstrap.running = MagicMock(name='running_future')
        self.mock_app.bootstrap.running.done = MagicMock(name='done')
        self.mock_app.bootstrap.running.done.return_value = False
        self.controller.finish()
        self.assertEqual(1, len(self.mock_submit.mock_calls))
        self.assertEqual(
            self.mock_controllers.mock_calls,
            [call.use('bootstrapwait'),
             call.use().render(sentinel.a_future)])

    def test_skip_bootstrap_wait(self):
        "Go directly to deploystatus if bootstrap is done"
        self.controller.finish()
        self.assertEqual(1, len(self.mock_submit.mock_calls))
        self.assertEqual(self.mock_controllers.mock_calls,
                         [call.use('deploystatus'),
                          call.use().render(ANY)])
class DeployGUIFinishTestCase(unittest.TestCase):

    def setUp(self):
        self.controller = DeployController()

        self.controllers_patcher = patch(
            'conjureup.controllers.deploy.gui.controllers')
        self.mock_controllers = self.controllers_patcher.start()

        self.utils_patcher = patch(
            'conjureup.controllers.deploy.gui.utils')
        self.mock_utils = self.utils_patcher.start()

        self.juju_patcher = patch(
            'conjureup.controllers.deploy.gui.juju')
        self.mock_juju = self.juju_patcher.start()

        self.render_patcher = patch(
            'conjureup.controllers.deploy.gui.DeployController.render')
        self.mock_render = self.render_patcher.start()
        self.app_patcher = patch(
            'conjureup.controllers.deploy.gui.app')
        self.mock_app = self.app_patcher.start()
        self.mock_app.ui = MagicMock(name="app.ui")

    def tearDown(self):
        self.controllers_patcher.stop()
        self.utils_patcher.stop()
        self.juju_patcher.stop()
        self.render_patcher.stop()
        self.app_patcher.stop()

    def test_show_bootstrap_wait(self):
        "Go to bootstrap wait controller if bootstrap pending"
        self.mock_app.bootstrap = MagicMock(name="bootstrap")
        self.mock_app.bootstrap.running = MagicMock(name='running_future')
        self.mock_app.bootstrap.running.done = MagicMock(name='done')
        self.mock_app.bootstrap.running.done.return_value = False
        self.controller.finish()
        self.assertEqual(self.mock_controllers.mock_calls,
                         [call.use('bootstrapwait'),
                          call.use().render()])

    def test_skip_bootstrap_wait(self):
        "Go directly to deploystatus if bootstrap is done"
        self.controller.finish()
        self.assertEqual(self.mock_controllers.mock_calls,
                         [call.use('deploystatus'),
                          call.use().render()])
class DeployGUIFinishTestCase(unittest.TestCase):
    def setUp(self):
        with patch.object(DeployController, 'init_machines_assignments'):
            self.controller = DeployController()

        self.controllers_patcher = patch(
            'conjureup.controllers.deploy.gui.controllers')
        self.mock_controllers = self.controllers_patcher.start()

        self.juju_patcher = patch('conjureup.controllers.deploy.gui.juju')
        self.mock_juju = self.juju_patcher.start()

        self.render_patcher = patch(
            'conjureup.controllers.deploy.gui.DeployController.render')
        self.mock_render = self.render_patcher.start()
        self.watch_patcher = patch(
            'conjureup.controllers.deploy.gui.DeployController'
            '.watch_for_deploy_complete')
        self.watch_patcher.start()
        self.app_patcher = patch('conjureup.controllers.deploy.gui.app')
        self.mock_app = self.app_patcher.start()
        self.mock_app.ui = MagicMock(name="app.ui")
        self.ev_app_patcher = patch('conjureup.events.app', self.mock_app)
        self.ev_app_patcher.start()

        self.common_patcher = patch('conjureup.controllers.deploy.gui.common')
        self.mock_common = self.common_patcher.start()

    def tearDown(self):
        self.controllers_patcher.stop()
        self.juju_patcher.stop()
        self.render_patcher.stop()
        self.watch_patcher.stop()
        self.app_patcher.stop()
        self.ev_app_patcher.stop()

    def test_show_bootstrap_wait(self):
        "Go to bootstrap wait controller if bootstrap pending"
        events.Bootstrapped.clear()
        self.controller.finish()
        self.mock_controllers.use.assert_called_once_with('bootstrapwait')

    def test_skip_bootstrap_wait(self):
        "Go directly to deploystatus if bootstrap is done"
        events.Bootstrapped.set()
        self.controller.finish()
        self.mock_controllers.use.assert_called_once_with('deploystatus')
예제 #4
0
class DeployGUIFinishTestCase(unittest.TestCase):
    def setUp(self):
        self.controller = DeployController()

        self.controllers_patcher = patch(
            'conjureup.controllers.deploy.gui.controllers')
        self.mock_controllers = self.controllers_patcher.start()

        self.utils_patcher = patch('conjureup.controllers.deploy.gui.utils')
        self.mock_utils = self.utils_patcher.start()

        self.juju_patcher = patch('conjureup.controllers.deploy.gui.juju')
        self.mock_juju = self.juju_patcher.start()

        self.render_patcher = patch(
            'conjureup.controllers.deploy.gui.DeployController.render')
        self.mock_render = self.render_patcher.start()
        self.app_patcher = patch('conjureup.controllers.deploy.gui.app')
        self.mock_app = self.app_patcher.start()
        self.mock_app.ui = MagicMock(name="app.ui")

    def tearDown(self):
        self.controllers_patcher.stop()
        self.utils_patcher.stop()
        self.juju_patcher.stop()
        self.render_patcher.stop()
        self.app_patcher.stop()

    def test_deploy_single(self):
        "Deploy a single service in finish"
        self.controller.finish(sentinel.single_service)
        self.assertEqual(
            self.mock_juju.mock_calls,
            [call.deploy_service(sentinel.single_service, ANY, ANY)])
        self.mock_render.assert_called_once_with()
        self.assertEqual(self.mock_controllers.mock_calls, [])

    def test_deploy_rest(self):
        "Deploy multiple services in finish"
        self.controller.services = [sentinel.service_1, sentinel.service_2]
        self.controller.finish()
        self.assertEqual(self.mock_juju.mock_calls, [
            call.deploy_service(sentinel.service_1, ANY, ANY),
            call.deploy_service(sentinel.service_2, ANY, ANY),
            call.set_relations([sentinel.service_1, sentinel.service_2], ANY,
                               ANY)
        ])

    def test_show_bootstrap_wait(self):
        "Go to bootstrap wait controller if bootstrap pending"
        self.mock_app.bootstrap = MagicMock(name="bootstrap")
        self.mock_app.bootstrap.running = MagicMock(name='running_future')
        self.mock_app.bootstrap.running.done = MagicMock(name='done')
        self.mock_app.bootstrap.running.done.return_value = False
        self.controller.finish()
        self.assertEqual(self.mock_controllers.mock_calls,
                         [call.use('bootstrapwait'),
                          call.use().render()])

    def test_skip_bootstrap_wait(self):
        "Go directly to deploystatus if bootstrap is done"
        self.controller.finish()
        self.assertEqual(self.mock_controllers.mock_calls,
                         [call.use('deploystatus'),
                          call.use().render()])
class DeployGUIFinishTestCase(unittest.TestCase):
    def setUp(self):
        self.controller = DeployController()

        self.controllers_patcher = patch(
            'conjureup.controllers.deploy.gui.controllers')
        self.mock_controllers = self.controllers_patcher.start()

        self.utils_patcher = patch(
            'conjureup.controllers.deploy.gui.utils')
        self.mock_utils = self.utils_patcher.start()

        self.juju_patcher = patch(
            'conjureup.controllers.deploy.gui.juju')
        self.mock_juju = self.juju_patcher.start()

        self.render_patcher = patch(
            'conjureup.controllers.deploy.gui.DeployController.render')
        self.mock_render = self.render_patcher.start()
        self.app_patcher = patch(
            'conjureup.controllers.deploy.gui.app')
        self.mock_app = self.app_patcher.start()
        self.mock_app.ui = MagicMock(name="app.ui")

    def tearDown(self):
        self.controllers_patcher.stop()
        self.utils_patcher.stop()
        self.juju_patcher.stop()
        self.render_patcher.stop()
        self.app_patcher.stop()

    def test_deploy_single(self):
        "Deploy a single service in finish"
        self.controller.finish(sentinel.single_service)
        self.assertEqual(self.mock_juju.mock_calls,
                         [call.deploy_service(sentinel.single_service,
                                              ANY, ANY)])
        self.mock_render.assert_called_once_with()
        self.assertEqual(self.mock_controllers.mock_calls, [])

    def test_deploy_rest(self):
        "Deploy multiple services in finish"
        self.controller.services = [sentinel.service_1, sentinel.service_2]
        self.controller.finish()
        self.assertEqual(self.mock_juju.mock_calls,
                         [call.deploy_service(sentinel.service_1, ANY, ANY),
                          call.deploy_service(sentinel.service_2, ANY, ANY),
                          call.set_relations([sentinel.service_1,
                                              sentinel.service_2], ANY, ANY)])

    def test_show_bootstrap_wait(self):
        "Go to bootstrap wait controller if bootstrap pending"
        self.mock_app.bootstrap = MagicMock(name="bootstrap")
        self.mock_app.bootstrap.running = MagicMock(name='running_future')
        self.mock_app.bootstrap.running.done = MagicMock(name='done')
        self.mock_app.bootstrap.running.done.return_value = False
        self.controller.finish()
        self.assertEqual(self.mock_controllers.mock_calls,
                         [call.use('bootstrapwait'),
                          call.use().render()])

    def test_skip_bootstrap_wait(self):
        "Go directly to deploystatus if bootstrap is done"
        self.controller.finish()
        self.assertEqual(self.mock_controllers.mock_calls,
                         [call.use('deploystatus'),
                          call.use().render()])