Merge lp:~nataliabidart/ubuntuone-control-panel/new-creds into lp:ubuntuone-control-panel
- new-creds
- Merge into trunk
Proposed by
Natalia Bidart
Status: | Merged |
---|---|
Approved by: | Natalia Bidart |
Approved revision: | 203 |
Merged at revision: | 201 |
Proposed branch: | lp:~nataliabidart/ubuntuone-control-panel/new-creds |
Merge into: | lp:ubuntuone-control-panel |
Diff against target: |
996 lines (+285/-203) 8 files modified
run-tests (+4/-2) setup.py (+12/-6) ubuntuone/controlpanel/gui/gtk/gui.py (+46/-70) ubuntuone/controlpanel/gui/gtk/tests/__init__.py (+12/-14) ubuntuone/controlpanel/gui/gtk/tests/test_gui.py (+19/-19) ubuntuone/controlpanel/gui/gtk/tests/test_gui_basic.py (+126/-81) ubuntuone/controlpanel/login_client.py (+18/-5) ubuntuone/controlpanel/tests/test_login_client.py (+48/-6) |
To merge this branch: | bzr merge lp:~nataliabidart/ubuntuone-control-panel/new-creds |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
John Lenton (community) | Approve | ||
Roberto Alsina (community) | Approve | ||
Review via email: mp+72077@code.launchpad.net |
Commit message
- Using CredentialsMana
Description of the change
To post a comment you must log in.
Revision history for this message
John Lenton (chipaca) wrote : | # |
Good.
What does GTK_MODULES break?
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'run-tests' | |||
2 | --- run-tests 2011-07-15 17:50:50 +0000 | |||
3 | +++ run-tests 2011-08-18 17:23:16 +0000 | |||
4 | @@ -37,14 +37,16 @@ | |||
5 | 37 | fi | 37 | fi |
6 | 38 | 38 | ||
7 | 39 | style_check() { | 39 | style_check() { |
9 | 40 | u1lint --ignore ubuntuone/controlpanel/gui/qt/ui ubuntuone/ | 40 | u1lint --ignore ubuntuone/controlpanel/gui/qt/ui |
10 | 41 | if [ -x `which pep8` ]; then | 41 | if [ -x `which pep8` ]; then |
12 | 42 | pep8 --exclude '.svn,CVS,.bzr,.hg,.git,*_ui.py,*_rc.py' --repeat bin/ $MODULE | 42 | pep8 --exclude '.svn,CVS,.bzr,.hg,.git,*_ui.py,*_rc.py' --repeat . |
13 | 43 | else | 43 | else |
14 | 44 | echo "Please install the 'pep8' package." | 44 | echo "Please install the 'pep8' package." |
15 | 45 | fi | 45 | fi |
16 | 46 | } | 46 | } |
17 | 47 | 47 | ||
18 | 48 | unset GTK_MODULES | ||
19 | 49 | |||
20 | 48 | ./setup.py build | 50 | ./setup.py build |
21 | 49 | echo "Running test suite for ""$MODULE" | 51 | echo "Running test suite for ""$MODULE" |
22 | 50 | if [ "$USE_QT" -eq 0 ]; then | 52 | if [ "$USE_QT" -eq 0 ]; then |
23 | 51 | 53 | ||
24 | === modified file 'setup.py' | |||
25 | --- setup.py 2011-08-12 19:09:02 +0000 | |||
26 | +++ setup.py 2011-08-18 17:23:16 +0000 | |||
27 | @@ -46,6 +46,7 @@ | |||
28 | 46 | CLEANFILES = [ | 46 | CLEANFILES = [ |
29 | 47 | SERVICE_FILE, GUI_SERVICE_FILE, MESSAGE_ENTRY, CONSTANTS, POT_FILE, | 47 | SERVICE_FILE, GUI_SERVICE_FILE, MESSAGE_ENTRY, CONSTANTS, POT_FILE, |
30 | 48 | 'MANIFEST'] | 48 | 'MANIFEST'] |
31 | 49 | QT_UI_DIR = os.path.join('ubuntuone', 'controlpanel', 'gui', 'qt', 'ui') | ||
32 | 49 | 50 | ||
33 | 50 | 51 | ||
34 | 51 | def replace_prefix(prefix): | 52 | def replace_prefix(prefix): |
35 | @@ -64,7 +65,7 @@ | |||
36 | 64 | def run(self): | 65 | def run(self): |
37 | 65 | """Do the install. | 66 | """Do the install. |
38 | 66 | 67 | ||
40 | 67 | Read from *.service.in and generate .service files with reeplacing | 68 | Read from *.service.in and generate .service files by replacing |
41 | 68 | @prefix@ by self.prefix. | 69 | @prefix@ by self.prefix. |
42 | 69 | 70 | ||
43 | 70 | """ | 71 | """ |
44 | @@ -75,7 +76,6 @@ | |||
45 | 75 | class ControlPanelBuild(build_extra.build_extra): | 76 | class ControlPanelBuild(build_extra.build_extra): |
46 | 76 | """Build PyQt (.ui) files and resources.""" | 77 | """Build PyQt (.ui) files and resources.""" |
47 | 77 | 78 | ||
48 | 78 | QT_UI_DIR = os.path.join('ubuntuone', 'controlpanel', 'gui', 'qt', 'ui') | ||
49 | 79 | description = "build PyQt GUIs (.ui) and resources (.qrc)" | 79 | description = "build PyQt GUIs (.ui) and resources (.qrc)" |
50 | 80 | 80 | ||
51 | 81 | def compile_ui(self, ui_file, py_file=None): | 81 | def compile_ui(self, ui_file, py_file=None): |
52 | @@ -86,7 +86,7 @@ | |||
53 | 86 | # python file in the qt moodule | 86 | # python file in the qt moodule |
54 | 87 | py_file = os.path.split(ui_file)[1] | 87 | py_file = os.path.split(ui_file)[1] |
55 | 88 | py_file = os.path.splitext(py_file)[0] + '_ui.py' | 88 | py_file = os.path.splitext(py_file)[0] + '_ui.py' |
57 | 89 | py_file = os.path.join(self.QT_UI_DIR, py_file) | 89 | py_file = os.path.join(QT_UI_DIR, py_file) |
58 | 90 | # we indeed want to catch Exception, is ugly but we need it | 90 | # we indeed want to catch Exception, is ugly but we need it |
59 | 91 | # pylint: disable=W0703 | 91 | # pylint: disable=W0703 |
60 | 92 | try: | 92 | try: |
61 | @@ -112,7 +112,7 @@ | |||
62 | 112 | if py_file is None: | 112 | if py_file is None: |
63 | 113 | py_file = os.path.split(qrc_file)[1] | 113 | py_file = os.path.split(qrc_file)[1] |
64 | 114 | py_file = os.path.splitext(py_file)[0] + '_rc.py' | 114 | py_file = os.path.splitext(py_file)[0] + '_rc.py' |
66 | 115 | py_file = os.path.join(self.QT_UI_DIR, py_file) | 115 | py_file = os.path.join(QT_UI_DIR, py_file) |
67 | 116 | path = os.getenv('PATH') | 116 | path = os.getenv('PATH') |
68 | 117 | os.putenv('PATH', path + os.path.pathsep + os.path.join( | 117 | os.putenv('PATH', path + os.path.pathsep + os.path.join( |
69 | 118 | os.path.dirname(PyQt4.__file__), 'bin')) | 118 | os.path.dirname(PyQt4.__file__), 'bin')) |
70 | @@ -218,6 +218,12 @@ | |||
71 | 218 | if os.path.exists(built_file): | 218 | if os.path.exists(built_file): |
72 | 219 | os.unlink(built_file) | 219 | os.unlink(built_file) |
73 | 220 | 220 | ||
74 | 221 | for dirpath, _, filenames in os.walk(os.path.join(QT_UI_DIR)): | ||
75 | 222 | for current_file in filenames: | ||
76 | 223 | if current_file.endswith('_ui.py') or\ | ||
77 | 224 | current_file.endswith('_rc.py'): | ||
78 | 225 | os.unlink(os.path.join(dirpath, current_file)) | ||
79 | 226 | |||
80 | 221 | DistUtilsExtra.auto.clean_build_tree.run(self) | 227 | DistUtilsExtra.auto.clean_build_tree.run(self) |
81 | 222 | 228 | ||
82 | 223 | 229 | ||
83 | @@ -228,8 +234,8 @@ | |||
84 | 228 | author='Natalia Bidart', | 234 | author='Natalia Bidart', |
85 | 229 | author_email='natalia.bidart@canonical.com', | 235 | author_email='natalia.bidart@canonical.com', |
86 | 230 | description='Ubuntu One Control Panel', | 236 | description='Ubuntu One Control Panel', |
89 | 231 | long_description='Application to manage a Ubuntu One account. Provides a'\ | 237 | long_description='Application to manage a Ubuntu One account. Provides' \ |
90 | 232 | 'DBus service to query/modify all the Ubuntu One bits.', | 238 | ' a DBus service to query/modify all the Ubuntu One bits.', |
91 | 233 | url='https://launchpad.net/ubuntuone-control-panel', | 239 | url='https://launchpad.net/ubuntuone-control-panel', |
92 | 234 | packages=[ | 240 | packages=[ |
93 | 235 | 'ubuntuone', 'ubuntuone.controlpanel', 'ubuntuone.controlpanel.gui', | 241 | 'ubuntuone', 'ubuntuone.controlpanel', 'ubuntuone.controlpanel.gui', |
94 | 236 | 242 | ||
95 | === modified file 'ubuntuone/controlpanel/gui/gtk/gui.py' | |||
96 | --- ubuntuone/controlpanel/gui/gtk/gui.py 2011-06-01 18:10:22 +0000 | |||
97 | +++ ubuntuone/controlpanel/gui/gtk/gui.py 2011-08-18 17:23:16 +0000 | |||
98 | @@ -28,17 +28,15 @@ | |||
99 | 28 | import dbus | 28 | import dbus |
100 | 29 | import gtk | 29 | import gtk |
101 | 30 | import gobject | 30 | import gobject |
102 | 31 | import ubuntu_sso | ||
103 | 32 | 31 | ||
104 | 33 | from dbus.mainloop.glib import DBusGMainLoop | 32 | from dbus.mainloop.glib import DBusGMainLoop |
105 | 34 | from ubuntu_sso import networkstate | 33 | from ubuntu_sso import networkstate |
106 | 35 | from ubuntu_sso.credentials import (TC_URL_KEY, HELP_TEXT_KEY, WINDOW_ID_KEY, | ||
107 | 36 | PING_URL_KEY) | ||
108 | 37 | # No name 'clientdefs' in module 'ubuntuone' | ||
109 | 38 | # pylint: disable=E0611,F0401 | 34 | # pylint: disable=E0611,F0401 |
110 | 39 | from gi.repository import GLib | 35 | from gi.repository import GLib |
113 | 40 | from ubuntuone.clientdefs import (APP_NAME as U1_APP_NAME, TC_URL as U1_TC_URL, | 36 | from ubuntuone.platform.credentials import ( |
114 | 41 | PING_URL as U1_PING_URL, DESCRIPTION as U1_DESCRIPTION) | 37 | APP_NAME as U1_APP_NAME, |
115 | 38 | CredentialsManagementTool, | ||
116 | 39 | ) | ||
117 | 42 | # pylint: enable=E0611,F0401 | 40 | # pylint: enable=E0611,F0401 |
118 | 43 | 41 | ||
119 | 44 | # Wildcard import ubuntuone.controlpanel.gui | 42 | # Wildcard import ubuntuone.controlpanel.gui |
120 | @@ -123,21 +121,6 @@ | |||
121 | 123 | gtk.main() | 121 | gtk.main() |
122 | 124 | 122 | ||
123 | 125 | 123 | ||
124 | 126 | def filter_by_app_name(f): | ||
125 | 127 | """Excecute 'f' filtering by app_name.""" | ||
126 | 128 | |||
127 | 129 | @wraps(f) | ||
128 | 130 | def filter_by_app_name_inner(instance, app_name, *args, **kwargs): | ||
129 | 131 | """Execute 'f' only if 'app_name' matches 'U1_APP_NAME'.""" | ||
130 | 132 | if app_name == U1_APP_NAME: | ||
131 | 133 | return f(instance, app_name, *args, **kwargs) | ||
132 | 134 | else: | ||
133 | 135 | logger.info('%s: ignoring call since received app_name '\ | ||
134 | 136 | '"%s" (expected "%s")', | ||
135 | 137 | f.__name__, app_name, U1_APP_NAME) | ||
136 | 138 | return filter_by_app_name_inner | ||
137 | 139 | |||
138 | 140 | |||
139 | 141 | def on_size_allocate(widget, allocation, label): | 124 | def on_size_allocate(widget, allocation, label): |
140 | 142 | """Resize labels according to who 'widget' is being resized.""" | 125 | """Resize labels according to who 'widget' is being resized.""" |
141 | 143 | label.set_size_request(allocation.width - 2, -1) | 126 | label.set_size_request(allocation.width - 2, -1) |
142 | @@ -272,23 +255,9 @@ | |||
143 | 272 | 255 | ||
144 | 273 | def __init__(self, main_window): | 256 | def __init__(self, main_window): |
145 | 274 | GreyableBin.__init__(self) | 257 | GreyableBin.__init__(self) |
161 | 275 | 258 | creds_backend = CredentialsManagementTool() | |
147 | 276 | sso_backend = None | ||
148 | 277 | bus = dbus.SessionBus() | ||
149 | 278 | try: | ||
150 | 279 | obj = bus.get_object(ubuntu_sso.DBUS_BUS_NAME, | ||
151 | 280 | ubuntu_sso.DBUS_CREDENTIALS_PATH, | ||
152 | 281 | follow_name_owner_changes=True) | ||
153 | 282 | iface = ubuntu_sso.DBUS_CREDENTIALS_IFACE | ||
154 | 283 | sso_backend = dbus.Interface(obj, dbus_interface=iface) | ||
155 | 284 | except dbus.exceptions.DBusException: | ||
156 | 285 | logger.exception('Can not connect to DBus at %r', | ||
157 | 286 | (ubuntu_sso.DBUS_BUS_NAME, | ||
158 | 287 | ubuntu_sso.DBUS_CREDENTIALS_PATH)) | ||
159 | 288 | raise | ||
160 | 289 | |||
162 | 290 | ControlPanelMixin.__init__(self, filename='overview.ui', | 259 | ControlPanelMixin.__init__(self, filename='overview.ui', |
164 | 291 | backend_instance=sso_backend) | 260 | backend_instance=creds_backend) |
165 | 292 | self.add(self.itself) | 261 | self.add(self.itself) |
166 | 293 | self.banner.set_from_file(get_data_file(OVERVIEW_BANNER)) | 262 | self.banner.set_from_file(get_data_file(OVERVIEW_BANNER)) |
167 | 294 | self.files_icon.set_from_file(get_data_file(FILES_ICON)) | 263 | self.files_icon.set_from_file(get_data_file(FILES_ICON)) |
168 | @@ -305,15 +274,6 @@ | |||
169 | 305 | self._credentials_are_new = False | 274 | self._credentials_are_new = False |
170 | 306 | self.show() | 275 | self.show() |
171 | 307 | 276 | ||
172 | 308 | self.backend.connect_to_signal('CredentialsFound', | ||
173 | 309 | self.on_credentials_found) | ||
174 | 310 | self.backend.connect_to_signal('CredentialsNotFound', | ||
175 | 311 | self.on_credentials_not_found) | ||
176 | 312 | self.backend.connect_to_signal('CredentialsError', | ||
177 | 313 | self.on_credentials_error) | ||
178 | 314 | self.backend.connect_to_signal('AuthorizationDenied', | ||
179 | 315 | self.on_authorization_denied) | ||
180 | 316 | |||
181 | 317 | kw = dict(result_cb=self.on_network_state_changed) | 277 | kw = dict(result_cb=self.on_network_state_changed) |
182 | 318 | self.network_manager_state = networkstate.NetworkManagerState(**kw) | 278 | self.network_manager_state = networkstate.NetworkManagerState(**kw) |
183 | 319 | self.network_manager_state.find_online_state() | 279 | self.network_manager_state.find_online_state() |
184 | @@ -323,6 +283,14 @@ | |||
185 | 323 | ControlPanelMixin._set_warning(self, message, | 283 | ControlPanelMixin._set_warning(self, message, |
186 | 324 | label=self.warning_label) | 284 | label=self.warning_label) |
187 | 325 | 285 | ||
188 | 286 | def _window_xid(self): | ||
189 | 287 | """Return settings for credentials backend.""" | ||
190 | 288 | if self.main_window.window is not None: | ||
191 | 289 | settings = {'window_id': str(self.main_window.window.xid)} | ||
192 | 290 | else: | ||
193 | 291 | settings = {} | ||
194 | 292 | return settings | ||
195 | 293 | |||
196 | 326 | def set_property(self, prop_name, new_value): | 294 | def set_property(self, prop_name, new_value): |
197 | 327 | """Override 'set_property' to disable buttons if prop is 'greyed'.""" | 295 | """Override 'set_property' to disable buttons if prop is 'greyed'.""" |
198 | 328 | if prop_name == 'greyed': | 296 | if prop_name == 'greyed': |
199 | @@ -342,21 +310,17 @@ | |||
200 | 342 | 310 | ||
201 | 343 | def on_join_now_button_clicked(self, *a, **kw): | 311 | def on_join_now_button_clicked(self, *a, **kw): |
202 | 344 | """User wants to join now.""" | 312 | """User wants to join now.""" |
208 | 345 | settings = {TC_URL_KEY: U1_TC_URL, HELP_TEXT_KEY: U1_DESCRIPTION, | 313 | d = self.backend.register(**self._window_xid()) |
209 | 346 | WINDOW_ID_KEY: str(self.main_window.window.xid), | 314 | d.addCallback(self.on_credentials_result) |
210 | 347 | PING_URL_KEY: U1_PING_URL} | 315 | d.addErrback(self.on_credentials_error) |
206 | 348 | self.backend.register(U1_APP_NAME, settings, | ||
207 | 349 | reply_handler=NO_OP, error_handler=error_handler) | ||
211 | 350 | self.set_property('greyed', True) | 316 | self.set_property('greyed', True) |
212 | 351 | self.warning_label.set_text('') | 317 | self.warning_label.set_text('') |
213 | 352 | 318 | ||
214 | 353 | def on_connect_button_clicked(self, *a, **kw): | 319 | def on_connect_button_clicked(self, *a, **kw): |
215 | 354 | """User wants to connect now.""" | 320 | """User wants to connect now.""" |
221 | 355 | settings = {TC_URL_KEY: U1_TC_URL, HELP_TEXT_KEY: U1_DESCRIPTION, | 321 | d = self.backend.login(**self._window_xid()) |
222 | 356 | WINDOW_ID_KEY: str(self.main_window.window.xid), | 322 | d.addCallback(self.on_credentials_result) |
223 | 357 | PING_URL_KEY: U1_PING_URL} | 323 | d.addErrback(self.on_credentials_error) |
219 | 358 | self.backend.login(U1_APP_NAME, settings, | ||
220 | 359 | reply_handler=NO_OP, error_handler=error_handler) | ||
224 | 360 | self.set_property('greyed', True) | 324 | self.set_property('greyed', True) |
225 | 361 | self.warning_label.set_text('') | 325 | self.warning_label.set_text('') |
226 | 362 | 326 | ||
227 | @@ -364,31 +328,42 @@ | |||
228 | 364 | """User wants to learn more.""" | 328 | """User wants to learn more.""" |
229 | 365 | uri_hook(self.learn_more_button, LEARN_MORE_LINK) | 329 | uri_hook(self.learn_more_button, LEARN_MORE_LINK) |
230 | 366 | 330 | ||
232 | 367 | @filter_by_app_name | 331 | def on_credentials_result(self, result): |
233 | 332 | """Process the credentials response. | ||
234 | 333 | |||
235 | 334 | If 'result' is a non empty dict, they were found. | ||
236 | 335 | If 'result' is an empty dict, they were not found. | ||
237 | 336 | If 'result' is None, the user cancelled the process. | ||
238 | 337 | |||
239 | 338 | """ | ||
240 | 339 | if result is None: | ||
241 | 340 | self.on_authorization_denied() | ||
242 | 341 | elif result == {}: | ||
243 | 342 | self.on_credentials_not_found() | ||
244 | 343 | else: | ||
245 | 344 | self.on_credentials_found(result) | ||
246 | 345 | |||
247 | 368 | @log_call(logger.info, with_args=False) | 346 | @log_call(logger.info, with_args=False) |
250 | 369 | def on_credentials_found(self, app_name, credentials): | 347 | def on_credentials_found(self, credentials): |
251 | 370 | """SSO backend notifies of credentials found.""" | 348 | """Credentials backend notifies of credentials found.""" |
252 | 371 | self.set_property('greyed', False) | 349 | self.set_property('greyed', False) |
253 | 372 | self.emit('credentials-found', self._credentials_are_new, credentials) | 350 | self.emit('credentials-found', self._credentials_are_new, credentials) |
254 | 373 | 351 | ||
255 | 374 | @filter_by_app_name | ||
256 | 375 | @log_call(logger.info) | 352 | @log_call(logger.info) |
259 | 376 | def on_credentials_not_found(self, app_name): | 353 | def on_credentials_not_found(self): |
260 | 377 | """SSO backend notifies of credentials not found.""" | 354 | """Creds backend notifies of credentials not found.""" |
261 | 378 | self._credentials_are_new = True | 355 | self._credentials_are_new = True |
262 | 379 | self.set_property('greyed', False) | 356 | self.set_property('greyed', False) |
263 | 380 | 357 | ||
264 | 381 | @filter_by_app_name | ||
265 | 382 | @log_call(logger.error) | 358 | @log_call(logger.error) |
268 | 383 | def on_credentials_error(self, app_name, error_dict): | 359 | def on_credentials_error(self, error_dict): |
269 | 384 | """SSO backend notifies of an error when fetching credentials.""" | 360 | """Creds backend notifies of an error when fetching credentials.""" |
270 | 385 | self.set_property('greyed', False) | 361 | self.set_property('greyed', False) |
271 | 386 | self._set_warning(CREDENTIALS_ERROR) | 362 | self._set_warning(CREDENTIALS_ERROR) |
272 | 387 | 363 | ||
273 | 388 | @filter_by_app_name | ||
274 | 389 | @log_call(logger.info) | 364 | @log_call(logger.info) |
277 | 390 | def on_authorization_denied(self, app_name): | 365 | def on_authorization_denied(self): |
278 | 391 | """SSO backend notifies that user refused auth for 'app_name'.""" | 366 | """Creds backend notifies that user refused auth for 'app_name'.""" |
279 | 392 | self.set_property('greyed', False) | 367 | self.set_property('greyed', False) |
280 | 393 | 368 | ||
281 | 394 | @log_call(logger.info) | 369 | @log_call(logger.info) |
282 | @@ -402,8 +377,9 @@ | |||
283 | 402 | else: | 377 | else: |
284 | 403 | self.set_sensitive(True) | 378 | self.set_sensitive(True) |
285 | 404 | self.warning_label.set_text(msg) | 379 | self.warning_label.set_text(msg) |
288 | 405 | self.backend.find_credentials(U1_APP_NAME, {}, | 380 | d = self.backend.find_credentials() |
289 | 406 | reply_handler=NO_OP, error_handler=error_handler) | 381 | d.addCallback(self.on_credentials_result) |
290 | 382 | d.addErrback(self.on_credentials_error) | ||
291 | 407 | 383 | ||
292 | 408 | 384 | ||
293 | 409 | class DashboardPanel(UbuntuOneBin, ControlPanelMixin): | 385 | class DashboardPanel(UbuntuOneBin, ControlPanelMixin): |
294 | 410 | 386 | ||
295 | === modified file 'ubuntuone/controlpanel/gui/gtk/tests/__init__.py' | |||
296 | --- ubuntuone/controlpanel/gui/gtk/tests/__init__.py 2011-05-26 22:18:04 +0000 | |||
297 | +++ ubuntuone/controlpanel/gui/gtk/tests/__init__.py 2011-08-18 17:23:16 +0000 | |||
298 | @@ -22,6 +22,7 @@ | |||
299 | 22 | 22 | ||
300 | 23 | from collections import defaultdict | 23 | from collections import defaultdict |
301 | 24 | 24 | ||
302 | 25 | from twisted.internet import defer | ||
303 | 25 | from ubuntuone.devtools.handlers import MementoHandler | 26 | from ubuntuone.devtools.handlers import MementoHandler |
304 | 26 | 27 | ||
305 | 27 | from ubuntuone.controlpanel.gui.gtk import gui | 28 | from ubuntuone.controlpanel.gui.gtk import gui |
306 | @@ -83,14 +84,12 @@ | |||
307 | 83 | self._signals[signal].append(handler) | 84 | self._signals[signal].append(handler) |
308 | 84 | 85 | ||
309 | 85 | 86 | ||
312 | 86 | class FakedSSOBackend(FakedDBusBackend): | 87 | class FakedCredentialsBackend(FakedObject): |
313 | 87 | """Fake a SSO Backend, act as a dbus.Interface.""" | 88 | """Fake a credentials backend.""" |
314 | 88 | 89 | ||
315 | 89 | bus_name = gui.ubuntu_sso.DBUS_BUS_NAME | ||
316 | 90 | object_path = gui.ubuntu_sso.DBUS_CREDENTIALS_PATH | ||
317 | 91 | iface = gui.ubuntu_sso.DBUS_CREDENTIALS_IFACE | ||
318 | 92 | exposed_methods = ['find_credentials', 'clear_credentials', | 90 | exposed_methods = ['find_credentials', 'clear_credentials', |
319 | 93 | 'login', 'register'] | 91 | 'login', 'register'] |
320 | 92 | next_result = defer.succeed(None) | ||
321 | 94 | 93 | ||
322 | 95 | 94 | ||
323 | 96 | class FakedControlPanelBackend(FakedDBusBackend): | 95 | class FakedControlPanelBackend(FakedDBusBackend): |
324 | @@ -135,8 +134,6 @@ | |||
325 | 135 | if dbus_interface == gui.DBUS_PREFERENCES_IFACE: | 134 | if dbus_interface == gui.DBUS_PREFERENCES_IFACE: |
326 | 136 | return FakedControlPanelBackend(obj, dbus_interface, | 135 | return FakedControlPanelBackend(obj, dbus_interface, |
327 | 137 | *args, **kwargs) | 136 | *args, **kwargs) |
328 | 138 | if dbus_interface == gui.ubuntu_sso.DBUS_CREDENTIALS_IFACE: | ||
329 | 139 | return FakedSSOBackend(obj, dbus_interface, *args, **kwargs) | ||
330 | 140 | if dbus_interface == gui.DBUS_IFACE_GUI: | 137 | if dbus_interface == gui.DBUS_IFACE_GUI: |
331 | 141 | return FakeControlPanelBackend( | 138 | return FakeControlPanelBackend( |
332 | 142 | obj, dbus_interface, *args, **kwargs) | 139 | obj, dbus_interface, *args, **kwargs) |
333 | @@ -188,9 +185,11 @@ | |||
334 | 188 | # pylint: disable=E1102 | 185 | # pylint: disable=E1102 |
335 | 189 | klass = None | 186 | klass = None |
336 | 190 | kwargs = {} | 187 | kwargs = {} |
337 | 188 | backend_is_dbus = True | ||
338 | 191 | 189 | ||
339 | 192 | def setUp(self): | 190 | def setUp(self): |
340 | 193 | super(BaseTestCase, self).setUp() | 191 | super(BaseTestCase, self).setUp() |
341 | 192 | self.patch(gui, 'CredentialsManagementTool', FakedCredentialsBackend) | ||
342 | 194 | self.patch(gui.os.path, 'expanduser', | 193 | self.patch(gui.os.path, 'expanduser', |
343 | 195 | lambda path: path.replace('~', USER_HOME)) | 194 | lambda path: path.replace('~', USER_HOME)) |
344 | 196 | self.patch(gui.gtk, 'main', lambda: None) | 195 | self.patch(gui.gtk, 'main', lambda: None) |
345 | @@ -221,14 +220,13 @@ | |||
346 | 221 | pb = gui.gtk.gdk.pixbuf_new_from_file(gui.get_data_file(filename)) | 220 | pb = gui.gtk.gdk.pixbuf_new_from_file(gui.get_data_file(filename)) |
347 | 222 | self.assertEqual(image.get_pixbuf().get_pixels(), pb.get_pixels()) | 221 | self.assertEqual(image.get_pixbuf().get_pixels(), pb.get_pixels()) |
348 | 223 | 222 | ||
350 | 224 | def assert_backend_called(self, method_name, args, backend=None): | 223 | def assert_backend_called(self, method_name, *args, **kwargs): |
351 | 225 | """Check that the control panel backend 'method_name' was called.""" | 224 | """Check that the control panel backend 'method_name' was called.""" |
358 | 226 | if backend is None: | 225 | if self.backend_is_dbus: |
359 | 227 | backend = self.ui.backend | 226 | kwargs = {'reply_handler': gui.NO_OP, |
360 | 228 | self.assertIn(method_name, backend._called) | 227 | 'error_handler': gui.error_handler} |
361 | 229 | kwargs = {'reply_handler': gui.NO_OP, | 228 | self.assertIn(method_name, self.ui.backend._called) |
362 | 230 | 'error_handler': gui.error_handler} | 229 | self.assertEqual(self.ui.backend._called[method_name], (args, kwargs)) |
357 | 231 | self.assertEqual(backend._called[method_name], (args, kwargs)) | ||
363 | 232 | 230 | ||
364 | 233 | def assert_warning_correct(self, warning, text): | 231 | def assert_warning_correct(self, warning, text): |
365 | 234 | """Check that 'warning' is visible, showing 'text'.""" | 232 | """Check that 'warning' is visible, showing 'text'.""" |
366 | 235 | 233 | ||
367 | === modified file 'ubuntuone/controlpanel/gui/gtk/tests/test_gui.py' | |||
368 | --- ubuntuone/controlpanel/gui/gtk/tests/test_gui.py 2011-06-01 21:18:46 +0000 | |||
369 | +++ ubuntuone/controlpanel/gui/gtk/tests/test_gui.py 2011-08-18 17:23:16 +0000 | |||
370 | @@ -159,7 +159,7 @@ | |||
371 | 159 | self.ui.backend._called.pop('volumes_info', None) | 159 | self.ui.backend._called.pop('volumes_info', None) |
372 | 160 | self.ui.load() | 160 | self.ui.load() |
373 | 161 | 161 | ||
375 | 162 | self.assert_backend_called('volumes_info', ()) | 162 | self.assert_backend_called('volumes_info') |
376 | 163 | 163 | ||
377 | 164 | def test_is_processing_after_load(self): | 164 | def test_is_processing_after_load(self): |
378 | 165 | """The ui is processing when contents are load.""" | 165 | """The ui is processing when contents are load.""" |
379 | @@ -440,7 +440,7 @@ | |||
380 | 440 | subscribed = gui.bool_str(not bool(volume['subscribed'])) | 440 | subscribed = gui.bool_str(not bool(volume['subscribed'])) |
381 | 441 | # backend was called | 441 | # backend was called |
382 | 442 | self.assert_backend_called('change_volume_settings', | 442 | self.assert_backend_called('change_volume_settings', |
384 | 443 | (fid, {'subscribed': subscribed})) | 443 | fid, {'subscribed': subscribed}) |
385 | 444 | # store was updated | 444 | # store was updated |
386 | 445 | it = self.ui.volumes_store.get_iter(path) | 445 | it = self.ui.volumes_store.get_iter(path) |
387 | 446 | value = self.ui.volumes_store.get_value(it, 1) | 446 | value = self.ui.volumes_store.get_value(it, 1) |
388 | @@ -572,7 +572,7 @@ | |||
389 | 572 | """Changing throttling settings updates the backend properly.""" | 572 | """Changing throttling settings updates the backend properly.""" |
390 | 573 | expected = self.ui.__dict__ | 573 | expected = self.ui.__dict__ |
391 | 574 | self.assert_backend_called('change_device_settings', | 574 | self.assert_backend_called('change_device_settings', |
393 | 575 | (self.ui.id, expected)) | 575 | self.ui.id, expected) |
394 | 576 | self.assertEqual(self.ui.warning_label.get_text(), '') | 576 | self.assertEqual(self.ui.warning_label.get_text(), '') |
395 | 577 | 577 | ||
396 | 578 | limit_enabled = self.ui.throttling_limits.get_sensitive() | 578 | limit_enabled = self.ui.throttling_limits.get_sensitive() |
397 | @@ -806,7 +806,7 @@ | |||
398 | 806 | self.ui.is_local = False | 806 | self.ui.is_local = False |
399 | 807 | self.ui.remove.clicked() | 807 | self.ui.remove.clicked() |
400 | 808 | 808 | ||
402 | 809 | self.assert_backend_called('remove_device', (self.ui.id,)) | 809 | self.assert_backend_called('remove_device', self.ui.id) |
403 | 810 | self.assertFalse(self.ui.get_sensitive(), | 810 | self.assertFalse(self.ui.get_sensitive(), |
404 | 811 | 'Must be disabled while removing.') | 811 | 'Must be disabled while removing.') |
405 | 812 | 812 | ||
406 | @@ -936,7 +936,7 @@ | |||
407 | 936 | self.ui.backend._called.pop('devices_info', None) | 936 | self.ui.backend._called.pop('devices_info', None) |
408 | 937 | self.ui.load() | 937 | self.ui.load() |
409 | 938 | 938 | ||
411 | 939 | self.assert_backend_called('devices_info', ()) | 939 | self.assert_backend_called('devices_info') |
412 | 940 | 940 | ||
413 | 941 | def test_is_processing_after_load(self): | 941 | def test_is_processing_after_load(self): |
414 | 942 | """The ui is processing when contents are load.""" | 942 | """The ui is processing when contents are load.""" |
415 | @@ -1246,7 +1246,7 @@ | |||
416 | 1246 | 1246 | ||
417 | 1247 | def test_file_sync_status_is_requested(self): | 1247 | def test_file_sync_status_is_requested(self): |
418 | 1248 | """The file sync status is requested to the backend.""" | 1248 | """The file sync status is requested to the backend.""" |
420 | 1249 | self.assert_backend_called('file_sync_status', ()) | 1249 | self.assert_backend_called('file_sync_status') |
421 | 1250 | 1250 | ||
422 | 1251 | def test_is_disabled(self): | 1251 | def test_is_disabled(self): |
423 | 1252 | """Until file sync status is given, the widget is disabled.""" | 1252 | """Until file sync status is given, the widget is disabled.""" |
424 | @@ -1273,10 +1273,10 @@ | |||
425 | 1273 | assert self.ui.button.get_active() | 1273 | assert self.ui.button.get_active() |
426 | 1274 | 1274 | ||
427 | 1275 | self.ui.button.set_active(not self.ui.button.get_active()) | 1275 | self.ui.button.set_active(not self.ui.button.get_active()) |
429 | 1276 | self.assert_backend_called('disable_files', ()) | 1276 | self.assert_backend_called('disable_files') |
430 | 1277 | 1277 | ||
431 | 1278 | self.ui.button.set_active(not self.ui.button.get_active()) | 1278 | self.ui.button.set_active(not self.ui.button.get_active()) |
433 | 1279 | self.assert_backend_called('enable_files', ()) | 1279 | self.assert_backend_called('enable_files') |
434 | 1280 | 1280 | ||
435 | 1281 | def test_on_file_sync_enabled(self): | 1281 | def test_on_file_sync_enabled(self): |
436 | 1282 | """When file sync is enabled, the button is active.""" | 1282 | """When file sync is enabled, the button is active.""" |
437 | @@ -1330,7 +1330,7 @@ | |||
438 | 1330 | 1330 | ||
439 | 1331 | args = (self.service_id, | 1331 | args = (self.service_id, |
440 | 1332 | {'enabled': gui.bool_str(self.ui.button.get_active())}) | 1332 | {'enabled': gui.bool_str(self.ui.button.get_active())}) |
442 | 1333 | self.assert_backend_called('change_replication_settings', args) | 1333 | self.assert_backend_called('change_replication_settings', *args) |
443 | 1334 | 1334 | ||
444 | 1335 | def test_dependency(self): | 1335 | def test_dependency(self): |
445 | 1336 | """The dependency box is None.""" | 1336 | """The dependency box is None.""" |
446 | @@ -1543,7 +1543,7 @@ | |||
447 | 1543 | self.ui.load_replications() | 1543 | self.ui.load_replications() |
448 | 1544 | 1544 | ||
449 | 1545 | self.assertTrue(self.ui.message.active) | 1545 | self.assertTrue(self.ui.message.active) |
451 | 1546 | self.assert_backend_called('replications_info', ()) | 1546 | self.assert_backend_called('replications_info') |
452 | 1547 | 1547 | ||
453 | 1548 | 1548 | ||
454 | 1549 | class ServicesWithDesktopcouchTestCase(ServicesTestCase): | 1549 | class ServicesWithDesktopcouchTestCase(ServicesTestCase): |
455 | @@ -1750,7 +1750,7 @@ | |||
456 | 1750 | def test_file_sync_status_is_requested_on_load(self): | 1750 | def test_file_sync_status_is_requested_on_load(self): |
457 | 1751 | """The file sync status is requested to the backend.""" | 1751 | """The file sync status is requested to the backend.""" |
458 | 1752 | self.ui.load() | 1752 | self.ui.load() |
460 | 1753 | self.assert_backend_called('file_sync_status', ()) | 1753 | self.assert_backend_called('file_sync_status') |
461 | 1754 | 1754 | ||
462 | 1755 | def test_on_file_sync_status_disabled(self): | 1755 | def test_on_file_sync_status_disabled(self): |
463 | 1756 | """The file sync is disabled. | 1756 | """The file sync is disabled. |
464 | @@ -1862,43 +1862,43 @@ | |||
465 | 1862 | self.ui.backend._called.clear() | 1862 | self.ui.backend._called.clear() |
466 | 1863 | self.ui.on_files_start_error({'error_msg': 'error msg'}) | 1863 | self.ui.on_files_start_error({'error_msg': 'error msg'}) |
467 | 1864 | 1864 | ||
469 | 1865 | self.assert_backend_called('file_sync_status', ()) | 1865 | self.assert_backend_called('file_sync_status') |
470 | 1866 | 1866 | ||
471 | 1867 | def test_on_connect_clicked(self): | 1867 | def test_on_connect_clicked(self): |
472 | 1868 | """User requested connection.""" | 1868 | """User requested connection.""" |
473 | 1869 | self.ui.on_connect_clicked(self.ui.button) | 1869 | self.ui.on_connect_clicked(self.ui.button) |
474 | 1870 | 1870 | ||
476 | 1871 | self.assert_backend_called('connect_files', ()) | 1871 | self.assert_backend_called('connect_files') |
477 | 1872 | 1872 | ||
478 | 1873 | def test_on_disconnect_clicked(self): | 1873 | def test_on_disconnect_clicked(self): |
479 | 1874 | """User requested disconnection.""" | 1874 | """User requested disconnection.""" |
480 | 1875 | self.ui.on_disconnect_clicked(self.ui.button) | 1875 | self.ui.on_disconnect_clicked(self.ui.button) |
481 | 1876 | 1876 | ||
483 | 1877 | self.assert_backend_called('disconnect_files', ()) | 1877 | self.assert_backend_called('disconnect_files') |
484 | 1878 | 1878 | ||
485 | 1879 | def test_on_enable_clicked(self): | 1879 | def test_on_enable_clicked(self): |
486 | 1880 | """User requested enable the service.""" | 1880 | """User requested enable the service.""" |
487 | 1881 | self.ui.on_enable_clicked(self.ui.button) | 1881 | self.ui.on_enable_clicked(self.ui.button) |
488 | 1882 | 1882 | ||
490 | 1883 | self.assert_backend_called('enable_files', ()) | 1883 | self.assert_backend_called('enable_files') |
491 | 1884 | 1884 | ||
492 | 1885 | def test_on_restart_clicked(self): | 1885 | def test_on_restart_clicked(self): |
493 | 1886 | """User requested restart the service.""" | 1886 | """User requested restart the service.""" |
494 | 1887 | self.ui.on_restart_clicked(self.ui.button) | 1887 | self.ui.on_restart_clicked(self.ui.button) |
495 | 1888 | 1888 | ||
497 | 1889 | self.assert_backend_called('restart_files', ()) | 1889 | self.assert_backend_called('restart_files') |
498 | 1890 | 1890 | ||
499 | 1891 | def test_on_start_clicked(self): | 1891 | def test_on_start_clicked(self): |
500 | 1892 | """User requested start the service.""" | 1892 | """User requested start the service.""" |
501 | 1893 | self.ui.on_start_clicked(self.ui.button) | 1893 | self.ui.on_start_clicked(self.ui.button) |
502 | 1894 | 1894 | ||
504 | 1895 | self.assert_backend_called('start_files', ()) | 1895 | self.assert_backend_called('start_files') |
505 | 1896 | 1896 | ||
506 | 1897 | def test_on_stop_clicked(self): | 1897 | def test_on_stop_clicked(self): |
507 | 1898 | """User requested stop the service.""" | 1898 | """User requested stop the service.""" |
508 | 1899 | self.ui.on_stop_clicked(self.ui.button) | 1899 | self.ui.on_stop_clicked(self.ui.button) |
509 | 1900 | 1900 | ||
511 | 1901 | self.assert_backend_called('stop_files', ()) | 1901 | self.assert_backend_called('stop_files') |
512 | 1902 | 1902 | ||
513 | 1903 | 1903 | ||
514 | 1904 | class ManagementPanelTestCase(ControlPanelMixinTestCase): | 1904 | class ManagementPanelTestCase(ControlPanelMixinTestCase): |
515 | @@ -1992,7 +1992,7 @@ | |||
516 | 1992 | def test_account_info_is_requested_on_load(self): | 1992 | def test_account_info_is_requested_on_load(self): |
517 | 1993 | """The account info is requested to the backend.""" | 1993 | """The account info is requested to the backend.""" |
518 | 1994 | self.ui.load() | 1994 | self.ui.load() |
520 | 1995 | self.assert_backend_called('account_info', ()) | 1995 | self.assert_backend_called('account_info') |
521 | 1996 | 1996 | ||
522 | 1997 | def test_file_sync_status_info_is_requested_on_load(self): | 1997 | def test_file_sync_status_info_is_requested_on_load(self): |
523 | 1998 | """The file sync status info is requested to the backend.""" | 1998 | """The file sync status info is requested to the backend.""" |
524 | 1999 | 1999 | ||
525 | === modified file 'ubuntuone/controlpanel/gui/gtk/tests/test_gui_basic.py' | |||
526 | --- ubuntuone/controlpanel/gui/gtk/tests/test_gui_basic.py 2011-05-24 16:05:30 +0000 | |||
527 | +++ ubuntuone/controlpanel/gui/gtk/tests/test_gui_basic.py 2011-08-18 17:23:16 +0000 | |||
528 | @@ -20,9 +20,14 @@ | |||
529 | 20 | 20 | ||
530 | 21 | from __future__ import division | 21 | from __future__ import division |
531 | 22 | 22 | ||
532 | 23 | from twisted.internet import defer | ||
533 | 24 | from twisted.python.failure import Failure | ||
534 | 23 | 25 | ||
535 | 24 | from ubuntuone.controlpanel.gui.gtk import gui | 26 | from ubuntuone.controlpanel.gui.gtk import gui |
537 | 25 | from ubuntuone.controlpanel.gui.gtk.tests import BaseTestCase, FakedSSOBackend | 27 | from ubuntuone.controlpanel.gui.gtk.tests import ( |
538 | 28 | BaseTestCase, | ||
539 | 29 | FakedCredentialsBackend, | ||
540 | 30 | ) | ||
541 | 26 | from ubuntuone.controlpanel.tests import TOKEN | 31 | from ubuntuone.controlpanel.tests import TOKEN |
542 | 27 | 32 | ||
543 | 28 | from ubuntuone.devtools.testcase import skipIf | 33 | from ubuntuone.devtools.testcase import skipIf |
544 | @@ -287,7 +292,7 @@ | |||
545 | 287 | """On 'credentials-found' signal, ask syncdaemon to connect.""" | 292 | """On 'credentials-found' signal, ask syncdaemon to connect.""" |
546 | 288 | # credentials are new | 293 | # credentials are new |
547 | 289 | self.ui.overview.emit('credentials-found', True, object()) | 294 | self.ui.overview.emit('credentials-found', True, object()) |
549 | 290 | self.assert_backend_called('connect_files', ()) | 295 | self.assert_backend_called('connect_files') |
550 | 291 | 296 | ||
551 | 292 | def test_local_device_removed_shows_overview_panel(self): | 297 | def test_local_device_removed_shows_overview_panel(self): |
552 | 293 | """On 'local-device-removed' signal, the overview panel is shown.""" | 298 | """On 'local-device-removed' signal, the overview panel is shown.""" |
553 | @@ -306,7 +311,7 @@ | |||
554 | 306 | def test_backend_is_shutdown_on_close(self): | 311 | def test_backend_is_shutdown_on_close(self): |
555 | 307 | """When the control panel is closed, the backend is shutdown.""" | 312 | """When the control panel is closed, the backend is shutdown.""" |
556 | 308 | self.ui.emit('destroy') | 313 | self.ui.emit('destroy') |
558 | 309 | self.assert_backend_called('shutdown', ()) | 314 | self.assert_backend_called('shutdown') |
559 | 310 | 315 | ||
560 | 311 | 316 | ||
561 | 312 | class UbuntuOneBinTestCase(BaseTestCase): | 317 | class UbuntuOneBinTestCase(BaseTestCase): |
562 | @@ -437,6 +442,11 @@ | |||
563 | 437 | klass = gui.OverviewPanel | 442 | klass = gui.OverviewPanel |
564 | 438 | kwargs = {'main_window': gui.gtk.Window()} | 443 | kwargs = {'main_window': gui.gtk.Window()} |
565 | 439 | ui_filename = 'overview.ui' | 444 | ui_filename = 'overview.ui' |
566 | 445 | backend_is_dbus = False | ||
567 | 446 | |||
568 | 447 | def setUp(self): | ||
569 | 448 | super(OverwiewPanelTestCase, self).setUp() | ||
570 | 449 | gui.gtk.link_button_set_uri_hook(lambda *a: None) | ||
571 | 440 | 450 | ||
572 | 441 | def test_is_a_greyable_bin(self): | 451 | def test_is_a_greyable_bin(self): |
573 | 442 | """Inherits from GreyableBin.""" | 452 | """Inherits from GreyableBin.""" |
574 | @@ -450,20 +460,102 @@ | |||
575 | 450 | """The 'join_now' button is the default widget.""" | 460 | """The 'join_now' button is the default widget.""" |
576 | 451 | self.assertTrue(self.ui.join_now_button.get_property('can-default')) | 461 | self.assertTrue(self.ui.join_now_button.get_property('can-default')) |
577 | 452 | 462 | ||
592 | 453 | def test_sso_backend(self): | 463 | def test_backend(self): |
593 | 454 | """Has a correct SSO backend.""" | 464 | """Has a correct backend.""" |
594 | 455 | self.assertIsInstance(self.ui.backend, FakedSSOBackend) | 465 | self.assertIsInstance(self.ui.backend, FakedCredentialsBackend) |
595 | 456 | 466 | ||
596 | 457 | def test_sso_backend_signals(self): | 467 | |
597 | 458 | """The proper signals are connected to the backend.""" | 468 | class OverwiewPanelBackendCallbacksTestCase(OverwiewPanelTestCase): |
598 | 459 | self.assertEqual(self.ui.backend._signals['CredentialsFound'], | 469 | """Proper callbacks are chained to the credentials backend methods.""" |
599 | 460 | [self.ui.on_credentials_found]) | 470 | |
600 | 461 | self.assertEqual(self.ui.backend._signals['CredentialsNotFound'], | 471 | failure = Exception() |
601 | 462 | [self.ui.on_credentials_not_found]) | 472 | |
602 | 463 | self.assertEqual(self.ui.backend._signals['CredentialsError'], | 473 | def test_find_credentials_fired_with_credentials(self): |
603 | 464 | [self.ui.on_credentials_error]) | 474 | """Test that on_credentials_found is called.""" |
604 | 465 | self.assertEqual(self.ui.backend._signals['AuthorizationDenied'], | 475 | self.ui.backend.next_result = defer.succeed(TOKEN) |
605 | 466 | [self.ui.on_authorization_denied]) | 476 | self.patch(self.ui, 'on_credentials_found', self._set_called) |
606 | 477 | |||
607 | 478 | self.ui.on_network_state_changed(gui.networkstate.ONLINE) | ||
608 | 479 | |||
609 | 480 | self.assertEqual(self._called, ((TOKEN,), {})) | ||
610 | 481 | |||
611 | 482 | def test_find_credentials_fired_without_credentials(self): | ||
612 | 483 | """Test that on_credentials_not_found is called.""" | ||
613 | 484 | self.ui.backend.next_result = defer.succeed({}) | ||
614 | 485 | self.patch(self.ui, 'on_credentials_not_found', self._set_called) | ||
615 | 486 | |||
616 | 487 | self.ui.on_network_state_changed(gui.networkstate.ONLINE) | ||
617 | 488 | |||
618 | 489 | self.assertEqual(self._called, ((), {})) | ||
619 | 490 | |||
620 | 491 | def test_find_credentials_errback(self): | ||
621 | 492 | """Test that on_credentials_error is called.""" | ||
622 | 493 | self.ui.backend.next_result = defer.fail(self.failure) | ||
623 | 494 | self.patch(self.ui, 'on_credentials_error', self._set_called) | ||
624 | 495 | |||
625 | 496 | self.ui.on_network_state_changed(gui.networkstate.ONLINE) | ||
626 | 497 | |||
627 | 498 | failure = self._called[0][0] | ||
628 | 499 | self.assertIsInstance(failure, Failure) | ||
629 | 500 | self.assertEqual(failure.value, self.failure) | ||
630 | 501 | |||
631 | 502 | def test_register_fired_with_credentials(self): | ||
632 | 503 | """Test that on_credentials_found is called.""" | ||
633 | 504 | self.ui.backend.next_result = defer.succeed(TOKEN) | ||
634 | 505 | self.patch(self.ui, 'on_credentials_found', self._set_called) | ||
635 | 506 | |||
636 | 507 | self.ui.join_now_button.clicked() | ||
637 | 508 | |||
638 | 509 | self.assertEqual(self._called, ((TOKEN,), {})) | ||
639 | 510 | |||
640 | 511 | def test_register_fired_with_credentials_none(self): | ||
641 | 512 | """Test that on_authorization_denied is called.""" | ||
642 | 513 | self.ui.backend.next_result = defer.succeed(None) | ||
643 | 514 | self.patch(self.ui, 'on_authorization_denied', self._set_called) | ||
644 | 515 | |||
645 | 516 | self.ui.join_now_button.clicked() | ||
646 | 517 | |||
647 | 518 | self.assertEqual(self._called, ((), {})) | ||
648 | 519 | |||
649 | 520 | def test_register_errback(self): | ||
650 | 521 | """Test that on_credentials_error is called.""" | ||
651 | 522 | self.ui.backend.next_result = defer.fail(self.failure) | ||
652 | 523 | self.patch(self.ui, 'on_credentials_error', self._set_called) | ||
653 | 524 | |||
654 | 525 | self.ui.join_now_button.clicked() | ||
655 | 526 | |||
656 | 527 | failure = self._called[0][0] | ||
657 | 528 | self.assertIsInstance(failure, Failure) | ||
658 | 529 | self.assertEqual(failure.value, self.failure) | ||
659 | 530 | |||
660 | 531 | def test_login_fired_with_credentials(self): | ||
661 | 532 | """Test that on_credentials_found is called.""" | ||
662 | 533 | self.ui.backend.next_result = defer.succeed(TOKEN) | ||
663 | 534 | self.patch(self.ui, 'on_credentials_found', self._set_called) | ||
664 | 535 | |||
665 | 536 | self.ui.connect_button.clicked() | ||
666 | 537 | |||
667 | 538 | self.assertEqual(self._called, ((TOKEN,), {})) | ||
668 | 539 | |||
669 | 540 | def test_login_fired_with_credentials_none(self): | ||
670 | 541 | """Test that on_authorization_denied is called.""" | ||
671 | 542 | self.ui.backend.next_result = defer.succeed(None) | ||
672 | 543 | self.patch(self.ui, 'on_authorization_denied', self._set_called) | ||
673 | 544 | |||
674 | 545 | self.ui.connect_button.clicked() | ||
675 | 546 | |||
676 | 547 | self.assertEqual(self._called, ((), {})) | ||
677 | 548 | |||
678 | 549 | def test_login_errback(self): | ||
679 | 550 | """Test that on_credentials_error is called.""" | ||
680 | 551 | self.ui.backend.next_result = defer.fail(self.failure) | ||
681 | 552 | self.patch(self.ui, 'on_credentials_error', self._set_called) | ||
682 | 553 | |||
683 | 554 | self.ui.connect_button.clicked() | ||
684 | 555 | |||
685 | 556 | failure = self._called[0][0] | ||
686 | 557 | self.assertIsInstance(failure, Failure) | ||
687 | 558 | self.assertEqual(failure.value, self.failure) | ||
688 | 467 | 559 | ||
689 | 468 | 560 | ||
690 | 469 | class OverwiewNetworkStatePanelTestCase(OverwiewPanelTestCase): | 561 | class OverwiewNetworkStatePanelTestCase(OverwiewPanelTestCase): |
691 | @@ -514,13 +606,13 @@ | |||
692 | 514 | def test_find_credentials_is_called(self): | 606 | def test_find_credentials_is_called(self): |
693 | 515 | """Credentials are asked to SSO backend.""" | 607 | """Credentials are asked to SSO backend.""" |
694 | 516 | self.assertFalse(self.ui._credentials_are_new) | 608 | self.assertFalse(self.ui._credentials_are_new) |
696 | 517 | self.assert_backend_called('find_credentials', (gui.U1_APP_NAME, {})) | 609 | self.assert_backend_called('find_credentials') |
697 | 518 | 610 | ||
698 | 519 | def test_on_credentials_found(self): | 611 | def test_on_credentials_found(self): |
699 | 520 | """Callback 'on_credentials_found' is correct.""" | 612 | """Callback 'on_credentials_found' is correct.""" |
700 | 521 | self.ui.connect('credentials-found', self._set_called) | 613 | self.ui.connect('credentials-found', self._set_called) |
701 | 522 | 614 | ||
703 | 523 | self.ui.on_credentials_found(gui.U1_APP_NAME, TOKEN) | 615 | self.ui.on_credentials_found(TOKEN) |
704 | 524 | 616 | ||
705 | 525 | self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.') | 617 | self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.') |
706 | 526 | # assume credentials were in local keyring | 618 | # assume credentials were in local keyring |
707 | @@ -531,9 +623,9 @@ | |||
708 | 531 | self.ui.connect('credentials-found', self._set_called) | 623 | self.ui.connect('credentials-found', self._set_called) |
709 | 532 | 624 | ||
710 | 533 | # credentials weren't in the system | 625 | # credentials weren't in the system |
712 | 534 | self.ui.on_credentials_not_found(gui.U1_APP_NAME) | 626 | self.ui.on_credentials_not_found() |
713 | 535 | # now they are! | 627 | # now they are! |
715 | 536 | self.ui.on_credentials_found(gui.U1_APP_NAME, TOKEN) | 628 | self.ui.on_credentials_found(TOKEN) |
716 | 537 | 629 | ||
717 | 538 | self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.') | 630 | self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.') |
718 | 539 | # assume credentials were not in local keyring | 631 | # assume credentials were not in local keyring |
719 | @@ -541,70 +633,31 @@ | |||
720 | 541 | 633 | ||
721 | 542 | def test_on_credentials_not_found(self): | 634 | def test_on_credentials_not_found(self): |
722 | 543 | """Callback 'on_credentials_not_found' is correct.""" | 635 | """Callback 'on_credentials_not_found' is correct.""" |
724 | 544 | self.ui.on_credentials_not_found(gui.U1_APP_NAME) | 636 | self.ui.on_credentials_not_found() |
725 | 545 | self.assertTrue(self.ui.get_visible()) | 637 | self.assertTrue(self.ui.get_visible()) |
726 | 546 | self.assertTrue(self.ui._credentials_are_new) | 638 | self.assertTrue(self.ui._credentials_are_new) |
727 | 547 | 639 | ||
728 | 548 | def test_on_credentials_error(self): | 640 | def test_on_credentials_error(self): |
729 | 549 | """Callback 'on_credentials_error' is correct.""" | 641 | """Callback 'on_credentials_error' is correct.""" |
731 | 550 | self.ui.on_credentials_error(gui.U1_APP_NAME, {}) | 642 | self.ui.on_credentials_error({}) |
732 | 551 | self.assertTrue(self.ui.get_visible()) | 643 | self.assertTrue(self.ui.get_visible()) |
733 | 552 | self.assert_warning_correct(self.ui.warning_label, | 644 | self.assert_warning_correct(self.ui.warning_label, |
734 | 553 | gui.CREDENTIALS_ERROR) | 645 | gui.CREDENTIALS_ERROR) |
735 | 554 | 646 | ||
736 | 555 | def test_on_authorization_denied(self): | 647 | def test_on_authorization_denied(self): |
737 | 556 | """Callback 'on_authorization_denied' is correct.""" | 648 | """Callback 'on_authorization_denied' is correct.""" |
739 | 557 | self.ui.on_authorization_denied(gui.U1_APP_NAME) | 649 | self.ui.on_authorization_denied() |
740 | 558 | self.assertTrue(self.ui.get_visible()) | 650 | self.assertTrue(self.ui.get_visible()) |
741 | 559 | self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.') | 651 | self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.') |
742 | 560 | self.assertEqual(self.ui.warning_label.get_text(), '') | 652 | self.assertEqual(self.ui.warning_label.get_text(), '') |
743 | 561 | 653 | ||
744 | 562 | 654 | ||
745 | 563 | class OverwiewPanelAppNameMismatchTestCase(OverwiewPanelTestCase): | ||
746 | 564 | """The test suite for the overview panel when the app_name won't match.""" | ||
747 | 565 | |||
748 | 566 | NOT_U1_APP = 'Not ' + gui.U1_APP_NAME | ||
749 | 567 | |||
750 | 568 | def test_filter_by_app_name(self): | ||
751 | 569 | """The filter_by_app_name decorator is correct.""" | ||
752 | 570 | f = gui.filter_by_app_name(self._set_called) | ||
753 | 571 | f(self.ui, self.NOT_U1_APP) | ||
754 | 572 | self.assertFalse(self._called) | ||
755 | 573 | self.assertTrue(self.memento.check_info('ignoring', self.NOT_U1_APP)) | ||
756 | 574 | |||
757 | 575 | args = ('test', object()) | ||
758 | 576 | kwargs = {'really': 'AWESOME'} | ||
759 | 577 | f(self.ui, gui.U1_APP_NAME, *args, **kwargs) | ||
760 | 578 | self.assertEqual(self._called, | ||
761 | 579 | ((self.ui, gui.U1_APP_NAME,) + args, kwargs)) | ||
762 | 580 | |||
763 | 581 | def test_on_credentials_found(self): | ||
764 | 582 | """Callback 'on_credentials_found' is not executed.""" | ||
765 | 583 | self.assert_function_decorated(gui.filter_by_app_name, | ||
766 | 584 | self.ui.on_credentials_found) | ||
767 | 585 | |||
768 | 586 | def test_on_credentials_not_found(self): | ||
769 | 587 | """Callback 'on_credentials_not_found' is not executed.""" | ||
770 | 588 | self.assert_function_decorated(gui.filter_by_app_name, | ||
771 | 589 | self.ui.on_credentials_not_found) | ||
772 | 590 | |||
773 | 591 | def test_on_credentials_error(self): | ||
774 | 592 | """Callback 'on_credentials_error' is not executed.""" | ||
775 | 593 | self.assert_function_decorated(gui.filter_by_app_name, | ||
776 | 594 | self.ui.on_credentials_error) | ||
777 | 595 | |||
778 | 596 | def test_on_authorization_denied(self): | ||
779 | 597 | """Callback 'on_authorization_denied' is not executed.""" | ||
780 | 598 | self.assert_function_decorated(gui.filter_by_app_name, | ||
781 | 599 | self.ui.on_authorization_denied) | ||
782 | 600 | |||
783 | 601 | |||
784 | 602 | class OverwiewPanelNoCredsTestCase(OverwiewPanelTestCase): | 655 | class OverwiewPanelNoCredsTestCase(OverwiewPanelTestCase): |
785 | 603 | """The test suite for the overview panel when no credentials are found.""" | 656 | """The test suite for the overview panel when no credentials are found.""" |
786 | 604 | 657 | ||
787 | 605 | def setUp(self): | 658 | def setUp(self): |
788 | 606 | super(OverwiewPanelNoCredsTestCase, self).setUp() | 659 | super(OverwiewPanelNoCredsTestCase, self).setUp() |
790 | 607 | self.ui.on_credentials_not_found(gui.U1_APP_NAME) | 660 | self.ui.on_credentials_not_found() |
791 | 608 | 661 | ||
792 | 609 | def test_startup_visibility(self): | 662 | def test_startup_visibility(self): |
793 | 610 | """The widget is visible at startup.""" | 663 | """The widget is visible at startup.""" |
794 | @@ -631,12 +684,8 @@ | |||
795 | 631 | self.ui.join_now_button.clicked() | 684 | self.ui.join_now_button.clicked() |
796 | 632 | 685 | ||
797 | 633 | window_id = self.kwargs['main_window'].window.xid | 686 | window_id = self.kwargs['main_window'].window.xid |
804 | 634 | args = (gui.U1_APP_NAME, | 687 | kwargs = {'window_id': str(window_id)} |
805 | 635 | {gui.TC_URL_KEY: gui.U1_TC_URL, | 688 | self.assert_backend_called('register', **kwargs) |
800 | 636 | gui.HELP_TEXT_KEY: gui.U1_DESCRIPTION, | ||
801 | 637 | gui.WINDOW_ID_KEY: str(window_id), | ||
802 | 638 | gui.PING_URL_KEY: gui.U1_PING_URL}) | ||
803 | 639 | self.assert_backend_called('register', args) | ||
806 | 640 | 689 | ||
807 | 641 | def test_connect_button_clicked(self): | 690 | def test_connect_button_clicked(self): |
808 | 642 | """Test the 'join now' button callback.""" | 691 | """Test the 'join now' button callback.""" |
809 | @@ -646,12 +695,8 @@ | |||
810 | 646 | self.ui.connect_button.clicked() | 695 | self.ui.connect_button.clicked() |
811 | 647 | 696 | ||
812 | 648 | window_id = self.kwargs['main_window'].window.xid | 697 | window_id = self.kwargs['main_window'].window.xid |
819 | 649 | args = (gui.U1_APP_NAME, | 698 | kwargs = {'window_id': str(window_id)} |
820 | 650 | {gui.TC_URL_KEY: gui.U1_TC_URL, | 699 | self.assert_backend_called('login', **kwargs) |
815 | 651 | gui.HELP_TEXT_KEY: gui.U1_DESCRIPTION, | ||
816 | 652 | gui.WINDOW_ID_KEY: str(window_id), | ||
817 | 653 | gui.PING_URL_KEY: gui.U1_PING_URL}) | ||
818 | 654 | self.assert_backend_called('login', args) | ||
821 | 655 | 700 | ||
822 | 656 | def test_join_now_button_clicked_set_greyed(self): | 701 | def test_join_now_button_clicked_set_greyed(self): |
823 | 657 | """Clicking on 'join_now' self is greyed.""" | 702 | """Clicking on 'join_now' self is greyed.""" |
824 | @@ -660,7 +705,7 @@ | |||
825 | 660 | 705 | ||
826 | 661 | def test_join_now_button_clicked_removes_warning(self): | 706 | def test_join_now_button_clicked_removes_warning(self): |
827 | 662 | """Clicking on 'join_now' the warnings are removed.""" | 707 | """Clicking on 'join_now' the warnings are removed.""" |
829 | 663 | self.ui.on_authorization_denied(gui.U1_APP_NAME) # show warning | 708 | self.ui.on_authorization_denied() # show warning |
830 | 664 | self.ui.join_now_button.clicked() | 709 | self.ui.join_now_button.clicked() |
831 | 665 | 710 | ||
832 | 666 | self.assertEqual(self.ui.warning_label.get_text(), '') | 711 | self.assertEqual(self.ui.warning_label.get_text(), '') |
833 | @@ -672,7 +717,7 @@ | |||
834 | 672 | 717 | ||
835 | 673 | def test_connect_button_clicked_removes_warning(self): | 718 | def test_connect_button_clicked_removes_warning(self): |
836 | 674 | """Clicking on 'connect' the warnings are removed.""" | 719 | """Clicking on 'connect' the warnings are removed.""" |
838 | 675 | self.ui.on_authorization_denied(gui.U1_APP_NAME) # show warning | 720 | self.ui.on_authorization_denied() # show warning |
839 | 676 | self.ui.connect_button.clicked() | 721 | self.ui.connect_button.clicked() |
840 | 677 | 722 | ||
841 | 678 | self.assertEqual(self.ui.warning_label.get_text(), '') | 723 | self.assertEqual(self.ui.warning_label.get_text(), '') |
842 | @@ -688,21 +733,21 @@ | |||
843 | 688 | def test_on_credentials_not_found_unset_greyed(self): | 733 | def test_on_credentials_not_found_unset_greyed(self): |
844 | 689 | """Callback 'on_credentials_not_found' unsets the 'greyed' prop.""" | 734 | """Callback 'on_credentials_not_found' unsets the 'greyed' prop.""" |
845 | 690 | self.ui.connect_button.clicked() | 735 | self.ui.connect_button.clicked() |
847 | 691 | self.ui.on_credentials_not_found(gui.U1_APP_NAME) | 736 | self.ui.on_credentials_not_found() |
848 | 692 | 737 | ||
849 | 693 | self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.') | 738 | self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.') |
850 | 694 | 739 | ||
851 | 695 | def test_on_credentials_error_unset_greyed(self): | 740 | def test_on_credentials_error_unset_greyed(self): |
852 | 696 | """Callback 'on_credentials_error' unsets the 'greyed' prop.""" | 741 | """Callback 'on_credentials_error' unsets the 'greyed' prop.""" |
853 | 697 | self.ui.connect_button.clicked() | 742 | self.ui.connect_button.clicked() |
855 | 698 | self.ui.on_credentials_error(gui.U1_APP_NAME, {}) | 743 | self.ui.on_credentials_error({}) |
856 | 699 | 744 | ||
857 | 700 | self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.') | 745 | self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.') |
858 | 701 | 746 | ||
859 | 702 | def test_on_authorization_denied_unset_greyed(self): | 747 | def test_on_authorization_denied_unset_greyed(self): |
860 | 703 | """Callback 'on_authorization_denied' unsets the 'greyed' prop.""" | 748 | """Callback 'on_authorization_denied' unsets the 'greyed' prop.""" |
861 | 704 | self.ui.connect_button.clicked() | 749 | self.ui.connect_button.clicked() |
863 | 705 | self.ui.on_authorization_denied(gui.U1_APP_NAME) | 750 | self.ui.on_authorization_denied() |
864 | 706 | 751 | ||
865 | 707 | self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.') | 752 | self.assertFalse(self.ui.get_property('greyed'), 'Must not be greyed.') |
866 | 708 | 753 | ||
867 | 709 | 754 | ||
868 | === modified file 'ubuntuone/controlpanel/login_client.py' | |||
869 | --- ubuntuone/controlpanel/login_client.py 2011-06-17 15:56:54 +0000 | |||
870 | +++ ubuntuone/controlpanel/login_client.py 2011-08-18 17:23:16 +0000 | |||
871 | @@ -18,14 +18,15 @@ | |||
872 | 18 | 18 | ||
873 | 19 | """Client to access Ubuntu One credentials.""" | 19 | """Client to access Ubuntu One credentials.""" |
874 | 20 | 20 | ||
875 | 21 | # pylint: disable=E0611, F0401 | ||
876 | 22 | from ubuntuone.platform.credentials import CredentialsManagementTool | ||
877 | 23 | # pylint: enable=E0611, F0401 | ||
878 | 24 | |||
879 | 21 | 25 | ||
880 | 22 | def get_sso_proxy(): | 26 | def get_sso_proxy(): |
881 | 23 | """Return a login client.""" | 27 | """Return a login client.""" |
887 | 24 | # No name 'credentials' in module 'ubuntuone.platform' | 28 | result = CredentialsManagementTool() |
888 | 25 | # Reimport 'credentials' (imported line 22) | 29 | return result |
884 | 26 | # pylint: disable=E0611,W0404 | ||
885 | 27 | from ubuntuone.platform import credentials | ||
886 | 28 | return credentials.CredentialsManagementTool() | ||
889 | 29 | 30 | ||
890 | 30 | 31 | ||
891 | 31 | def get_credentials(): | 32 | def get_credentials(): |
892 | @@ -38,3 +39,15 @@ | |||
893 | 38 | """Clear the credentials for Ubuntu One.""" | 39 | """Clear the credentials for Ubuntu One.""" |
894 | 39 | proxy = get_sso_proxy() | 40 | proxy = get_sso_proxy() |
895 | 40 | return proxy.clear_credentials() | 41 | return proxy.clear_credentials() |
896 | 42 | |||
897 | 43 | |||
898 | 44 | def login(*args, **kwargs): | ||
899 | 45 | """Get the credentials for Ubuntu One offering the user to login.""" | ||
900 | 46 | proxy = get_sso_proxy() | ||
901 | 47 | return proxy.login(*args, **kwargs) | ||
902 | 48 | |||
903 | 49 | |||
904 | 50 | def register(*args, **kwargs): | ||
905 | 51 | """Get the credentials for Ubuntu One offering the user to register.""" | ||
906 | 52 | proxy = get_sso_proxy() | ||
907 | 53 | return proxy.register(*args, **kwargs) | ||
908 | 41 | 54 | ||
909 | === modified file 'ubuntuone/controlpanel/tests/test_login_client.py' | |||
910 | --- ubuntuone/controlpanel/tests/test_login_client.py 2011-06-17 15:56:54 +0000 | |||
911 | +++ ubuntuone/controlpanel/tests/test_login_client.py 2011-08-18 17:23:16 +0000 | |||
912 | @@ -19,10 +19,6 @@ | |||
913 | 19 | """Tests for the service when accessing the login client.""" | 19 | """Tests for the service when accessing the login client.""" |
914 | 20 | 20 | ||
915 | 21 | from twisted.internet import defer | 21 | from twisted.internet import defer |
916 | 22 | # No name 'credentials' in module 'ubuntuone.platform' | ||
917 | 23 | # pylint: disable=E0611 | ||
918 | 24 | from ubuntuone.platform import credentials | ||
919 | 25 | # pylint: enable=E0611 | ||
920 | 26 | 22 | ||
921 | 27 | from ubuntuone.controlpanel import login_client | 23 | from ubuntuone.controlpanel import login_client |
922 | 28 | from ubuntuone.controlpanel.tests import TestCase, TOKEN | 24 | from ubuntuone.controlpanel.tests import TestCase, TOKEN |
923 | @@ -49,13 +45,23 @@ | |||
924 | 49 | FakedCredentialsManagementTool.credentials = None | 45 | FakedCredentialsManagementTool.credentials = None |
925 | 50 | yield | 46 | yield |
926 | 51 | 47 | ||
927 | 48 | @defer.inlineCallbacks | ||
928 | 49 | def login(self): | ||
929 | 50 | """Create credentials for Ubuntu One by logging in.""" | ||
930 | 51 | yield defer.succeed(FakedCredentialsManagementTool.credentials) | ||
931 | 52 | |||
932 | 53 | @defer.inlineCallbacks | ||
933 | 54 | def register(self): | ||
934 | 55 | """Create credentials for Ubuntu One by registering.""" | ||
935 | 56 | yield defer.succeed(FakedCredentialsManagementTool.credentials) | ||
936 | 57 | |||
937 | 52 | 58 | ||
938 | 53 | class BaseTestCase(TestCase): | 59 | class BaseTestCase(TestCase): |
939 | 54 | """Base TestCase for the login client methods.""" | 60 | """Base TestCase for the login client methods.""" |
940 | 55 | 61 | ||
941 | 56 | def setUp(self): | 62 | def setUp(self): |
942 | 57 | super(BaseTestCase, self).setUp() | 63 | super(BaseTestCase, self).setUp() |
944 | 58 | self.patch(credentials, 'CredentialsManagementTool', | 64 | self.patch(login_client, 'CredentialsManagementTool', |
945 | 59 | FakedCredentialsManagementTool) | 65 | FakedCredentialsManagementTool) |
946 | 60 | FakedCredentialsManagementTool.credentials = TOKEN | 66 | FakedCredentialsManagementTool.credentials = TOKEN |
947 | 61 | 67 | ||
948 | @@ -87,7 +93,7 @@ | |||
949 | 87 | 93 | ||
950 | 88 | @defer.inlineCallbacks | 94 | @defer.inlineCallbacks |
951 | 89 | def test_clear_credentials(self): | 95 | def test_clear_credentials(self): |
953 | 90 | """The credentials are properly retrieved.""" | 96 | """The credentials are properly cleared.""" |
954 | 91 | yield login_client.clear_credentials() | 97 | yield login_client.clear_credentials() |
955 | 92 | self.assertEqual(None, FakedCredentialsManagementTool.credentials) | 98 | self.assertEqual(None, FakedCredentialsManagementTool.credentials) |
956 | 93 | 99 | ||
957 | @@ -98,3 +104,39 @@ | |||
958 | 98 | self.fake_fail) | 104 | self.fake_fail) |
959 | 99 | yield self.assertFailure(login_client.clear_credentials(), | 105 | yield self.assertFailure(login_client.clear_credentials(), |
960 | 100 | CustomError) | 106 | CustomError) |
961 | 107 | |||
962 | 108 | |||
963 | 109 | class LoginTestCase(BaseTestCase): | ||
964 | 110 | """Test for the login method.""" | ||
965 | 111 | |||
966 | 112 | @defer.inlineCallbacks | ||
967 | 113 | def test_login(self): | ||
968 | 114 | """The credentials are properly retrieved.""" | ||
969 | 115 | yield login_client.login() | ||
970 | 116 | self.assertEqual(TOKEN, FakedCredentialsManagementTool.credentials) | ||
971 | 117 | |||
972 | 118 | @defer.inlineCallbacks | ||
973 | 119 | def test_login_throws_an_error(self): | ||
974 | 120 | """If login fails, the error is propagated.""" | ||
975 | 121 | self.patch(FakedCredentialsManagementTool, 'login', | ||
976 | 122 | self.fake_fail) | ||
977 | 123 | yield self.assertFailure(login_client.login(), | ||
978 | 124 | CustomError) | ||
979 | 125 | |||
980 | 126 | |||
981 | 127 | class RegisterTestCase(BaseTestCase): | ||
982 | 128 | """Test for the register method.""" | ||
983 | 129 | |||
984 | 130 | @defer.inlineCallbacks | ||
985 | 131 | def test_register(self): | ||
986 | 132 | """The credentials are properly retrieved.""" | ||
987 | 133 | yield login_client.register() | ||
988 | 134 | self.assertEqual(TOKEN, FakedCredentialsManagementTool.credentials) | ||
989 | 135 | |||
990 | 136 | @defer.inlineCallbacks | ||
991 | 137 | def test_register_throws_an_error(self): | ||
992 | 138 | """If register fails, the error is propagated.""" | ||
993 | 139 | self.patch(FakedCredentialsManagementTool, 'register', | ||
994 | 140 | self.fake_fail) | ||
995 | 141 | yield self.assertFailure(login_client.register(), | ||
996 | 142 | CustomError) |
+1