77
class FakeAreYouSure(object):
83
def __init__(self, *args, **kwargs):
84
self.args = (args, kwargs)
87
"""Fake showing the dialog."""
88
return self.result # Means reject
75
91
class MainWindowTestCase(BaseTestCase):
76
92
"""Test the qt main window."""
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()
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,
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
108
126
def test_start_control_panel_on_finishing(self):
109
"""If done is called with result=1, the control panel
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'],), {}))
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.
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)
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)
146
self.ui.done(result=0)
147
self.assertEqual(self.ui.isVisible(), True)
149
def test_later_accepts_cancel(self):
150
"""Clicking 'Later' accepts cancellation."""
151
gui.AreYouSure.result = 0
153
self.ui.done(result=0)
154
self.assertEqual(self.ui.isVisible(), False)
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)
139
170
congrats_page.ui.progressContainer.isVisible(), True)
141
172
def test_sync_later_hides_message(self):
142
"""If the user selects 'Sync Later' the congrats page
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)
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
426
setup_account.BAD % setup_account.EMPTY_NAME)
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
441
setup_account.BAD % setup_account.EMPTY_NAME)
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
467
setup_account.BAD % setup_account.INVALID_EMAIL)
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
507
setup_account.BAD % setup_account.EMAIL_MATCH)
484
510
def test_short_password(self):