Merge lp:~elopio/ubuntuone-credentials/python3 into lp:ubuntuone-credentials

Proposed by Leo Arias
Status: Merged
Approved by: dobey
Approved revision: 100
Merged at revision: 98
Proposed branch: lp:~elopio/ubuntuone-credentials/python3
Merge into: lp:ubuntuone-credentials
Diff against target: 483 lines (+73/-93)
8 files modified
debian/control (+4/-4)
online-accounts-provider/tests/CMakeLists.txt (+3/-4)
online-accounts-provider/tests/autopilot/ubuntuone_credentials/__init__.py (+15/-35)
online-accounts-provider/tests/autopilot/ubuntuone_credentials/base.py (+10/-12)
online-accounts-provider/tests/autopilot/ubuntuone_credentials/fake_servers.py (+10/-9)
online-accounts-provider/tests/autopilot/ubuntuone_credentials/test_existing_account.py (+4/-4)
online-accounts-provider/tests/autopilot/ubuntuone_credentials/test_fixture_setup.py (+6/-6)
online-accounts-provider/tests/autopilot/ubuntuone_credentials/test_new_account.py (+21/-19)
To merge this branch: bzr merge lp:~elopio/ubuntuone-credentials/python3
Reviewer Review Type Date Requested Status
dobey (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+224927@code.launchpad.net

Commit message

Ported the autopilot tests to python3.
Refactored and updated the tests to use new helpers and to be more consistent with the rest of packages.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
dobey (dobey) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2014-05-13 08:28:24 +0000
3+++ debian/control 2014-06-29 09:58:30 +0000
4@@ -11,7 +11,7 @@
5 qtbase5-dev,
6 qtdeclarative5-dev,
7 qtdeclarative5-ubuntu-ui-toolkit-plugin,
8- python (>= 2.7),
9+ python3-all,
10 signon-plugins-dev,
11 ubuntu-ui-toolkit-autopilot,
12 xvfb,
13@@ -42,9 +42,9 @@
14 Architecture: all
15 Depends:
16 libautopilot-qt (>= 1.4),
17- python-autopilot,
18- python-fixtures,
19- python-testtools,
20+ python3-autopilot,
21+ python3-fixtures,
22+ python3-testtools,
23 qtdeclarative5-online-accounts-client0.1,
24 qtdeclarative5-qtquick2-plugin,
25 qtdeclarative5-test-plugin,
26
27=== modified file 'online-accounts-provider/tests/CMakeLists.txt'
28--- online-accounts-provider/tests/CMakeLists.txt 2014-01-30 18:46:46 +0000
29+++ online-accounts-provider/tests/CMakeLists.txt 2014-06-29 09:58:30 +0000
30@@ -3,13 +3,13 @@
31 set (AUTOPILOT_PACKAGE ubuntuone_credentials)
32
33 add_custom_target(online-accounts-provider-autopilot-tests
34- COMMAND autopilot run ${AUTOPILOT_PACKAGE}
35+ COMMAND autopilot3 run ${AUTOPILOT_PACKAGE}
36 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/autopilot
37 DEPENDS ${QML_PLUGIN_NAME}
38 )
39
40 add_custom_target(online-accounts-provider-autopilot-tests-local
41- COMMAND SSO_AUTH_BASE_URL=fake SSO_UONE_BASE_URL=fake autopilot run ${AUTOPILOT_PACKAGE}
42+ COMMAND SSO_AUTH_BASE_URL=fake SSO_UONE_BASE_URL=fake autopilot3 run ${AUTOPILOT_PACKAGE}
43 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/autopilot
44 DEPENDS ${QML_PLUGIN_NAME}
45 )
46@@ -18,13 +18,12 @@
47 COMMAND qmltestrunner -input ${CMAKE_CURRENT_SOURCE_DIR}/unit
48 )
49
50-set (Python_ADDITIONAL_VERSIONS 2.7)
51 find_package (PythonInterp)
52
53 set (AUTOPILOT_DIR autopilot/ubuntuone_credentials)
54
55 execute_process (
56- COMMAND ${PYTHON_EXECUTABLE} -c "from distutils import sysconfig; print sysconfig.get_python_lib()"
57+ COMMAND python3 -c "from distutils import sysconfig; print(sysconfig.get_python_lib())"
58 COMMAND sed -r -e "s|^/usr/(local/)?||g"
59 OUTPUT_VARIABLE PYTHON_PACKAGE_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
60
61
62=== renamed file 'online-accounts-provider/tests/autopilot/ubuntuone_credentials/emulators.py' => 'online-accounts-provider/tests/autopilot/ubuntuone_credentials/__init__.py'
63--- online-accounts-provider/tests/autopilot/ubuntuone_credentials/emulators.py 2013-10-25 21:53:34 +0000
64+++ online-accounts-provider/tests/autopilot/ubuntuone_credentials/__init__.py 2014-06-29 09:58:30 +0000
65@@ -1,6 +1,6 @@
66 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
67 #
68-# Copyright (C) 2013 Canonical Ltd.
69+# Copyright (C) 2013-2014 Canonical Ltd.
70 #
71 # This program is free software; you can redistribute it and/or modify
72 # it under the terms of the GNU General Public License version 3, as published
73@@ -14,13 +14,12 @@
74 # You should have received a copy of the GNU General Public License
75 # along with this program. If not, see <http://www.gnu.org/licenses/>.
76
77-from autopilot import input
78-
79-from ubuntuuitoolkit import emulators as toolkit_emulators
80-
81-
82-class NewAccount(toolkit_emulators.UbuntuUIToolkitEmulatorBase):
83- """New Account Autopilot emulator."""
84+import ubuntuuitoolkit
85+
86+
87+class NewAccount(ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
88+
89+ """New Account Autopilot helper."""
90
91 def is_error_label_visible(self):
92 error_label = self.select_single(objectName='errorLabel')
93@@ -32,7 +31,7 @@
94
95 def enter_twofactor_code(self, twoFactorCode):
96 two_factor_text_field = self.select_single(
97- TextField, objectName='twoFactorTextField')
98+ ubuntuuitoolkit.TextField, objectName='twoFactorTextField')
99 two_factor_text_field.write(twoFactorCode)
100 self._click_continue()
101
102@@ -42,12 +41,12 @@
103
104 def _enter_email(self, email):
105 email_text_field = self.select_single(
106- TextField, objectName='emailTextField')
107+ ubuntuuitoolkit.TextField, objectName='emailTextField')
108 email_text_field.write(email)
109
110 def _enter_login_password(self, password):
111 password_text_field = self.select_single(
112- TextField, objectName='loginFormPasswordTextField')
113+ ubuntuuitoolkit.TextField, objectName='loginFormPasswordTextField')
114 password_text_field.write(password)
115
116 def _click_continue(self):
117@@ -67,48 +66,29 @@
118
119 def _switch_to_new_account(self):
120 new_user_switch = self.select_single(
121- toolkit_emulators.CheckBox, objectName='newUserToggleSwitch')
122+ ubuntuuitoolkit.CheckBox, objectName='newUserToggleSwitch')
123 new_user_switch.check()
124
125 def _enter_name(self, name):
126 name_text_field = self.select_single(
127- TextField, objectName='nameTextField')
128+ ubuntuuitoolkit.TextField, objectName='nameTextField')
129 name_text_field.write(name)
130
131 def _enter_password_new_user(self, password):
132 password_text_field = self.select_single(
133- TextField, objectName='passwordTextField')
134+ ubuntuuitoolkit.TextField, objectName='passwordTextField')
135 password_text_field.write(password)
136
137 def _enter_password_confirmation(self, password_confirmation):
138 confirm_password_text_field = self.select_single(
139- TextField, objectName='confirmPasswordTextField')
140+ ubuntuuitoolkit.TextField, objectName='confirmPasswordTextField')
141 confirm_password_text_field.write(password_confirmation)
142
143 def _agree_to_terms(self, agree):
144 terms_and_conditions_check_box = self.select_single(
145- toolkit_emulators.CheckBox,
146+ ubuntuuitoolkit.CheckBox,
147 objectName='termsAndConditionsCheckBox')
148 if agree:
149 terms_and_conditions_check_box.check()
150 else:
151 terms_and_conditions_check_box.uncheck()
152-
153-
154-class TextField(toolkit_emulators.UbuntuUIToolkitEmulatorBase):
155- """TextField Autopilot emulator."""
156- # TODO change this to use the text field emulator, once it lands on
157- # ubuntu-ui-toolkit. --elopio - 2013-10-08
158-
159- def __init__(self, *args):
160- super(TextField, self).__init__(*args)
161- self.keyboard = input.Keyboard.create()
162-
163- def write(self, text):
164- """Write into the text field.
165-
166- :parameter text: The text to write.
167-
168- """
169- self.pointing_device.click_object(self)
170- self.keyboard.type(text)
171
172=== renamed file 'online-accounts-provider/tests/autopilot/ubuntuone_credentials/__init__.py' => 'online-accounts-provider/tests/autopilot/ubuntuone_credentials/base.py'
173--- online-accounts-provider/tests/autopilot/ubuntuone_credentials/__init__.py 2014-01-24 15:43:27 +0000
174+++ online-accounts-provider/tests/autopilot/ubuntuone_credentials/base.py 2014-06-29 09:58:30 +0000
175@@ -21,14 +21,10 @@
176 import tempfile
177
178 import fixtures
179+import ubuntuuitoolkit
180 from autopilot import input
181 from autopilot.matchers import Eventually
182 from testtools.matchers import Equals
183-from ubuntuuitoolkit import (
184- base,
185- emulators as toolkit_emulators,
186- tests as toolkit_tests
187-)
188
189 from ubuntuone_credentials import fixture_setup
190
191@@ -43,7 +39,7 @@
192 os.path.dirname(__file__), '..', '..', '..'))
193
194
195-class TestCaseWithQMLWrapper(base.UbuntuUIToolkitAppTestCase):
196+class TestCaseWithQMLWrapper(ubuntuuitoolkit.base.UbuntuUIToolkitAppTestCase):
197
198 _DESKTOP_FILE_CONTENTS = ("""[Desktop Entry]
199 Type=Application
200@@ -71,7 +67,8 @@
201
202 def use_qml2_import_path_for_fake_wrapper(self):
203 arch = subprocess.check_output(
204- ["dpkg-architecture", "-qDEB_HOST_MULTIARCH"]).strip()
205+ ["dpkg-architecture", "-qDEB_HOST_MULTIARCH"],
206+ universal_newlines=True).strip()
207 system_settings_path = (
208 '/usr/lib/{}/ubuntu-system-settings/private'.format(arch))
209 qml_credentials_path = os.path.join(
210@@ -86,26 +83,27 @@
211 desktop_file_path = self._write_test_desktop_file()
212 self.addCleanup(os.remove, desktop_file_path)
213 self.app = self.launch_test_application(
214- base.get_qmlscene_launch_command(),
215+ ubuntuuitoolkit.base.get_qmlscene_launch_command(),
216 '-I' + _get_module_include_path(),
217 qml_file_path,
218 '--desktop_file_hint={0}'.format(desktop_file_path),
219- emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase,
220+ emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase,
221 app_type='qt')
222
223 self.assertThat(
224 self.main_view.visible, Eventually(Equals(True)))
225
226 def _write_test_desktop_file(self):
227- desktop_file_dir = toolkit_tests.get_local_desktop_file_directory()
228+ desktop_file_dir = (
229+ ubuntuuitoolkit.tests.get_local_desktop_file_directory())
230 if not os.path.exists(desktop_file_dir):
231 os.makedirs(desktop_file_dir)
232 desktop_file = tempfile.NamedTemporaryFile(
233- suffix='.desktop', dir=desktop_file_dir, delete=False)
234+ mode='w+t', suffix='.desktop', dir=desktop_file_dir, delete=False)
235 desktop_file.write(self._DESKTOP_FILE_CONTENTS)
236 desktop_file.close()
237 return desktop_file.name
238
239 @property
240 def main_view(self):
241- return self.app.select_single(toolkit_emulators.MainView)
242+ return self.app.select_single(ubuntuuitoolkit.MainView)
243
244=== modified file 'online-accounts-provider/tests/autopilot/ubuntuone_credentials/fake_servers.py'
245--- online-accounts-provider/tests/autopilot/ubuntuone_credentials/fake_servers.py 2014-01-27 06:30:26 +0000
246+++ online-accounts-provider/tests/autopilot/ubuntuone_credentials/fake_servers.py 2014-06-29 09:58:30 +0000
247@@ -14,23 +14,23 @@
248 # You should have received a copy of the GNU General Public License
249 # along with this program. If not, see <http://www.gnu.org/licenses/>.
250
251-import BaseHTTPServer
252+import http.server
253 import json
254 import logging
255-import urlparse
256+import urllib.parse
257
258
259 logger = logging.getLogger(__name__)
260
261
262-class FakeSSOAndU1Server(BaseHTTPServer.HTTPServer, object):
263+class FakeSSOAndU1Server(http.server.HTTPServer, object):
264
265 def __init__(self, server_address):
266 super(FakeSSOAndU1Server, self).__init__(
267 server_address, FakeSSOAndU1RequestHandler)
268
269
270-class FakeSSOAndU1RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
271+class FakeSSOAndU1RequestHandler(http.server.BaseHTTPRequestHandler):
272
273 SSO_API_PATH = '/api/v2'
274
275@@ -85,8 +85,8 @@
276
277 def do_GET(self):
278 """Handle GET as if we were the one.ubuntu.com server."""
279- parsed_path = urlparse.urlparse(self.path)
280- query_dict = urlparse.parse_qs(parsed_path.query)
281+ parsed_path = urllib.parse.urlparse(self.path)
282+ query_dict = urllib.parse.parse_qs(parsed_path.query)
283
284 if parsed_path.path.startswith('/oauth/sso-finished-so-get-tokens/'):
285 self._handle_get_tokens(query_dict)
286@@ -103,12 +103,13 @@
287 else:
288 self.send_response(200)
289 self.end_headers()
290- self.wfile.write("ok 0/0") # fake format of server's real response
291+ # fake format of server's real response
292+ self.wfile.write("ok 0/0".encode())
293
294 def do_POST(self):
295 """Handle POST as if we are the login.ubuntu.com server."""
296 length = int(self.headers['Content-Length'])
297- post_data = self.rfile.read(length)
298+ post_data = self.rfile.read(length).decode('utf-8')
299 if post_data == '':
300 logger.debug('NOTE: empty post data, just dropping the request.')
301 else:
302@@ -136,7 +137,7 @@
303 self.send_response(code)
304 self.send_header('Content-Type', 'application/json')
305 self.end_headers()
306- self.wfile.write(reply_json)
307+ self.wfile.write(reply_json.encode())
308
309 def _handle_login(self, body_dict):
310 if ('email' not in body_dict or 'password' not in body_dict or
311
312=== modified file 'online-accounts-provider/tests/autopilot/ubuntuone_credentials/test_existing_account.py'
313--- online-accounts-provider/tests/autopilot/ubuntuone_credentials/test_existing_account.py 2014-01-24 15:43:27 +0000
314+++ online-accounts-provider/tests/autopilot/ubuntuone_credentials/test_existing_account.py 2014-06-29 09:58:30 +0000
315@@ -19,10 +19,10 @@
316 from autopilot.matchers import Eventually
317 from testtools.matchers import Equals
318
319-import ubuntuone_credentials
320-
321-
322-class ExistingUOAAccountTestCase(ubuntuone_credentials.TestCaseWithQMLWrapper):
323+from ubuntuone_credentials import base
324+
325+
326+class ExistingUOAAccountTestCase(base.TestCaseWithQMLWrapper):
327
328 test_qml_wrapper_file_name = 'TestWrapperExisting.qml'
329
330
331=== modified file 'online-accounts-provider/tests/autopilot/ubuntuone_credentials/test_fixture_setup.py'
332--- online-accounts-provider/tests/autopilot/ubuntuone_credentials/test_fixture_setup.py 2014-01-27 06:28:01 +0000
333+++ online-accounts-provider/tests/autopilot/ubuntuone_credentials/test_fixture_setup.py 2014-06-29 09:58:30 +0000
334@@ -14,8 +14,8 @@
335 # You should have received a copy of the GNU General Public License
336 # along with this program. If not, see <http://www.gnu.org/licenses/>.
337
338-import httplib
339-import urlparse
340+import http.client
341+import urllib.parse
342
343 import testtools
344
345@@ -30,10 +30,10 @@
346 self.addCleanup(self.assert_server_not_running)
347 self.useFixture(fake_search_server)
348
349- self.netloc = urlparse.urlparse(fake_search_server.url).netloc
350+ self.netloc = urllib.parse.urlparse(fake_search_server.url).netloc
351
352 def assert_server_not_running(self):
353- connection = httplib.HTTPConnection(self.netloc)
354+ connection = http.client.HTTPConnection(self.netloc)
355 self.assertRaises(Exception, self.do_get_request, connection)
356
357 def do_get_request(self, connection):
358@@ -43,14 +43,14 @@
359 connection.request('POST', '/api/v2/tokens/oauth', 'dummy body')
360
361 def test_fake_sso_and_u1_server_must_accept_get_request(self):
362- connection = httplib.HTTPConnection(self.netloc)
363+ connection = http.client.HTTPConnection(self.netloc)
364 self.addCleanup(connection.close)
365
366 self.do_get_request(connection)
367 self.assertEqual(connection.getresponse().status, 401)
368
369 def test_fake_sso_and_u1_server_must_accept_post_request(self):
370- connection = httplib.HTTPConnection(self.netloc)
371+ connection = http.client.HTTPConnection(self.netloc)
372 self.addCleanup(connection.close)
373
374 self.do_post_request(connection)
375
376=== modified file 'online-accounts-provider/tests/autopilot/ubuntuone_credentials/test_new_account.py'
377--- online-accounts-provider/tests/autopilot/ubuntuone_credentials/test_new_account.py 2014-01-24 15:43:27 +0000
378+++ online-accounts-provider/tests/autopilot/ubuntuone_credentials/test_new_account.py 2014-06-29 09:58:30 +0000
379@@ -16,23 +16,22 @@
380
381 import os
382
383+import ubuntuuitoolkit
384 from autopilot.matchers import Eventually
385 from testtools.matchers import Equals, Not
386-from ubuntuuitoolkit import emulators as toolkit_emulators
387-
388-from ubuntuone_credentials import (
389- emulators,
390- TestCaseWithQMLWrapper
391-)
392-
393-
394-class NewUbuntuOneOnlineAccountTestCase(TestCaseWithQMLWrapper):
395+
396+import ubuntuone_credentials
397+from ubuntuone_credentials import base
398+
399+
400+class NewUbuntuOneOnlineAccountTestCase(base.TestCaseWithQMLWrapper):
401
402 test_qml_wrapper_file_name = 'TestWrapperNew.qml'
403
404 def setUp(self):
405 super(NewUbuntuOneOnlineAccountTestCase, self).setUp()
406- self.new_account = self.main_view.select_single(emulators.NewAccount)
407+ self.new_account = self.main_view.select_single(
408+ ubuntuone_credentials.NewAccount)
409
410 def test_loading_overlay_starts_invisible(self):
411 overlay = self.main_view.select_single(objectName='loadingOverlay')
412@@ -55,7 +54,7 @@
413
414 def test_switch_to_new_user(self):
415 new_user_switch = self.main_view.select_single(
416- toolkit_emulators.CheckBox, objectName='newUserToggleSwitch')
417+ ubuntuuitoolkit.CheckBox, objectName='newUserToggleSwitch')
418 new_user_switch.check()
419
420 password_text_field = self.main_view.select_single(
421@@ -72,7 +71,7 @@
422 Eventually(Equals(False)))
423
424
425-class SimpleLogInTestCase(TestCaseWithQMLWrapper):
426+class SimpleLogInTestCase(base.TestCaseWithQMLWrapper):
427
428 test_qml_wrapper_file_name = 'TestWrapperNew.qml'
429
430@@ -93,7 +92,8 @@
431 """Test that success pops the NewAccount main page, and
432 failure shows the error label.
433 """
434- new_account = self.main_view.select_single(emulators.NewAccount)
435+ new_account = self.main_view.select_single(
436+ ubuntuone_credentials.NewAccount)
437 new_account.log_in(email=self.email, password=self.password)
438 dummyPage = self.main_view.select_single(objectName="dummyPage")
439 self.assertThat(dummyPage.visible, Eventually(Equals(self.success)))
440@@ -101,7 +101,7 @@
441 Eventually(Equals(not self.success)))
442
443
444-class TwoFactorLogInTestCase(TestCaseWithQMLWrapper):
445+class TwoFactorLogInTestCase(base.TestCaseWithQMLWrapper):
446
447 test_qml_wrapper_file_name = 'TestWrapperNew.qml'
448
449@@ -135,11 +135,12 @@
450 # password field, which is always at the location that the
451 # hidden two-factor field starts out at.
452 tfn = 'twoFactorTextField'
453- two_factor_field = self.main_view.select_single(emulators.TextField,
454- objectName=tfn)
455+ two_factor_field = self.main_view.select_single(
456+ ubuntuuitoolkit.TextField, objectName=tfn)
457 saved_rect = two_factor_field.globalRect
458
459- new_account = self.main_view.select_single(emulators.NewAccount)
460+ new_account = self.main_view.select_single(
461+ ubuntuone_credentials.NewAccount)
462 new_account.log_in(email=self.email, password=self.password)
463
464 # Here we wait for both visible and focus, to ensure that the
465@@ -166,7 +167,7 @@
466 success=True)
467
468
469-class RegisterNewU1AccountTestCase(TestCaseWithQMLWrapper):
470+class RegisterNewU1AccountTestCase(base.TestCaseWithQMLWrapper):
471
472 test_qml_wrapper_file_name = 'TestWrapperNew.qml'
473
474@@ -186,7 +187,8 @@
475 def test_register_new_account(self):
476 "Test that registering a new account pops the main page."
477
478- new_account = self.main_view.select_single(emulators.NewAccount)
479+ new_account = self.main_view.select_single(
480+ ubuntuone_credentials.NewAccount)
481 new_account.register_new_account(self.email, self.name, self.password,
482 self.password_confirmation,
483 self.agree_to_terms)

Subscribers

People subscribed via source and target branches

to all changes: