Merge lp:~mandel/ubuntuone-windows-installer/auto-update-python-only into lp:ubuntuone-windows-installer
- auto-update-python-only
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Roberto Alsina | ||||
Approved revision: | 77 | ||||
Merged at revision: | 73 | ||||
Proposed branch: | lp:~mandel/ubuntuone-windows-installer/auto-update-python-only | ||||
Merge into: | lp:ubuntuone-windows-installer | ||||
Diff against target: |
415 lines (+241/-7) 7 files modified
ubuntuone_installer/gui/qt/gui.py (+11/-0) ubuntuone_installer/gui/qt/main/tests/test_windows.py (+19/-2) ubuntuone_installer/gui/qt/main/windows.py (+29/-5) ubuntuone_installer/gui/qt/tests/test_gui.py (+49/-0) ubuntuone_installer/gui/qt/utils/__init__.py (+4/-0) ubuntuone_installer/gui/qt/utils/tests/test_windows.py (+85/-0) ubuntuone_installer/gui/qt/utils/windows.py (+44/-0) |
||||
To merge this branch: | bzr merge lp:~mandel/ubuntuone-windows-installer/auto-update-python-only | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Roberto Alsina (community) | Approve | ||
Diego Sarmentero (community) | Approve | ||
Review via email:
|
Commit message
Partial fix for lp: 845662
Provides the code that perform a call to the auto-update process that will check for updates and will perform them if the user agrees to do so.
Description of the change
Provides the code that perform a call to the auto-update process that will check for updates and will perform them if the user agrees to do so.
- 72. By Manuel de la Peña
-
Remove named parameter comming from a smart-ass diff.
- 73. By Manuel de la Peña
-
Fixed the tests so that they take into account the new update method.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Roberto Alsina (ralsina) wrote : | # |
C:\Users\
Traceback (most recent call last):
File "ubuntuone-
File "ubuntuone_
File "twisted\
TypeError: check_credentials() takes at most 4 arguments (5 given)
- 74. By Manuel de la Peña
-
Pass the correct number of parameters.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Roberto Alsina (ralsina) wrote : | # |
2011-09-20 09:51:56,575 - ubuntuone.
Unhandled error in Deferred:
Traceback (most recent call last):
File "twisted\
File "twisted\
File "twisted\
File "twisted\
--- <exception caught here> ---
File "twisted\
File "twisted\
File "ubuntuone_
File "twisted\
File "twisted\
File "ubuntuone_
File "twisted\
File "ubuntuone_
File "ubuntuone_
exceptions.
- 75. By Manuel de la Peña
-
Added missing var.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Roberto Alsina (ralsina) wrote : | # |
Unhandled error in Deferred:
Traceback (most recent call last):
File "twisted\
File "twisted\
File "twisted\
File "twisted\
--- <exception caught here> ---
File "twisted\
File "twisted\
File "ubuntuone_
File "twisted\
File "ubuntuone_
File "ubuntuone_
File "twisted\
twisted.
- 76. By Manuel de la Peña
-
Merged with trunk.
- 77. By Manuel de la Peña
-
Removed the stop_fn since there is not need because the installer takes care of the situation in which the files are used.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Roberto Alsina (ralsina) : | # |
Preview Diff
1 | === modified file 'ubuntuone_installer/gui/qt/gui.py' | |||
2 | --- ubuntuone_installer/gui/qt/gui.py 2011-09-19 15:41:40 +0000 | |||
3 | +++ ubuntuone_installer/gui/qt/gui.py 2011-09-22 19:45:30 +0000 | |||
4 | @@ -84,12 +84,23 @@ | |||
5 | 84 | CREDENTIALS_ERROR = _('Application will close.\n\n%r') | 84 | CREDENTIALS_ERROR = _('Application will close.\n\n%r') |
6 | 85 | SKIP_TOUR = _("Skip tour, go to Dashboard") | 85 | SKIP_TOUR = _("Skip tour, go to Dashboard") |
7 | 86 | START_SETUP = _("Start setup") | 86 | START_SETUP = _("Start setup") |
8 | 87 | UPDATE_TITLE = _("Updates are available") | ||
9 | 88 | UPDATE_SOFTWARE = _("There is a new version available. Do you want perform an upgrade?") | ||
10 | 87 | # Invalid name logger | 89 | # Invalid name logger |
11 | 88 | # pylint: disable=C0103 | 90 | # pylint: disable=C0103 |
12 | 89 | logger = setup_logging('qt.gui') | 91 | logger = setup_logging('qt.gui') |
13 | 90 | # pylint: enable=C0103 | 92 | # pylint: enable=C0103 |
14 | 91 | 93 | ||
15 | 92 | 94 | ||
16 | 95 | def user_wants_to_update(): | ||
17 | 96 | """Ask the user if he really wants to update the software.""" | ||
18 | 97 | result = QtGui.QMessageBox.question(None, UPDATE_TITLE, UPDATE_SOFTWARE, | ||
19 | 98 | QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) | ||
20 | 99 | if result == QtGui.QMessageBox.Yes: | ||
21 | 100 | return True | ||
22 | 101 | return False | ||
23 | 102 | |||
24 | 103 | |||
25 | 93 | class LicensePage(SSOWizardPage): | 104 | class LicensePage(SSOWizardPage): |
26 | 94 | """Wizard Page that displays the license info and links to the GPL.""" | 105 | """Wizard Page that displays the license info and links to the GPL.""" |
27 | 95 | 106 | ||
28 | 96 | 107 | ||
29 | === modified file 'ubuntuone_installer/gui/qt/main/tests/test_windows.py' | |||
30 | --- ubuntuone_installer/gui/qt/main/tests/test_windows.py 2011-09-19 23:00:32 +0000 | |||
31 | +++ ubuntuone_installer/gui/qt/main/tests/test_windows.py 2011-09-22 19:45:30 +0000 | |||
32 | @@ -59,22 +59,37 @@ | |||
33 | 59 | """Fake Logger.""" | 59 | """Fake Logger.""" |
34 | 60 | 60 | ||
35 | 61 | error_args = None | 61 | error_args = None |
36 | 62 | debug_args = None | ||
37 | 63 | info_args = None | ||
38 | 62 | 64 | ||
39 | 63 | def error(self, *args, **kwargs): | 65 | def error(self, *args, **kwargs): |
40 | 64 | """Save the error.""" | 66 | """Save the error.""" |
41 | 65 | self.error_args = (args, kwargs) | 67 | self.error_args = (args, kwargs) |
42 | 66 | 68 | ||
43 | 69 | def debug(self, *args, **kwargs): | ||
44 | 70 | """Save the debug.""" | ||
45 | 71 | self.debug_args = (args, kwargs) | ||
46 | 72 | |||
47 | 73 | def info(self, *args, **kwargs): | ||
48 | 74 | """Save the info.""" | ||
49 | 75 | self.info_args = (args, kwargs) | ||
50 | 76 | |||
51 | 67 | 77 | ||
52 | 68 | class CredsFailureMainTestCase(TestCase): | 78 | class CredsFailureMainTestCase(TestCase): |
53 | 69 | 79 | ||
54 | 70 | """Test the qt main window.""" | 80 | """Test the qt main window.""" |
55 | 71 | 81 | ||
56 | 72 | stopped = False | 82 | stopped = False |
57 | 83 | updates_checked = False | ||
58 | 73 | 84 | ||
59 | 74 | def stop(self): | 85 | def stop(self): |
60 | 75 | """A fake stop.""" | 86 | """A fake stop.""" |
61 | 76 | self.stopped = True | 87 | self.stopped = True |
62 | 77 | 88 | ||
63 | 89 | def check_updates(self, gui, logger): | ||
64 | 90 | """A fake check updates.""" | ||
65 | 91 | self.updates_checked = True | ||
66 | 92 | |||
67 | 78 | @defer.inlineCallbacks | 93 | @defer.inlineCallbacks |
68 | 79 | def test_failure(self): | 94 | def test_failure(self): |
69 | 80 | """Credential errors should display a critical message.""" | 95 | """Credential errors should display a critical message.""" |
70 | @@ -116,6 +131,7 @@ | |||
71 | 116 | logger = FakeLogger() | 131 | logger = FakeLogger() |
72 | 117 | self.patch(utils, 'start_control_panel', self._set_called) | 132 | self.patch(utils, 'start_control_panel', self._set_called) |
73 | 118 | self.patch(windows, 'stop', self.stop) | 133 | self.patch(windows, 'stop', self.stop) |
74 | 134 | self.patch(windows, 'check_updates', self.check_updates) | ||
75 | 119 | self.stopped = False | 135 | self.stopped = False |
76 | 120 | yield windows.check_credentials( | 136 | yield windows.check_credentials( |
77 | 121 | FakeCredentialsManagementTool, | 137 | FakeCredentialsManagementTool, |
78 | @@ -126,6 +142,7 @@ | |||
79 | 126 | self.assertEqual(self._called, ((), {'with_icon': False})) | 142 | self.assertEqual(self._called, ((), {'with_icon': False})) |
80 | 127 | # Should stop the app | 143 | # Should stop the app |
81 | 128 | self.assertTrue(self.stopped) | 144 | self.assertTrue(self.stopped) |
82 | 145 | self.assertTrue(self.updates_checked) | ||
83 | 129 | 146 | ||
84 | 130 | @defer.inlineCallbacks | 147 | @defer.inlineCallbacks |
85 | 131 | def test_without_installed_flag(self): | 148 | def test_without_installed_flag(self): |
86 | @@ -136,7 +153,7 @@ | |||
87 | 136 | FakeCredentialsManagementTool, | 153 | FakeCredentialsManagementTool, |
88 | 137 | gui, logger) | 154 | gui, logger) |
89 | 138 | self.assertEqual(self._called, (('Something not false', | 155 | self.assertEqual(self._called, (('Something not false', |
91 | 139 | gui, False), {})) | 156 | gui, False, logger), {})) |
92 | 140 | 157 | ||
93 | 141 | @defer.inlineCallbacks | 158 | @defer.inlineCallbacks |
94 | 142 | def test_with_installed_flag(self): | 159 | def test_with_installed_flag(self): |
95 | @@ -147,4 +164,4 @@ | |||
96 | 147 | FakeCredentialsManagementTool, | 164 | FakeCredentialsManagementTool, |
97 | 148 | gui, logger, installer=True) | 165 | gui, logger, installer=True) |
98 | 149 | self.assertEqual(self._called, (('Something not false', | 166 | self.assertEqual(self._called, (('Something not false', |
100 | 150 | gui, True), {})) | 167 | gui, True, logger), {})) |
101 | 151 | 168 | ||
102 | === modified file 'ubuntuone_installer/gui/qt/main/windows.py' | |||
103 | --- ubuntuone_installer/gui/qt/main/windows.py 2011-09-19 23:00:32 +0000 | |||
104 | +++ ubuntuone_installer/gui/qt/main/windows.py 2011-09-22 19:45:30 +0000 | |||
105 | @@ -29,6 +29,7 @@ | |||
106 | 29 | # pylint: disable=W0611 | 29 | # pylint: disable=W0611 |
107 | 30 | from ubuntuone_installer.gui.qt.ui import images_rc | 30 | from ubuntuone_installer.gui.qt.ui import images_rc |
108 | 31 | # pylint: enable=W0611 | 31 | # pylint: enable=W0611 |
109 | 32 | from ubuntuone_installer.gui.qt import utils | ||
110 | 32 | 33 | ||
111 | 33 | 34 | ||
112 | 34 | def stop(*args): | 35 | def stop(*args): |
113 | @@ -43,14 +44,20 @@ | |||
114 | 43 | 'Error while getting the credentials: %r', exc) | 44 | 'Error while getting the credentials: %r', exc) |
115 | 44 | stop() | 45 | stop() |
116 | 45 | 46 | ||
119 | 46 | 47 | @defer.inlineCallbacks | |
120 | 47 | def success_cb(creds, gui, installing): | 48 | def success_cb(creds, gui, installing, logger): |
121 | 48 | """Handle credentials success.""" | 49 | """Handle credentials success.""" |
122 | 50 | logger.debug('Got back from sso.') | ||
123 | 49 | if creds: # Have credentials already | 51 | if creds: # Have credentials already |
125 | 50 | from ubuntuone_installer.gui.qt import utils | 52 | logger.debug('Already got credentials.') |
126 | 53 | logger.info('Starting control panel.') | ||
127 | 51 | utils.start_control_panel(with_icon=False) | 54 | utils.start_control_panel(with_icon=False) |
128 | 55 | logger.info('Checking updates.') | ||
129 | 56 | yield check_updates(gui, logger) | ||
130 | 57 | logger.info('Stopping.') | ||
131 | 52 | stop() | 58 | stop() |
132 | 53 | else: # No credentials | 59 | else: # No credentials |
133 | 60 | logger.debug('Did got connections.') | ||
134 | 54 | window = gui.MainWindow(close_callback=stop, installing=installing) | 61 | window = gui.MainWindow(close_callback=stop, installing=installing) |
135 | 55 | # Set Application Style Sheet | 62 | # Set Application Style Sheet |
136 | 56 | app = QtGui.QApplication.instance() | 63 | app = QtGui.QApplication.instance() |
137 | @@ -65,7 +72,8 @@ | |||
138 | 65 | 72 | ||
139 | 66 | 73 | ||
140 | 67 | @defer.inlineCallbacks | 74 | @defer.inlineCallbacks |
142 | 68 | def check_credentials(credentials_tool, gui, logger, installer=False): | 75 | def check_credentials(credentials_tool, gui, logger, |
143 | 76 | installer=False): | ||
144 | 69 | """Check credentials and either start u1cp or show the wizard.""" | 77 | """Check credentials and either start u1cp or show the wizard.""" |
145 | 70 | credtool = credentials_tool() | 78 | credtool = credentials_tool() |
146 | 71 | # pylint: disable=W0703 | 79 | # pylint: disable=W0703 |
147 | @@ -74,7 +82,23 @@ | |||
148 | 74 | except Exception, exc: | 82 | except Exception, exc: |
149 | 75 | error_cb(exc, logger) | 83 | error_cb(exc, logger) |
150 | 76 | else: | 84 | else: |
152 | 77 | success_cb(creds, gui, installer) | 85 | yield success_cb(creds, gui, installer, logger) |
153 | 86 | |||
154 | 87 | @defer.inlineCallbacks | ||
155 | 88 | def check_updates(gui, logger): | ||
156 | 89 | """Check for updates.""" | ||
157 | 90 | logger.info('Checking for updates.') | ||
158 | 91 | # the idea is simple, check if there are updates, ask user if we perform | ||
159 | 92 | # the update and continue. | ||
160 | 93 | are_updates_present = yield utils.are_updates_present(logger) | ||
161 | 94 | logger.debug('Updates present: %r', are_updates_present) | ||
162 | 95 | if are_updates_present: | ||
163 | 96 | logger.info('Updates are present.') | ||
164 | 97 | if gui.user_wants_to_update(): | ||
165 | 98 | logger.info('Performing auto-update in diff process.') | ||
166 | 99 | utils.perform_update() | ||
167 | 100 | else: | ||
168 | 101 | logger.info('No updates are present.') | ||
169 | 78 | 102 | ||
170 | 79 | 103 | ||
171 | 80 | def main(installing=False): | 104 | def main(installing=False): |
172 | 81 | 105 | ||
173 | === modified file 'ubuntuone_installer/gui/qt/tests/test_gui.py' | |||
174 | --- ubuntuone_installer/gui/qt/tests/test_gui.py 2011-09-21 18:24:39 +0000 | |||
175 | +++ ubuntuone_installer/gui/qt/tests/test_gui.py 2011-09-22 19:45:30 +0000 | |||
176 | @@ -22,6 +22,7 @@ | |||
177 | 22 | from PyQt4 import QtGui, QtCore | 22 | from PyQt4 import QtGui, QtCore |
178 | 23 | from ubuntuone.controlpanel.gui import qt | 23 | from ubuntuone.controlpanel.gui import qt |
179 | 24 | from ubuntuone.platform.credentials import APP_NAME | 24 | from ubuntuone.platform.credentials import APP_NAME |
180 | 25 | from twisted.internet import defer | ||
181 | 25 | 26 | ||
182 | 26 | from ubuntuone_installer.gui import NEXT | 27 | from ubuntuone_installer.gui import NEXT |
183 | 27 | from ubuntuone_installer.gui.qt import gui, forgotten, utils | 28 | from ubuntuone_installer.gui.qt import gui, forgotten, utils |
184 | @@ -662,3 +663,51 @@ | |||
185 | 662 | [QtGui.QWizard.Stretch, | 663 | [QtGui.QWizard.Stretch, |
186 | 663 | QtGui.QWizard.FinishButton, | 664 | QtGui.QWizard.FinishButton, |
187 | 664 | QtGui.QWizard.NextButton]) | 665 | QtGui.QWizard.NextButton]) |
188 | 666 | |||
189 | 667 | class UpgradeQuestion(BaseTestCase): | ||
190 | 668 | """Test the dialog that ask the user if he wants to upgrade.""" | ||
191 | 669 | |||
192 | 670 | @defer.inlineCallbacks | ||
193 | 671 | def setUp(self): | ||
194 | 672 | """Set the tests.""" | ||
195 | 673 | yield super(UpgradeQuestion, self).setUp() | ||
196 | 674 | self.answer = 0 | ||
197 | 675 | self.parent = None | ||
198 | 676 | self.title = None | ||
199 | 677 | self.text = None | ||
200 | 678 | self.yes_button = None | ||
201 | 679 | self.no_button = None | ||
202 | 680 | |||
203 | 681 | def fake_question(parent, title, text, yes_button, | ||
204 | 682 | no_button): | ||
205 | 683 | """Fake asking a question.""" | ||
206 | 684 | self.parent = parent | ||
207 | 685 | self.title = title | ||
208 | 686 | self.text = text | ||
209 | 687 | self.yes_button = yes_button | ||
210 | 688 | self.no_button = no_button | ||
211 | 689 | return self.answer | ||
212 | 690 | |||
213 | 691 | self.patch(gui.QtGui.QMessageBox, 'question', fake_question) | ||
214 | 692 | |||
215 | 693 | def user_wants_to_update_true(self): | ||
216 | 694 | """Test the question.""" | ||
217 | 695 | self.answer = gui.QtGui.QMessageBox.Yes | ||
218 | 696 | self.assertTrue(gui.user_wants_to_update(), 'User wants to update.') | ||
219 | 697 | # lets assert the parameters | ||
220 | 698 | self.assertTrue(None, self.parent) | ||
221 | 699 | self.assertTrue(self.title, gui.UPDATE_TITLE) | ||
222 | 700 | self.assertTrue(self.text, gui.UPDATE_SOFTWARE) | ||
223 | 701 | self.assertTrue(self.yes_button, gui.QtGui.QMessageBox.Yes) | ||
224 | 702 | self.assertTrue(self.no_button, gui.QtGui.QMessageBox.No) | ||
225 | 703 | |||
226 | 704 | def user_wants_to_update_false(self): | ||
227 | 705 | """Test the question.""" | ||
228 | 706 | self.answer = gui.QtGui.QMessageBox.No | ||
229 | 707 | self.assertFalse(gui.user_wants_to_update(), 'User DOES NOT want to update.') | ||
230 | 708 | # lets assert the parameters | ||
231 | 709 | self.assertTrue(None, self.parent) | ||
232 | 710 | self.assertTrue(self.title, gui.UPDATE_TITLE) | ||
233 | 711 | self.assertTrue(self.text, gui.UPDATE_SOFTWARE) | ||
234 | 712 | self.assertTrue(self.yes_button, gui.QtGui.QMessageBox.Yes) | ||
235 | 713 | self.assertTrue(self.no_button, gui.QtGui.QMessageBox.No) | ||
236 | 665 | 714 | ||
237 | === modified file 'ubuntuone_installer/gui/qt/utils/__init__.py' | |||
238 | --- ubuntuone_installer/gui/qt/utils/__init__.py 2011-09-01 13:52:35 +0000 | |||
239 | +++ ubuntuone_installer/gui/qt/utils/__init__.py 2011-09-22 19:45:30 +0000 | |||
240 | @@ -28,9 +28,13 @@ | |||
241 | 28 | start_control_panel = windows.start_control_panel | 28 | start_control_panel = windows.start_control_panel |
242 | 29 | add_syncdaemon_to_autostart = windows.add_syncdaemon_to_autostart | 29 | add_syncdaemon_to_autostart = windows.add_syncdaemon_to_autostart |
243 | 30 | default_folders = windows.default_folders | 30 | default_folders = windows.default_folders |
244 | 31 | are_updates_present = windows.are_updates_present | ||
245 | 32 | perform_update = windows.perform_update | ||
246 | 31 | else: | 33 | else: |
247 | 32 | from ubuntuone_installer.gui.qt.utils import linux | 34 | from ubuntuone_installer.gui.qt.utils import linux |
248 | 33 | uninstall_application = linux.uninstall_application | 35 | uninstall_application = linux.uninstall_application |
249 | 34 | start_control_panel = linux.start_control_panel | 36 | start_control_panel = linux.start_control_panel |
250 | 35 | add_syncdaemon_to_autostart = linux.add_syncdaemon_to_autostart | 37 | add_syncdaemon_to_autostart = linux.add_syncdaemon_to_autostart |
251 | 36 | default_folders = linux.default_folders | 38 | default_folders = linux.default_folders |
252 | 39 | are_updates_present = lambda *args, **kwargs: False | ||
253 | 40 | perform_update = lambda *args, **kwargs: None | ||
254 | 37 | 41 | ||
255 | === modified file 'ubuntuone_installer/gui/qt/utils/tests/test_windows.py' | |||
256 | --- ubuntuone_installer/gui/qt/utils/tests/test_windows.py 2011-09-19 23:01:24 +0000 | |||
257 | +++ ubuntuone_installer/gui/qt/utils/tests/test_windows.py 2011-09-22 19:45:30 +0000 | |||
258 | @@ -27,6 +27,8 @@ | |||
259 | 27 | import win32api | 27 | import win32api |
260 | 28 | # pylint: enable=F0401 | 28 | # pylint: enable=F0401 |
261 | 29 | 29 | ||
262 | 30 | from twisted.internet import defer | ||
263 | 31 | |||
264 | 30 | from ubuntuone_installer.gui.qt import utils | 32 | from ubuntuone_installer.gui.qt import utils |
265 | 31 | from ubuntuone_installer.gui.qt.tests import BaseTestCase | 33 | from ubuntuone_installer.gui.qt.tests import BaseTestCase |
266 | 32 | 34 | ||
267 | @@ -229,3 +231,86 @@ | |||
268 | 229 | pictures = buf.value | 231 | pictures = buf.value |
269 | 230 | expected = [docs, music, pictures] | 232 | expected = [docs, music, pictures] |
270 | 231 | self.assertEqual(sorted(folders), sorted(expected)) | 233 | self.assertEqual(sorted(folders), sorted(expected)) |
271 | 234 | |||
272 | 235 | |||
273 | 236 | class FakeLogger(object): | ||
274 | 237 | """A Fake logging object.""" | ||
275 | 238 | |||
276 | 239 | def __init__(self): | ||
277 | 240 | """Create a new instance.""" | ||
278 | 241 | self.called_methods = [] | ||
279 | 242 | |||
280 | 243 | def info(self, message, *args, **kwargs): | ||
281 | 244 | """Set an info log message.""" | ||
282 | 245 | self.called_methods.append(('info', message, args, kwargs)) | ||
283 | 246 | |||
284 | 247 | def debug(self, message, *args, **kwargs): | ||
285 | 248 | """Set a debug log message.""" | ||
286 | 249 | self.called_methods.append(('debug', message, args, kwargs)) | ||
287 | 250 | |||
288 | 251 | |||
289 | 252 | class AutoupdaterTestCase(BaseTestCase): | ||
290 | 253 | """Test the code that is used for the auto update process.""" | ||
291 | 254 | |||
292 | 255 | @defer.inlineCallbacks | ||
293 | 256 | def setUp(self): | ||
294 | 257 | """Prepare for the diff tests.""" | ||
295 | 258 | yield super(AutoupdaterTestCase, self).setUp() | ||
296 | 259 | self.auto_update_path = r'path\to\exe' | ||
297 | 260 | self.return_from_call = 0 | ||
298 | 261 | self.command = None | ||
299 | 262 | self.args = [] | ||
300 | 263 | |||
301 | 264 | def fake_execute_process(command, args=None, path=None): | ||
302 | 265 | """Fake async process execution.""" | ||
303 | 266 | self.command = command | ||
304 | 267 | self.args = args | ||
305 | 268 | return self.return_from_call | ||
306 | 269 | |||
307 | 270 | self.fake_logger = FakeLogger() | ||
308 | 271 | self.patch(utils.windows, 'getProcessValue', fake_execute_process) | ||
309 | 272 | self.patch(utils.windows, '_get_update_path', | ||
310 | 273 | lambda:self.auto_update_path) | ||
311 | 274 | |||
312 | 275 | |||
313 | 276 | @defer.inlineCallbacks | ||
314 | 277 | def test_are_updates_present_true(self): | ||
315 | 278 | """Test when updates are present.""" | ||
316 | 279 | # the idea is simple, set the value to be returned from | ||
317 | 280 | # the fake call, assert that we get true and also that | ||
318 | 281 | # we did use the correct parameters. | ||
319 | 282 | self.return_from_call = 0 | ||
320 | 283 | are_present = yield utils.are_updates_present(self.fake_logger) | ||
321 | 284 | self.assertTrue(are_present, 'Updates should be present.') | ||
322 | 285 | # lets assert that we did use the correct args | ||
323 | 286 | expected_args = ('--mode', 'unattended') | ||
324 | 287 | self.assertEqual(expected_args, self.args) | ||
325 | 288 | self.assertEqual(self.command, self.auto_update_path) | ||
326 | 289 | |||
327 | 290 | |||
328 | 291 | @defer.inlineCallbacks | ||
329 | 292 | def test_are_updates_present_false(self): | ||
330 | 293 | """Test when updates are not present.""" | ||
331 | 294 | # similar to test_are_updates_present_true but with diff retcode | ||
332 | 295 | self.return_from_call = 40 | ||
333 | 296 | are_present = yield utils.are_updates_present(self.fake_logger) | ||
334 | 297 | self.assertFalse(are_present, 'Updates should NOT be present.') | ||
335 | 298 | # lets assert that we did use the correct args | ||
336 | 299 | expected_args = ('--mode', 'unattended') | ||
337 | 300 | self.assertEqual(expected_args, self.args) | ||
338 | 301 | self.assertEqual(self.command, self.auto_update_path) | ||
339 | 302 | |||
340 | 303 | def test_perform_update(self): | ||
341 | 304 | """Test the method that perfroms the update.""" | ||
342 | 305 | self.patch(utils.windows.win32api, 'ShellExecute', self._set_called) | ||
343 | 306 | utils.perform_update() | ||
344 | 307 | self.assertIn(self.auto_update_path, self._called[0][2]) | ||
345 | 308 | self.assertEqual('runas', self._called[0][1]) | ||
346 | 309 | self.assertEqual('--unattendedmodeui none', self._called[0][3]) | ||
347 | 310 | self.assertEqual('', self._called[0][4]) | ||
348 | 311 | self.assertEqual(0, self._called[0][5]) | ||
349 | 312 | |||
350 | 313 | def test_get_auto_update_path(self): | ||
351 | 314 | """Test the method used to get the autoupdate.""" | ||
352 | 315 | |||
353 | 316 | |||
354 | 232 | 317 | ||
355 | === modified file 'ubuntuone_installer/gui/qt/utils/windows.py' | |||
356 | --- ubuntuone_installer/gui/qt/utils/windows.py 2011-09-19 23:00:32 +0000 | |||
357 | +++ ubuntuone_installer/gui/qt/utils/windows.py 2011-09-22 19:45:30 +0000 | |||
358 | @@ -30,6 +30,9 @@ | |||
359 | 30 | import _winreg | 30 | import _winreg |
360 | 31 | # pylint: enable=F0401 | 31 | # pylint: enable=F0401 |
361 | 32 | 32 | ||
362 | 33 | from twisted.internet import defer | ||
363 | 34 | from twisted.internet.utils import getProcessValue | ||
364 | 35 | |||
365 | 33 | AUTORUN_KEY = r"Software\Microsoft\Windows\CurrentVersion\Run" | 36 | AUTORUN_KEY = r"Software\Microsoft\Windows\CurrentVersion\Run" |
366 | 34 | 37 | ||
367 | 35 | 38 | ||
368 | @@ -47,6 +50,47 @@ | |||
369 | 47 | '--mode win32', '', 0) | 50 | '--mode win32', '', 0) |
370 | 48 | 51 | ||
371 | 49 | 52 | ||
372 | 53 | def _get_update_path(): | ||
373 | 54 | """Return the path in which the autoupdate command is found.""" | ||
374 | 55 | if hasattr(sys, "frozen"): | ||
375 | 56 | exec_path = os.path.abspath(sys.executable) | ||
376 | 57 | else: | ||
377 | 58 | exec_path = os.path.dirname(__file__) | ||
378 | 59 | folder = os.path.dirname(exec_path) | ||
379 | 60 | update_path = os.path.join(folder, "autoupdate-windows.exe") | ||
380 | 61 | if os.path.exists(update_path): | ||
381 | 62 | return update_path | ||
382 | 63 | return None | ||
383 | 64 | |||
384 | 65 | |||
385 | 66 | @defer.inlineCallbacks | ||
386 | 67 | def are_updates_present(logger): | ||
387 | 68 | """Return if there are updates for Ubuntu One.""" | ||
388 | 69 | update_path = _get_update_path() | ||
389 | 70 | logger.debug('Update path %s', update_path) | ||
390 | 71 | if update_path is not None: | ||
391 | 72 | # If there is an update present we will get 0 and other number | ||
392 | 73 | # otherwise | ||
393 | 74 | retcode = yield getProcessValue(update_path, args=('--mode', | ||
394 | 75 | 'unattended'), path=os.path.dirname(update_path)) | ||
395 | 76 | logger.debug('Return code %s', retcode) | ||
396 | 77 | if retcode == 0: | ||
397 | 78 | logger.debug('Returning True') | ||
398 | 79 | defer.returnValue(True) | ||
399 | 80 | logger.debug('Returning False') | ||
400 | 81 | defer.returnValue(False) | ||
401 | 82 | |||
402 | 83 | |||
403 | 84 | def perform_update(): | ||
404 | 85 | """Spawn the autoupdate process and call the stop funtion.""" | ||
405 | 86 | update_path = _get_update_path() | ||
406 | 87 | if update_path is not None: | ||
407 | 88 | # lets call the updater with the commands that are required, | ||
408 | 89 | win32api.ShellExecute(None, 'runas', | ||
409 | 90 | update_path, | ||
410 | 91 | '--unattendedmodeui none', '', 0) | ||
411 | 92 | |||
412 | 93 | |||
413 | 50 | def start_control_panel(with_icon=True): | 94 | def start_control_panel(with_icon=True): |
414 | 51 | """Start the control panel.""" | 95 | """Start the control panel.""" |
415 | 52 | # If we are in windows and "frozen", assume it's in | 96 | # If we are in windows and "frozen", assume it's in |
... installer. gui.qt. main.tests. test_windows ainTestCase lib\site- packages\ twisted\ internet\ defer.py" , line 1020, in windows- installer- mandel\ ubuntuone_ installer\ gui\qt\ main\wi cb(creds, gui, installer, logger) lib\site- packages\ twisted\ internet\ defer.py" , line 1141, in s(None, f(*args, **kwargs), Deferred()) windows- installer- mandel\ ubuntuone_ installer\ gui\qt\ main\wi debug(' Got back from sso.') AttributeError: 'FakeLogger' object has no attribute 'debug' lib\site- packages\ twisted\ internet\ defer.py" , line 1020, in windows- installer- mandel\ ubuntuone_ installer\ gui\qt\ main\wi cb(creds, gui, installer, logger) lib\site- packages\ twisted\ internet\ defer.py" , line 1141, in s(None, f(*args, **kwargs), Deferred()) windows- installer- mandel\ ubuntuone_ installer\ gui\qt\ main\wi debug(' Got back from sso.') AttributeError: 'FakeLogger' object has no attribute 'debug' with_installed_ flag ... Traceback (most recent call last): lib\site- packages\ twisted\ internet\ defer.py" , line 1020, in windows- installer- mandel\ ubuntuone_ installer\ gui\qt\ main\te windows. py", line 150, in test_with_ installed_ flag trial.unittest. FailTest: not equal: installer. gui.qt. gui' from 'X:\ubuntuone- windows- installer- ubuntuone_ installer\ gui\qt\ gui.pyc' >, installer. gui.qt. main.tests. test_windows. FakeLogger object at 0x086 installer. gui.qt. gui' from 'X:\ubuntuone- windows- installer- ubuntuone_ installer\ gui\qt\ gui.pyc' >,
ubuntuone_
CredsFailureM
test_failure ... [OK]
test_no_creds ... Traceback (most recent call last):
File "C:\Python27\
_inlineCallbacks
result = g.send(result)
File "X:\ubuntuone-
ndows.py", line 85, in check_credentials
success_
File "C:\Python27\
unwindGenerator
return _inlineCallback
File "X:\ubuntuone-
ndows.py", line 50, in success_cb
logger.
exceptions.
[ERROR]
test_with_creds ... Traceback (most recent call last):
File "C:\Python27\
_inlineCallbacks
result = g.send(result)
File "X:\ubuntuone-
ndows.py", line 85, in check_credentials
success_
File "C:\Python27\
unwindGenerator
return _inlineCallback
File "X:\ubuntuone-
ndows.py", line 50, in success_cb
logger.
exceptions.
[ERROR]
test_
File "C:\Python27\
_inlineCallbacks
result = g.send(result)
File "X:\ubuntuone-
sts\test_
gui, True), {}))
twisted.
a = (('Something not false',
<module 'ubuntuone_
mandel\
True,
<ubuntuone_
9D3B0>),
{})
b = (('Something not false',
<module 'ubuntuone_
mandel\
True),
{})
[FAIL] without_ installed_ flag ... Traceback (most recent call last): lib\site- packages\ twisted\ internet\ defer.py" , line 1020, in windows- installer- mandel\ ubuntuone_ installer\ gui\qt\ main\te windows. py", line 139, in test_without_ installed_ flag trial.unittest. FailTest: not equal: installer. gui.qt. gui' from 'X:\ubuntuone- windows- installer- ubuntuone_ installer\ gui\qt\ gui.pyc' >, installer. gui.qt. main.tests. test_windows. FakeLogger object at 0x086
test_
File "C:\Python27\
_inlineCallbacks
result = g.send(result)
File "X:\ubuntuone-
sts\test_
gui, False), {}))
twisted.
a = (('Something not false',
<module 'ubuntuone_
mandel\
False,
<ubuntuone_
9D9B0>),
{})
b = (('Something not false',
<module 'ubunt...