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


import unittest
#  from unittest.mock import ANY, call, MagicMock, patch, sentinel
from unittest.mock import MagicMock, patch

from conjureup.controllers.newcloud.gui import NewCloudController


class NewCloudGUIRenderTestCase(unittest.TestCase):

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

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

        self.finish_patcher = patch(
            'conjureup.controllers.newcloud.gui.NewCloudController.finish')
        self.mock_finish = self.finish_patcher.start()

        self.view_patcher = patch(
            'conjureup.controllers.newcloud.gui.NewCloudView')
        self.view_patcher.start()
        self.app_patcher = patch(
            'conjureup.controllers.newcloud.gui.app')
        self.mock_app = self.app_patcher.start()
        self.mock_app.ui = MagicMock(name="app.ui")
        self.track_screen_patcher = patch(
            'conjureup.controllers.newcloud.gui.track_screen')
        self.mock_track_screen = self.track_screen_patcher.start()

    def tearDown(self):
        self.utils_patcher.stop()
        self.finish_patcher.stop()
        self.view_patcher.stop()
        self.app_patcher.stop()
        self.track_screen_patcher.stop()

    def test_render(self):
        "call render"
        self.mock_app.current_cloud = 'maas'
        self.controller.render()


class NewCloudGUIFinishTestCase(unittest.TestCase):

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

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

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

        self.render_patcher = patch(
            'conjureup.controllers.newcloud.gui.NewCloudController.render')
        self.mock_render = self.render_patcher.start()
        self.app_patcher = patch(
            'conjureup.controllers.newcloud.gui.app')
        self.mock_app = self.app_patcher.start()
        self.mock_app.ui = MagicMock(name="app.ui")
        self.track_screen_patcher = patch(
            'conjureup.controllers.newcloud.gui.track_screen')
        self.mock_track_screen = self.track_screen_patcher.start()
        self.track_event_patcher = patch(
            'conjureup.controllers.newcloud.gui.track_event')
        self.mock_track_event = self.track_event_patcher.start()

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

    def test_finish(self):
        "call finish"
        self.controller.finish()

@@ -399,32 +399,202 @@
 udController()%0A%0A
+        self.controllers_patcher = patch(%0A            'conjureup.controllers.newcloud.gui.controllers')%0A        self.mock_controllers = self.controllers_patcher.start()%0A%0A
         self.uti
@@ -605,32 +605,32 @@
 atcher = patch(%0A
-
             'con
@@ -1205,32 +1205,246 @@
 (name=%22app.ui%22)%0A
+        self.juju_patcher = patch(%0A            'conjureup.controllers.newcloud.gui.juju'%0A        )%0A        self.mock_juju = self.juju_patcher.start()%0A        self.mock_juju.get_cloud.return_value = %7B'type': 'lxd'%7D%0A
         self.tra
@@ -1751,32 +1751,65 @@
 _patcher.stop()%0A
+        self.juju_patcher.stop()%0A
         self.tra
@@ -1905,66 +1905,423 @@
 ock_
-app.current_cloud = 'maas'%0A        self.controller.render(
+utils.lxd_has_ipv6.return_value = False%0A        self.controller.render()%0A        self.mock_controllers.use.assert_called_once_with('deploy')%0A%0A    def test_render_lxdsetup_with_ipv6(self):%0A        %22call render and access lxdsetup controller if ipv6 enabled%22%0A        self.mock_utils.lxd_has_ipv6.return_value = True%0A        self.controller.render()%0A        self.mock_controllers.use.assert_called_once_with('lxdsetup'
 )%0A%0A%0A

Update tests