# Path: conjureup/controllers/juju/deploy/gui.py
# class DeployController:
#     def render(self):
#         """ Render deploy status view
#         """
#         view = DeployStatusView()
#         view.show()
# 
#         app.loop.create_task(common.do_deploy(view.set_footer))
#         app.loop.create_task(self._refresh(view))
#         app.loop.create_task(self._wait_for_applications(view))
# 
#     async def _refresh(self, view):
#         applications = sorted(app.current_bundle.applications,
#                               key=attrgetter('name'))
#         await events.ModelConnected.wait()
#         while not events.ModelSettled.is_set():
#             if events.Error.is_set():
#                 # deploy or wait_for_apps task failed, so stop refreshing
#                 # (the error screen will be shown instead)
#                 return
#             view.refresh_nodes(self._build_view_data(applications))
#             await asyncio.sleep(1)
# 
#     def _build_view_data(self, applications):
#         view_data = {}
#         for service in applications:
#             units = {}
#             view_data[service.name] = {'units': units}
#             num_units = service.num_units
#             if service.name in app.juju.client.applications:
#                 juju_app = app.juju.client.applications[service.name]
#                 num_units = max(service.num_units, len(juju_app.units))
#             else:
#                 juju_app = None
#             for unit_num in range(num_units):
#                 if juju_app and len(juju_app.units) > unit_num:
#                     unit = juju_app.units[unit_num]
#                     name = unit.name
#                     public_address = unit.public_address
#                     machine = unit.machine_id
#                     agent_status = unit.agent_status
#                     agent_info = unit.agent_status_message
#                     workload_status = unit.workload_status
#                     workload_info = unit.workload_status_message
#                 else:
#                     # fill out with placeholder so that the units are
#                     # always visible, even if they're not in the model yet
#                     name = '{}/{}'.format(service.name, unit_num)
#                     public_address = ''
#                     machine = ''
#                     agent_status = ''
#                     agent_info = ''
#                     workload_status = ''
#                     workload_info = ''
#                 units.update({
#                     name: {
#                         'public-address': public_address,
#                         'machine': machine,
#                         'agent-status': {
#                             'status': agent_status,
#                             'info': agent_info,
#                         },
#                         'workload-status': {
#                             'status': workload_status,
#                             'info': workload_info,
#                         },
#                     }
#                 })
#         return view_data
# 
#     async def _wait_for_applications(self, view):
#         await common.wait_for_applications(view.set_footer)
#         controllers.use('runsteps').render()


import unittest
from unittest.mock import MagicMock, patch
from conjureup.controllers.juju.deploy.gui import DeployController
#!/usr/bin/env python
#
# tests controllers/deploy/gui.py
#
# Copyright 2016, 2017 Canonical, Ltd.





class DeployGUIRenderTestCase(unittest.TestCase):
    def setUp(self):
        self.view_patcher = patch(
            'conjureup.controllers.juju.deploy.gui.DeployStatusView')
        self.view_patcher.start()
        self.app_patcher = patch(
            'conjureup.controllers.juju.deploy.gui.app')
        self.mock_app = self.app_patcher.start()

        self.controller = DeployController()
        self.controller._wait_for_applications = MagicMock()
        self.controller._refresh = MagicMock()
        self.common_patcher = patch(
            'conjureup.controllers.juju.deploy.gui.common')
        self.mock_common = self.common_patcher.start()


# Path: conjureup/controllers/juju/deploy/gui.py
# class DeployController:
#     def render(self):
#         """ Render deploy status view
#         """
#         view = DeployStatusView()
#         view.show()
# 
#         app.loop.create_task(common.do_deploy(view.set_footer))
#         app.loop.create_task(self._refresh(view))
#         app.loop.create_task(self._wait_for_applications(view))
# 
#     async def _refresh(self, view):
#         applications = sorted(app.current_bundle.applications,
#                               key=attrgetter('name'))
#         await events.ModelConnected.wait()
#         while not events.ModelSettled.is_set():
#             if events.Error.is_set():
#                 # deploy or wait_for_apps task failed, so stop refreshing
#                 # (the error screen will be shown instead)
#                 return
#             view.refresh_nodes(self._build_view_data(applications))
#             await asyncio.sleep(1)
# 
#     def _build_view_data(self, applications):
#         view_data = {}
#         for service in applications:
#             units = {}
#             view_data[service.name] = {'units': units}
#             num_units = service.num_units
#             if service.name in app.juju.client.applications:
#                 juju_app = app.juju.client.applications[service.name]
#                 num_units = max(service.num_units, len(juju_app.units))
#             else:
#                 juju_app = None
#             for unit_num in range(num_units):
#                 if juju_app and len(juju_app.units) > unit_num:
#                     unit = juju_app.units[unit_num]
#                     name = unit.name
#                     public_address = unit.public_address
#                     machine = unit.machine_id
#                     agent_status = unit.agent_status
#                     agent_info = unit.agent_status_message
#                     workload_status = unit.workload_status
#                     workload_info = unit.workload_status_message
#                 else:
#                     # fill out with placeholder so that the units are
#                     # always visible, even if they're not in the model yet
#                     name = '{}/{}'.format(service.name, unit_num)
#                     public_address = ''
#                     machine = ''
#                     agent_status = ''
#                     agent_info = ''
#                     workload_status = ''
#                     workload_info = ''
#                 units.update({
#                     name: {
#                         'public-address': public_address,
#                         'machine': machine,
#                         'agent-status': {
#                             'status': agent_status,
#                             'info': agent_info,
#                         },
#                         'workload-status': {
#                             'status': workload_status,
#                             'info': workload_info,
#                         },
#                     }
#                 })
#         return view_data
# 
#     async def _wait_for_applications(self, view):
#         await common.wait_for_applications(view.set_footer)
#         controllers.use('runsteps').render()


# Path: test/controllers_juju/test_controllers_deploy_gui.py
import unittest
from unittest.mock import MagicMock, patch
from conjureup.controllers.juju.deploy.gui import DeployController

#!/usr/bin/env python
#
# tests controllers/deploy/gui.py
#
# Copyright 2016, 2017 Canonical, Ltd.





class DeployGUIRenderTestCase(unittest.TestCase):
    def setUp(self):
        self.view_patcher = patch(
            'conjureup.controllers.juju.deploy.gui.DeployStatusView')
        self.view_patcher.start()
        self.app_patcher = patch(
            'conjureup.controllers.juju.deploy.gui.app')
        self.mock_app = self.app_patcher.start()

        self.controller = DeployController()
        self.controller._wait_for_applications = MagicMock()
        self.controller._refresh = MagicMock()
        self.common_patcher = patch(
            'conjureup.controllers.juju.deploy.gui.common')
        self.mock_common = self.common_patcher.start()


    def tearDown(self):