~ralsina/ubuntuone-windows-installer/not-compressed

« back to all changes in this revision

Viewing changes to ubuntuone_installer/gui/qt/tests/test_gui.py

  • Committer: Tarmac
  • Author(s): ralsina
  • Date: 2011-07-08 19:30:57 UTC
  • mfrom: (12.4.23 fix_805290)
  • Revision ID: tarmac-20110708193057-fhp263mvq2tbbsce
Add the "Are you sure" dialog to be displayed on cancellation, as requested by design.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
from ubuntuone_installer.gui.qt import local_folders
41
41
from ubuntuone_installer.gui.qt import setup_account
42
42
from ubuntuone_installer.gui.qt.ui import (
43
 
    setup_account_ui
 
43
    setup_account_ui,
44
44
)
45
45
 
46
46
 
52
52
 
53
53
 
54
54
class FakeCredentials(object):
 
55
 
55
56
    """A very dummy Credentials object."""
56
57
 
57
58
    def __init__(self, *a, **kw):
60
61
 
61
62
 
62
63
class FakeController(object):
 
64
 
63
65
    """A fake controller for the tests."""
64
66
 
65
67
    def __init__(self, *args, **kwargs):
72
74
    is_fake = True
73
75
 
74
76
 
 
77
class FakeAreYouSure(object):
 
78
 
 
79
    """A fake Dialog."""
 
80
 
 
81
    result = 0
 
82
 
 
83
    def __init__(self, *args, **kwargs):
 
84
        self.args = (args, kwargs)
 
85
 
 
86
    def exec_(self):
 
87
        """Fake showing the dialog."""
 
88
        return self.result  # Means reject
 
89
 
 
90
 
75
91
class MainWindowTestCase(BaseTestCase):
76
92
    """Test the qt main window."""
77
93
 
89
105
        self.patch(gui, "SuccessController", FakeController)
90
106
        self.patch(gui, "ForgottenPasswordController", FakeController)
91
107
        self.patch(gui, "ResetPasswordController", FakeController)
92
 
        self.patch(gui, "ResetPasswordController", FakeController)
 
108
        self.patch(gui, "AreYouSure", FakeAreYouSure)
93
109
        super(MainWindowTestCase, self).setUp()
94
110
 
95
111
    def test_done_calls_custom_close_callback(self):
96
112
        """When closing the window, close_callback is called."""
 
113
        gui.AreYouSure.result = 0
97
114
        self.ui.close_callback = self._set_called
98
115
        self.ui.done(result=0)
99
116
        self.assertEqual(self._called,
101
118
 
102
119
    def test_close_callback_can_be_none(self):
103
120
        """The close_callback can be None."""
 
121
        gui.AreYouSure.result = 0
104
122
        self.ui.close_callback = None
105
123
        self.ui.done(result=0)
106
124
        # world did not explode
107
125
 
108
126
    def test_start_control_panel_on_finishing(self):
109
 
        """If done is called with result=1, the control panel
110
 
        should be called.
111
 
        """
 
127
        """Calling done with result=1, the control panel should be called."""
 
128
        gui.AreYouSure.result = 0
112
129
        self.patch(gui.subprocess, "Popen", self._set_called)
113
130
        self.ui.done(result=1)
114
131
        self.assertEqual(self._called,
115
132
            ((['ubuntuone-control-panel-qt'],), {}))
116
133
 
117
134
    def test_not_start_control_panel_on_cancel(self):
118
 
        """If done is called with result=0, the control panel
119
 
        should NOT be called.
120
 
        """
 
135
        """Called done with result=0, control panel should NOT be called."""
 
136
        gui.AreYouSure.result = 0
121
137
        self.patch(gui.subprocess, "Popen", self._set_called)
122
138
        self.ui.done(result=0)
123
139
        self.assertEqual(self._called, False)
124
140
 
 
141
    def test_continue_cancels_cancel(self):
 
142
        """Clicking 'Continue' cancels cancellation."""
 
143
        gui.AreYouSure.result = 1
 
144
        self.patch(gui.subprocess, "Popen", self._set_called)
 
145
        self.ui.show()
 
146
        self.ui.done(result=0)
 
147
        self.assertEqual(self.ui.isVisible(), True)
 
148
 
 
149
    def test_later_accepts_cancel(self):
 
150
        """Clicking 'Later' accepts cancellation."""
 
151
        gui.AreYouSure.result = 0
 
152
        self.ui.show()
 
153
        self.ui.done(result=0)
 
154
        self.assertEqual(self.ui.isVisible(), False)
 
155
 
125
156
    def test_sync_now_shows_message(self):
126
 
        """If the user selects 'Sync Now' the congrats page shows a message"""
 
157
        """If the user selects 'Sync Now' the congrats page shows a message."""
127
158
        congrats_page = self.ui.page(self.ui.CONGRATULATIONS_PAGE)
128
159
        congrats_page.setField("sync_now", True)
129
160
 
139
170
            congrats_page.ui.progressContainer.isVisible(), True)
140
171
 
141
172
    def test_sync_later_hides_message(self):
142
 
        """If the user selects 'Sync Later' the congrats page
143
 
        hides a message"""
 
173
        """Selecting 'Sync Later' the congrats page hides a message."""
144
174
        congrats_page = self.ui.page(self.ui.CONGRATULATIONS_PAGE)
145
175
        congrats_page.setField("sync_later", True)
146
176
 
393
423
        self.assertEqual(self.ui.ui.name_assistance.isVisible(), True)
394
424
        self.assertEqual(
395
425
            unicode(self.ui.ui.name_assistance.text()),
396
 
            setup_account.BAD % setup_account.EMPTY_NAME
397
 
        )
 
426
            setup_account.BAD % setup_account.EMPTY_NAME)
398
427
        self.ui.hide()
399
428
 
400
429
    def test_blank_name(self):
409
438
        self.assertEqual(self.ui.ui.name_assistance.isVisible(), True)
410
439
        self.assertEqual(
411
440
            unicode(self.ui.ui.name_assistance.text()),
412
 
            setup_account.BAD % setup_account.EMPTY_NAME
413
 
        )
 
441
            setup_account.BAD % setup_account.EMPTY_NAME)
414
442
        self.ui.hide()
415
443
 
416
444
    def test_valid_name(self):
436
464
        self.assertEqual(self.ui.ui.email_assistance.isVisible(), True)
437
465
        self.assertEqual(
438
466
            unicode(self.ui.ui.email_assistance.text()),
439
 
            setup_account.BAD % setup_account.INVALID_EMAIL
440
 
        )
 
467
            setup_account.BAD % setup_account.INVALID_EMAIL)
441
468
        self.ui.hide()
442
469
 
443
470
    def test_valid_email(self):
477
504
        self.assertEqual(self.ui.ui.confirm_email_assistance.isVisible(), True)
478
505
        self.assertEqual(
479
506
            unicode(self.ui.ui.confirm_email_assistance.text()),
480
 
            setup_account.BAD % setup_account.EMAIL_MATCH
481
 
        )
 
507
            setup_account.BAD % setup_account.EMAIL_MATCH)
482
508
        self.ui.hide()
483
509
 
484
510
    def test_short_password(self):