Merge lp:~canonical-platform-qa/ubuntu-system-tests/global_test_context into lp:ubuntu-system-tests

Proposed by Sergio Cazzolato
Status: Work in progress
Proposed branch: lp:~canonical-platform-qa/ubuntu-system-tests/global_test_context
Merge into: lp:ubuntu-system-tests
Diff against target: 438 lines (+89/-47)
14 files modified
ubuntu_system_tests/helpers/__init__.py (+27/-0)
ubuntu_system_tests/helpers/context.py (+24/-0)
ubuntu_system_tests/helpers/data.py (+1/-8)
ubuntu_system_tests/helpers/media.py (+2/-2)
ubuntu_system_tests/helpers/scopes/__init__.py (+3/-3)
ubuntu_system_tests/helpers/scopes/music.py (+2/-2)
ubuntu_system_tests/helpers/unity8/dash.py (+0/-15)
ubuntu_system_tests/tests/base.py (+18/-4)
ubuntu_system_tests/tests/base_messaging.py (+2/-3)
ubuntu_system_tests/tests/test_app_store.py (+2/-2)
ubuntu_system_tests/tests/test_html5_application.py (+2/-2)
ubuntu_system_tests/tests/test_mtp.py (+2/-2)
ubuntu_system_tests/tests/test_scopes.py (+2/-2)
ubuntu_system_tests/tests/test_uninstall_application.py (+2/-2)
To merge this branch: bzr merge lp:~canonical-platform-qa/ubuntu-system-tests/global_test_context
Reviewer Review Type Date Requested Status
platform-qa-bot continuous-integration Needs Fixing
PS Jenkins bot continuous-integration Approve
prod-platform-qa continuous-integration Pending
Canonical Platform QA Team Pending
Review via email: mp+272298@code.launchpad.net

Commit message

Creating context module used to store a shared dictionary with common objects

The shared context can be used list:
1. Import module: from ubuntu_system_tests.helpers import context
2. Access to any shared object: dash = context.shared.dash
3. Set a shared object = context.shared.dash = self.get_dash_proxy()

The base test class is in charge of cleaning this context on the test setup and add the unity and dash proxies in the unity8 launch method.

To post a comment you must log in.
Revision history for this message
Sergio Cazzolato (sergio-j-cazzolato) wrote :

In the clock app this change will be used to avoid going to the root class to access the main view.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Needs Fixing (continuous-integration)

Unmerged revisions

216. By Sergio Cazzolato

Creating context module used to store a shared disctionary with common objects

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntu_system_tests/helpers/__init__.py'
2--- ubuntu_system_tests/helpers/__init__.py 2014-12-10 01:36:09 +0000
3+++ ubuntu_system_tests/helpers/__init__.py 2015-09-24 17:40:06 +0000
4@@ -0,0 +1,27 @@
5+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
6+
7+#
8+# Ubuntu System Tests
9+# Copyright (C) 2015 Canonical
10+#
11+# This program is free software: you can redistribute it and/or modify
12+# it under the terms of the GNU General Public License as published by
13+# the Free Software Foundation, either version 3 of the License, or
14+# (at your option) any later version.
15+#
16+# This program is distributed in the hope that it will be useful,
17+# but WITHOUT ANY WARRANTY; without even the implied warranty of
18+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+# GNU General Public License for more details.
20+#
21+# You should have received a copy of the GNU General Public License
22+# along with this program. If not, see <http://www.gnu.org/licenses/>.
23+#
24+
25+
26+class AttrDict(dict):
27+ """ Class used to access to the dict keys as parameters """
28+
29+ def __init__(self, *args, **kwargs):
30+ super(AttrDict, self).__init__(*args, **kwargs)
31+ self.__dict__ = self
32
33=== added file 'ubuntu_system_tests/helpers/context.py'
34--- ubuntu_system_tests/helpers/context.py 1970-01-01 00:00:00 +0000
35+++ ubuntu_system_tests/helpers/context.py 2015-09-24 17:40:06 +0000
36@@ -0,0 +1,24 @@
37+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
38+
39+#
40+# Ubuntu System Tests
41+# Copyright (C) 2015 Canonical
42+#
43+# This program is free software: you can redistribute it and/or modify
44+# it under the terms of the GNU General Public License as published by
45+# the Free Software Foundation, either version 3 of the License, or
46+# (at your option) any later version.
47+#
48+# This program is distributed in the hope that it will be useful,
49+# but WITHOUT ANY WARRANTY; without even the implied warranty of
50+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
51+# GNU General Public License for more details.
52+#
53+# You should have received a copy of the GNU General Public License
54+# along with this program. If not, see <http://www.gnu.org/licenses/>.
55+#
56+
57+from ubuntu_system_tests.helpers import AttrDict
58+
59+
60+shared = AttrDict()
61
62=== modified file 'ubuntu_system_tests/helpers/data.py'
63--- ubuntu_system_tests/helpers/data.py 2015-09-04 20:57:11 +0000
64+++ ubuntu_system_tests/helpers/data.py 2015-09-24 17:40:06 +0000
65@@ -21,6 +21,7 @@
66 from json import (load, JSONDecoder)
67 from os import path, walk
68
69+from ubuntu_system_tests.helpers import AttrDict
70 from ubuntu_system_tests.helpers import file_system as fs
71
72
73@@ -38,14 +39,6 @@
74 return d
75
76
77-class AttrDict(dict):
78- """ Class used to access to the dict keys as parameters """
79-
80- def __init__(self, *args, **kwargs):
81- super(AttrDict, self).__init__(*args, **kwargs)
82- self.__dict__ = self
83-
84-
85 _full_dict = AttrDict()
86
87
88
89=== modified file 'ubuntu_system_tests/helpers/media.py'
90--- ubuntu_system_tests/helpers/media.py 2015-07-27 15:31:09 +0000
91+++ ubuntu_system_tests/helpers/media.py 2015-09-24 17:40:06 +0000
92@@ -23,8 +23,8 @@
93 from unity8.process_helpers import start_job, stop_job, is_job_running
94
95 from ubuntu_system_tests.helpers import backup_restore_fixture as brf
96+from ubuntu_system_tests.helpers import context
97 from ubuntu_system_tests.helpers.file_system import get_media_folder_list
98-from ubuntu_system_tests.helpers.unity8.dash import get_dash
99
100 MEDIA_SCANNER = 'mediascanner-2.0'
101
102@@ -34,7 +34,7 @@
103 if is_job_running(MEDIA_SCANNER):
104 stop_job(MEDIA_SCANNER)
105 start_job(MEDIA_SCANNER)
106- dash = get_dash()
107+ dash = context.shared.dash
108 dash.wait_for_dash_loaded()
109 dash.wait_for_processing_to_complete()
110
111
112=== modified file 'ubuntu_system_tests/helpers/scopes/__init__.py'
113--- ubuntu_system_tests/helpers/scopes/__init__.py 2015-09-14 15:52:45 +0000
114+++ ubuntu_system_tests/helpers/scopes/__init__.py 2015-09-24 17:40:06 +0000
115@@ -26,11 +26,11 @@
116 from collections import namedtuple
117
118 from autopilot import exceptions
119+from ubuntu_system_tests.helpers import context
120 from ubuntu_system_tests.helpers import file_system
121 from ubuntu_system_tests.helpers import timedate
122 from ubuntu_system_tests.helpers.autopilot import order_by_y_coord
123 from ubuntu_system_tests.helpers.ubuntuuitoolkit.pageheader import PageHeader
124-from ubuntu_system_tests.helpers.unity8.dash import get_dash
125
126 SCOPES_FILE = os.path.join(file_system.DIR_TEST_DATA_SCOPES, 'scopes.json')
127 KEY_DEFAULT_CONDITION = 'default_condition'
128@@ -224,7 +224,7 @@
129 """
130 self.scroll_to_bottom()
131 self._press_skip_setup_button()
132- get_dash().get_current_page_header().go_back()
133+ context.shared.dash.get_current_page_header().go_back()
134
135 def scroll_to_bottom(self):
136 """ Scroll to the bottom of the scope """
137@@ -267,7 +267,7 @@
138
139 def wait_for_processing_to_complete(self):
140 """Wait for the processing indicator to disappear."""
141- get_dash().wait_for_processing_to_complete()
142+ context.shared.dash.wait_for_processing_to_complete()
143
144
145 class ScopeData(object):
146
147=== modified file 'ubuntu_system_tests/helpers/scopes/music.py'
148--- ubuntu_system_tests/helpers/scopes/music.py 2015-09-16 15:16:00 +0000
149+++ ubuntu_system_tests/helpers/scopes/music.py 2015-09-24 17:40:06 +0000
150@@ -22,9 +22,9 @@
151
152 from autopilot import exceptions
153
154+from ubuntu_system_tests.helpers import context
155 from ubuntu_system_tests.helpers.scopes import Scope
156 from ubuntu_system_tests.helpers.ubuntuuitoolkit import pageheader
157-from ubuntu_system_tests.helpers.unity8.dash import get_dash
158
159 ARTISTS_LABEL = 'Artists'
160 ALBUMS_LABEL = 'Albums'
161@@ -202,7 +202,7 @@
162
163
164 def get_page_header():
165- return get_dash().get_current_page_header(header_class=PageHeader)
166+ return context.shared.dash.get_current_page_header(header_class=PageHeader)
167
168
169 def get_artists(songs):
170
171=== modified file 'ubuntu_system_tests/helpers/unity8/dash.py'
172--- ubuntu_system_tests/helpers/unity8/dash.py 2015-09-16 13:27:44 +0000
173+++ ubuntu_system_tests/helpers/unity8/dash.py 2015-09-24 17:40:06 +0000
174@@ -18,28 +18,13 @@
175 # along with this program. If not, see <http://www.gnu.org/licenses/>.
176 #
177
178-import ubuntuuitoolkit
179-
180 from retrying import retry
181
182-from autopilot import introspection
183-
184 from ubuntu_system_tests.helpers.autopilot import order_by_x_coord
185 from ubuntu_system_tests.helpers.ubuntuuitoolkit.pageheader import PageHeader
186-from unity8 import process_helpers
187 from unity8.shell.emulators import dash as unity8_dash
188
189
190-def get_dash():
191- """Return the Unity8 Dash autopilot custom proxy object."""
192- pid = process_helpers.get_job_pid('unity8-dash')
193- dash_proxy = introspection.get_proxy_object_for_existing_process(
194- pid=pid,
195- emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase,
196- )
197- return dash_proxy.select_single(Dash)
198-
199-
200 class Dash(unity8_dash.Dash):
201
202 def wait_for_processing_to_complete(self):
203
204=== modified file 'ubuntu_system_tests/tests/base.py'
205--- ubuntu_system_tests/tests/base.py 2015-09-18 08:09:44 +0000
206+++ ubuntu_system_tests/tests/base.py 2015-09-24 17:40:06 +0000
207@@ -43,13 +43,13 @@
208 from unity8 import process_helpers
209 from unity8.sensors import FakePlatformSensors
210
211+from ubuntu_system_tests.helpers import context
212 from ubuntu_system_tests.helpers import click
213 from ubuntu_system_tests.helpers import images
214 from ubuntu_system_tests.helpers import mir
215 from ubuntu_system_tests.helpers import unity8
216 from ubuntu_system_tests.helpers import autopilot as autopilot_helpers
217 from ubuntu_system_tests.helpers.processes import ensure_application_closed
218-from ubuntu_system_tests.helpers.unity8.dash import get_dash
219 from ubuntu_system_tests.helpers.unity8.shell import Unity8 # NOQA
220
221 # Any test name ending with this will leave device locked
222@@ -95,6 +95,9 @@
223 super().setUp()
224 self._reset_autopilot_registry()
225
226+ # The shared context is reset for each test
227+ context.shared.clear()
228+
229 @autopilot_logging.log_action(logger.info)
230 def launch_unity(self, fake_sensors=False):
231 """Launch Unity8 with testability enabled.
232@@ -124,6 +127,11 @@
233 self._reset_keyboard()
234 # Workaround for bug lp:1474444
235 self.useFixture(OSKAlwaysEnabled())
236+
237+ # Save the unity8 and dash in the shared context
238+ context.shared.unity = unity
239+ context.shared.dash = self.get_dash_proxy()
240+
241 return unity
242
243 def _start_unity_with_testability(self):
244@@ -185,7 +193,7 @@
245 unity_proxy = self.launch_unity(fake_sensors=fake_sensors)
246 if self.device_unlock_required():
247 unity_proxy.unlock()
248- get_dash().wait_for_dash_loaded()
249+ context.shared.dash.wait_for_dash_loaded()
250 return unity_proxy
251
252 def device_unlock_required(self):
253@@ -199,7 +207,7 @@
254
255 def get_scree_size(self):
256 """ Calculate the screen size base on the unity8 size """
257- unity = self.get_job_proxy_object('unity8')
258+ unity = context.shared.unity
259 return unity.get_width(), unity.get_height()
260
261 def get_screenshot_image(self):
262@@ -241,7 +249,7 @@
263 :return: Proxy object for application.
264
265 """
266- apps_scope = get_dash().open_apps_scope()
267+ apps_scope = context.shared.dash.open_apps_scope()
268 apps_scope.click_scope_item(category, app_name)
269
270 def _get_proxy_object_for_existing_app(self, process_name,
271@@ -435,3 +443,9 @@
272 from ubuntu_system_tests.helpers.webbrowser import _cpo # NOQA
273 proxy = self._get_proxy_object_for_existing_app('webbrowser-app')
274 return proxy.main_window
275+
276+ def get_dash_proxy(self):
277+ """Return the Unity8 Dash autopilot custom proxy object."""
278+ from ubuntu_system_tests.helpers.unity8.dash import Dash
279+ proxy = self.get_job_proxy_object('unity8-dash')
280+ return proxy.select_single(Dash)
281
282=== modified file 'ubuntu_system_tests/tests/base_messaging.py'
283--- ubuntu_system_tests/tests/base_messaging.py 2015-09-11 11:09:06 +0000
284+++ ubuntu_system_tests/tests/base_messaging.py 2015-09-24 17:40:06 +0000
285@@ -22,12 +22,12 @@
286 from datetime import datetime
287
288 from ubuntu_system_tests.helpers.addressbook import Contact
289+from ubuntu_system_tests.helpers import context
290 from ubuntu_system_tests.helpers import file_system as fs
291 from ubuntu_system_tests.helpers.messaging import fixture_setup
292 from ubuntu_system_tests.helpers import messaging as messaging_helpers
293 from ubuntu_system_tests.helpers import system_settings
294 from ubuntu_system_tests.helpers.system_settings import SETTINGS_PROCESS
295-from ubuntu_system_tests.helpers.unity8 import dash
296 from ubuntu_system_tests.tests import base
297 from ubuntu_system_tests.tests.base_telephony import BaseTelephonyTestCase
298
299@@ -56,7 +56,6 @@
300 number=self.get_telephony_service_number2(),
301 expected_reply=REPLY_2)
302 self.create_temporary_contact(self.contact_1)
303- self.dash = dash.get_dash()
304
305 def launch_messaging(self):
306 """Launch the messaging app from apps scope."""
307@@ -394,5 +393,5 @@
308 selector = cellular.get_default_sim_for_messages_selector(value)
309 settings.scroll_to_and_click(selector)
310 selector.selected.wait_for(True)
311- dash.get_dash().swipe_screen_from_left()
312+ context.shared.dash.swipe_screen_from_left()
313 self.addCleanup(self.ensure_application_closed, SETTINGS_PROCESS)
314
315=== modified file 'ubuntu_system_tests/tests/test_app_store.py'
316--- ubuntu_system_tests/tests/test_app_store.py 2015-09-02 11:19:54 +0000
317+++ ubuntu_system_tests/tests/test_app_store.py 2015-09-24 17:40:06 +0000
318@@ -48,9 +48,9 @@
319 from testtools.matchers import Equals
320 from ubuntu_system_tests.helpers import (
321 click,
322+ context,
323 ubuntuone_credentials
324 )
325-from ubuntu_system_tests.helpers.unity8 import dash
326 from ubuntu_system_tests.tests import base
327
328 # XXX Imported to load the custom proxy objects. We need to import the dash
329@@ -91,7 +91,7 @@
330 """Create U1 account and install application from store (OSMTouch)"""
331 unity_proxy = self.restart_unity()
332
333- dash_proxy = dash.get_dash()
334+ dash_proxy = context.shared.dash
335 apps_scope = dash_proxy.open_apps_scope()
336
337 store_scope = apps_scope.go_to_store()
338
339=== modified file 'ubuntu_system_tests/tests/test_html5_application.py'
340--- ubuntu_system_tests/tests/test_html5_application.py 2015-07-01 05:13:40 +0000
341+++ ubuntu_system_tests/tests/test_html5_application.py 2015-09-24 17:40:06 +0000
342@@ -31,7 +31,7 @@
343
344 from testtools.matchers import GreaterThan
345
346-from ubuntu_system_tests.helpers.unity8.dash import get_dash
347+from ubuntu_system_tests.helpers import context
348 from ubuntu_system_tests.tests import base
349
350 DEFAULT_WEBVIEW_INSPECTOR_IP = '127.0.0.1'
351@@ -67,7 +67,7 @@
352 UBUNTU_WEBVIEW_DEVTOOLS_PORT=str(DEFAULT_WEBVIEW_INSPECTOR_PORT)))
353
354 def launch_webapp(self, app_name):
355- apps_scope = get_dash().open_apps_scope()
356+ apps_scope = context.shared.dash.open_apps_scope()
357 apps_scope.click_scope_item('local', app_name)
358
359 self.addCleanup(ensure_webapp_closed)
360
361=== modified file 'ubuntu_system_tests/tests/test_mtp.py'
362--- ubuntu_system_tests/tests/test_mtp.py 2015-09-04 20:57:11 +0000
363+++ ubuntu_system_tests/tests/test_mtp.py 2015-09-24 17:40:06 +0000
364@@ -22,13 +22,13 @@
365 import os
366
367 from testtools import skipUnless
368+from ubuntu_system_tests.helpers import context
369 from ubuntu_system_tests.helpers.data import load_test_metadata
370 from ubuntu_system_tests.helpers import file_system as fs
371 from ubuntu_system_tests.helpers.mtp import MTPObjFactory, MTPHelper
372 from ubuntu_system_tests.helpers import ssh
373 from ubuntu_system_tests.helpers import media
374 from ubuntu_system_tests.helpers.scopes import music
375-from ubuntu_system_tests.helpers.unity8.dash import get_dash
376
377 from ubuntu_system_tests.tests import base
378
379@@ -63,7 +63,7 @@
380 :param album: The name ob the desired album
381 :return: True is there is an artist with the desired name
382 """
383- music_scope = music.MusicScope(get_dash().open_music_scope())
384+ music_scope = music.MusicScope(context.shared.dash.open_music_scope())
385 self.assertTrue(music_scope.is_artist(artist))
386
387 def verify_same_files(self, src_files, dst_files):
388
389=== modified file 'ubuntu_system_tests/tests/test_scopes.py'
390--- ubuntu_system_tests/tests/test_scopes.py 2015-09-16 13:27:44 +0000
391+++ ubuntu_system_tests/tests/test_scopes.py 2015-09-24 17:40:06 +0000
392@@ -24,6 +24,7 @@
393 from testtools import skipUnless
394 from ubuntu_system_tests.tests import base
395 from ubuntu_system_tests.helpers import autopilot
396+from ubuntu_system_tests.helpers import context
397 from ubuntu_system_tests.helpers.data import load_test_metadata
398 from ubuntu_system_tests.helpers import media
399 from ubuntu_system_tests.helpers import music
400@@ -37,7 +38,6 @@
401 from ubuntu_system_tests.helpers.scopes.music import MusicScope
402 from ubuntu_system_tests.helpers.scopes.video import VideoScope
403 from ubuntu_system_tests.helpers.scopes import timedate
404-from ubuntu_system_tests.helpers.unity8.dash import get_dash
405 from ubuntu_system_tests.helpers import web
406 from ubuntu_system_tests.helpers import webbrowser
407
408@@ -91,7 +91,7 @@
409 def setUp(self):
410 super().setUp()
411 self.unity_proxy = self.restart_unity()
412- self.dash = get_dash()
413+ self.dash = context.shared.dash
414 logger.info('Running test using channel: {c} and device: {d}'.format(
415 c=channel, d=device))
416 self.assertTrue(
417
418=== modified file 'ubuntu_system_tests/tests/test_uninstall_application.py'
419--- ubuntu_system_tests/tests/test_uninstall_application.py 2015-06-23 04:06:08 +0000
420+++ ubuntu_system_tests/tests/test_uninstall_application.py 2015-09-24 17:40:06 +0000
421@@ -26,7 +26,7 @@
422 import ubuntu_system_tests
423 from ubuntu_system_tests.tests import base
424 from ubuntu_system_tests.helpers import click
425-from ubuntu_system_tests.helpers.unity8.dash import get_dash
426+from ubuntu_system_tests.helpers import context
427
428 # Imported to load the custom proxy objects.
429 import ubuntu_system_tests.helpers.unityclickscope # NOQA
430@@ -39,7 +39,7 @@
431 ubuntu_system_tests.__name__, 'data/simpleclick.qa_0.1_all.click')
432 self.useFixture(click.ClickPackageInstalled(click_file_path))
433 self.restart_unity()
434- apps_scope = get_dash().open_apps_scope()
435+ apps_scope = context.shared.dash.open_apps_scope()
436 self.assertIn('simpleclick', apps_scope.get_applications('local'))
437
438 preview = apps_scope.open_preview(

Subscribers

People subscribed via source and target branches

to all changes: