Merge lp:~canonical-platform-qa/gallery-app/fix1381259-launch_fixture into lp:~canonical-platform-qa/gallery-app/clean_autopilot_setup

Proposed by Leo Arias
Status: Needs review
Proposed branch: lp:~canonical-platform-qa/gallery-app/fix1381259-launch_fixture
Merge into: lp:~canonical-platform-qa/gallery-app/clean_autopilot_setup
Prerequisite: lp:~canonical-platform-qa/gallery-app/fix1381273-no_tmp
Diff against target: 484 lines (+230/-87)
10 files modified
debian/control (+4/-2)
tests/autopilot/gallery_app/fixture_setup.py (+203/-0)
tests/autopilot/gallery_app/tests/__init__.py (+22/-76)
tests/autopilot/gallery_app/tests/test_album_editor.py (+0/-1)
tests/autopilot/gallery_app/tests/test_album_view.py (+0/-1)
tests/autopilot/gallery_app/tests/test_albums_view.py (+0/-2)
tests/autopilot/gallery_app/tests/test_events_view.py (+0/-2)
tests/autopilot/gallery_app/tests/test_photo_viewer.py (+0/-1)
tests/autopilot/gallery_app/tests/test_photos_view.py (+0/-1)
tests/autopilot/gallery_app/tests/test_picker_mode.py (+1/-1)
To merge this branch: bzr merge lp:~canonical-platform-qa/gallery-app/fix1381259-launch_fixture
Reviewer Review Type Date Requested Status
Canonical Platform QA Team Pending
Review via email: mp+238382@code.launchpad.net

Commit message

Use a fixture to launch the app on autopilot tests.

To post a comment you must log in.
1104. By Leo Arias

Link to the bug.

1105. By Leo Arias

Reverted the po changes.

1106. By Leo Arias

Pass arguments to the app.

1107. By Leo Arias

Fixed the db backup.

1108. By Leo Arias

Fixed typo.

1109. By Leo Arias

Fixed the fixture.

1110. By Leo Arias

Always configure the db.

1111. By Leo Arias

Fixed the path.

1112. By Leo Arias

Do not hide the folders.

1113. By Leo Arias

Copy instead of move.

1114. By Leo Arias

Fixed the copy.

1115. By Leo Arias

Do not copy database and thumbs to pictures.

Unmerged revisions

1115. By Leo Arias

Do not copy database and thumbs to pictures.

1114. By Leo Arias

Fixed the copy.

1113. By Leo Arias

Copy instead of move.

1112. By Leo Arias

Do not hide the folders.

1111. By Leo Arias

Fixed the path.

1110. By Leo Arias

Always configure the db.

1109. By Leo Arias

Fixed the fixture.

1108. By Leo Arias

Fixed typo.

1107. By Leo Arias

Fixed the db backup.

1106. By Leo Arias

Pass arguments to the app.

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-07-26 03:12:53 +0000
3+++ debian/control 2014-10-22 17:53:30 +0000
4@@ -49,10 +49,12 @@
5 gallery-app (>= ${source:Version}),
6 libautopilot-qt (>= 1.4),
7 libqt5test5,
8+ python3-autopilot,
9+ python3-enum34,
10+ python3-fixtures,
11+ python3-pkg-resources,
12 ubuntu-ui-toolkit-autopilot,
13 unity8-autopilot,
14- python3-pkg-resources,
15- python3-autopilot,
16 Description: Autopilot tests for the photo gallery for Ubuntu
17 gallery-app is a photo gallery for the Ubuntu platform. This package contains
18 autopilot tests for it.
19
20=== renamed directory 'tests/autopilot/gallery_app/data/default/.database' => 'tests/autopilot/gallery_app/data/database'
21=== renamed directory 'tests/autopilot/gallery_app/data/default/.thumbnails' => 'tests/autopilot/gallery_app/data/thumbnails'
22=== added file 'tests/autopilot/gallery_app/fixture_setup.py'
23--- tests/autopilot/gallery_app/fixture_setup.py 1970-01-01 00:00:00 +0000
24+++ tests/autopilot/gallery_app/fixture_setup.py 2014-10-22 17:53:30 +0000
25@@ -0,0 +1,203 @@
26+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
27+#
28+# Copyright (C) 2014 Canonical Ltd.
29+#
30+# This file is part of gallery-app.
31+#
32+# gallery-app is free software: you can redistribute it and/or modify it under
33+# the terms of the GNU General Public License as published by the Free Software
34+# Foundation; version 3.
35+#
36+# gallery-app is distributed in the hope that it will be useful, but WITHOUT
37+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
38+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
39+# details.
40+#
41+# You should have received a copy of the GNU General Public License along with
42+# this program. If not, see <http://www.gnu.org/licenses/>.
43+
44+import enum
45+import logging
46+import os
47+import shutil
48+
49+import fixtures
50+import ubuntuuitoolkit
51+from autopilot import application
52+
53+
54+logger = logging.getLogger(__name__)
55+
56+
57+_BASE_CLASS = ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase
58+
59+
60+class Launcher(enum.Enum):
61+ local_binary = 1
62+ installed_binary = 2
63+ installed_click = 3
64+
65+
66+class LaunchGalleryApp(fixtures.Fixture):
67+
68+ """Fixture to launch the Gallery App."""
69+
70+ def __init__(self, type_, binary_path=None, arguments=None):
71+ """Initialize the fixture.
72+
73+ :param type_: The type of the launcher to use.
74+ :type type_: One of the values of the Launcher enum.
75+ :param string binary_path: The path to use with the
76+ Launcher.installed_binary type. Not used for the other types.
77+ :param arguments: The arguments to pass to the gallery.
78+ :type arguments: A list of strings.
79+
80+ """
81+ super().__init__()
82+ arguments = [] if arguments is None else arguments
83+ if type_ is Launcher.local_binary:
84+ self.launcher = _LaunchLocalBinaryGalleryApp(
85+ binary_path, arguments)
86+ elif type_ is Launcher.installed_binary:
87+ self.launcher = _LaunchInstalledBinaryGalleryApp(arguments)
88+ elif type_ is Launcher.installed_click:
89+ self.launcher = _LaunchInstalledClickGalleryApp(arguments)
90+ else:
91+ raise TypeError('Unknown launcher type: {}.'.format(type_))
92+
93+ def setUp(self):
94+ super().setUp()
95+ self.useFixture(self.launcher)
96+ self.application_proxy = self.launcher.application_proxy
97+
98+
99+class _LaunchLocalBinaryGalleryApp(fixtures.Fixture):
100+
101+ """Fixture to launch the Gallery App from the local binary."""
102+
103+ def __init__(self, binary_path, arguments):
104+ super().__init__()
105+ self.binary_path = binary_path
106+ self.arguments = arguments
107+
108+ def setUp(self):
109+ """Launch the application when the fixture is used."""
110+ super().setUp()
111+ self._copy_binary_to_right_location()
112+ self.application_proxy = self._launch_application()
113+
114+ def _copy_binary_to_right_location(self):
115+ # XXX workaround for bug http://pad.lv/1381312
116+ workaround_binary_directory = os.path.abspath(os.path.join('..', '..'))
117+ workaround_binary_path = os.path.join(
118+ workaround_binary_directory, os.path.basename(self.binary_path))
119+ shutil.copy(self.binary_path, workaround_binary_directory)
120+ self.addCleanup(os.remove, workaround_binary_path)
121+ self.binary_path = workaround_binary_path
122+
123+ def _launch_application(self):
124+ logger.info('Launching gallery-app using the binary at {}.'.format(
125+ self.binary_path))
126+ application_launcher = self.useFixture(
127+ application.NormalApplicationLauncher(emulator_base=_BASE_CLASS))
128+ application_proxy = application_launcher.launch(
129+ self.binary_path,
130+ *self.arguments,
131+ app_type='qt',
132+ launch_dir=os.path.dirname(self.binary_path)
133+ )
134+ return application_proxy
135+
136+
137+class _LaunchInstalledBinaryGalleryApp(fixtures.Fixture):
138+
139+ """Fixture to launch the Gallery App from the installed binary."""
140+
141+ def __init__(self, arguments):
142+ super().__init__()
143+ self.arguments = arguments
144+
145+ def setUp(self):
146+ super().setUp()
147+ """Launch the application when the fixture is used."""
148+ self.application_proxy = self._launch_application()
149+
150+ def _launch_application(self):
151+ logger.info('Launching gallery-app using the installed binary.')
152+ application_launcher = self.useFixture(
153+ application.UpstartApplicationLauncher(emulator_base=_BASE_CLASS))
154+ application_proxy = application_launcher.launch(
155+ 'gallery-app', self.arguments)
156+ return application_proxy
157+
158+
159+class _LaunchInstalledClickGalleryApp(fixtures.Fixture):
160+
161+ """Fixture to launch the Gallery App from the installed click package."""
162+
163+ def __init__(self, arguments):
164+ super().__init__()
165+ self.arguments = arguments
166+
167+ def setUp(self):
168+ super().setUp()
169+ self.application_proxy = self._launch_application()
170+
171+ def _launch_application(self):
172+ logger.info('Launching gallery-app using the installed click package.')
173+ application_launcher = self.useFixture(
174+ application.ClickApplicationLauncher(emulator_base=_BASE_CLASS))
175+ if not arguments:
176+ application_proxy = application_launcher.launch(
177+ 'com.ubuntu.gallery')
178+ else:
179+ application_proxy = self._launch_application_with_arguments(
180+ application_launcher)
181+
182+ return application_proxy
183+
184+ def _launch_application_with_arguments(self, application_laucher):
185+ # XXX We need a better way to start click packages with arguments.
186+ # More discussion is required. --elopio - 2014-10-21
187+ desktop_file_path = self.write_sandbox_desktop_file()
188+ desktop_file_name = os.path.basename(desktop_file_path)
189+ application_name, _ = os.path.splitext(desktop_file_name)
190+ return application_launcher.launch(application_name)
191+
192+ def write_sandbox_desktop_file(self):
193+ desktop_file_dir = self.get_local_desktop_file_directory()
194+ desktop_file = tempfile.NamedTemporaryFile(
195+ dir=desktop_file_dir, suffix='.desktop', mode='w+t', delete=False)
196+ desktop_file.write('[Desktop Entry]\n')
197+ version, installed_path = self.get_installed_version_and_directory()
198+ gallery_exec = './gallery-app ' + ' '.join(arguments)
199+ desktop_file_dict = {
200+ 'Type': 'Application',
201+ 'Name': 'gallery',
202+ 'Exec': gallery_exec,
203+ 'Icon': 'Not important',
204+ 'Path': installed_path
205+ }
206+ for key, value in desktop_file_dict.items():
207+ desktop_file.write('{key}={value}\n'.format(key=key, value=value))
208+ desktop_file.close()
209+ return desktop_file.name
210+
211+ def get_local_desktop_file_directory(self):
212+ return os.path.join(
213+ os.environ.get('HOME'), '.local', 'share', 'applications')
214+
215+ def get_named_temporary_file(
216+ self, dir=None, mode='w+t', delete=False, suffix=''):
217+ # See https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1329141
218+ return
219+
220+ def get_installed_version_and_directory(self):
221+ db = Click.DB()
222+ db.read()
223+ package_name = 'com.ubuntu.gallery'
224+ registry = Click.User.for_user(db, name=os.environ.get('USER'))
225+ version = registry.get_version(package_name)
226+ directory = registry.get_path(package_name)
227+ return version, directory
228+
229
230=== modified file 'tests/autopilot/gallery_app/tests/__init__.py'
231--- tests/autopilot/gallery_app/tests/__init__.py 2014-10-15 04:39:20 +0000
232+++ tests/autopilot/gallery_app/tests/__init__.py 2014-10-22 17:53:30 +0000
233@@ -29,8 +29,9 @@
234 from autopilot.testcase import AutopilotTestCase
235 from autopilot.introspection import get_proxy_object_for_existing_process
236 from pkg_resources import resource_filename
237-
238 from ubuntuuitoolkit import emulators as toolkit_emulators
239+
240+from gallery_app import fixture_setup
241 from gallery_app.emulators import main_screen
242 from gallery_app.emulators.gallery_utils import GalleryUtils
243
244@@ -39,27 +40,21 @@
245 logger = logging.getLogger(__name__)
246
247
248-class EnvironmentTypes:
249- installed = "installed"
250- local = "local"
251- click = "click"
252-
253-
254 class GalleryTestCase(AutopilotTestCase):
255
256 """A common test case class that provides several useful methods for
257 gallery tests."""
258
259+ arguments = []
260+
261 sample_file_source = "/sample01.jpg"
262 tap_press_time = 1
263- local_location = "../../src/gallery-app"
264+ local_location = os.path.abspath('../../src/gallery-app')
265
266 _db = '~/.local/share/com.ubuntu.gallery/' \
267 'database/gallery.sqlite'
268 _thumbs = '~/.cache/com.ubuntu.gallery/thumbnails'
269
270- ARGS = []
271-
272 @property
273 def gallery_utils(self):
274 return GalleryUtils(self.app)
275@@ -73,17 +68,12 @@
276 gallery-app.
277
278 """
279- # Lets assume we are installed system wide if this file is somewhere
280- # in /usr
281- if os.path.realpath(__file__).startswith("/usr/"):
282- return EnvironmentTypes.installed
283- if model() == 'Desktop':
284- return EnvironmentTypes.installed
285+ if os.path.exists(self.local_location):
286+ return fixture_setup.Launcher.local_binary
287+ elif model() == 'Desktop':
288+ return fixture_setup.Launcher.installed_binary
289 else:
290- if os.path.exists(self.local_location):
291- return EnvironmentTypes.local
292- else:
293- return EnvironmentTypes.click
294+ return fixture_setup.Launcher.installed_click
295
296 def _get_sample_destination_dir(self):
297 pic_dir = os.path.expanduser("~/Pictures")
298@@ -105,9 +95,9 @@
299 self.addCleanup(shutil.move, db_bak, db)
300 if not os.path.exists(os.path.dirname(db)):
301 os.makedirs(os.path.dirname(db))
302- mock_db = os.path.join(self.sample_destination_dir, '.database',
303- 'gallery_confined.sqlite')
304- shutil.move(mock_db, db)
305+ mock_db = os.path.join(
306+ self.sample_dir, 'database', 'gallery_confined.sqlite')
307+ shutil.copy(mock_db, db)
308
309 def configure_thumbnails(self):
310 thumbs = os.path.expanduser(self._thumbs)
311@@ -118,13 +108,13 @@
312 self.addCleanup(shutil.move, thumbs_bak, thumbs)
313 if not os.path.exists(os.path.dirname(thumbs)):
314 os.makedirs(os.path.dirname(thumbs))
315- mock_thumbs = os.path.join(self.sample_destination_dir, '.thumbnails')
316- shutil.move(mock_thumbs, thumbs)
317+ mock_thumbs = os.path.join(self.sample_dir, 'thumbnails')
318+ shutil.copytree(mock_thumbs, thumbs)
319
320 def configure_sample_files(self, env_type):
321 self.sample_dir = resource_filename('gallery_app', 'data')
322 self.sample_destination_dir = self._get_sample_destination_dir()
323- if (os.path.exists(self.sample_destination_dir)):
324+ if os.path.exists(self.sample_destination_dir):
325 shutil.rmtree(self.sample_destination_dir)
326 self.assertFalse(os.path.exists(self.sample_destination_dir))
327
328@@ -142,9 +132,8 @@
329 self.sample_file_source = \
330 default_data_dir + self.sample_file_source
331
332- if env_type == EnvironmentTypes.click:
333- self.configure_db()
334- self.configure_thumbnails()
335+ self.configure_db()
336+ self.configure_thumbnails()
337
338 def do_reset_config(self):
339 config = os.path.expanduser(
340@@ -174,53 +163,10 @@
341 sleep(2)
342
343 def launch_gallery_app(self, env_type):
344- if env_type == EnvironmentTypes.installed:
345- self.launch_test_installed()
346- elif env_type == EnvironmentTypes.local:
347- self.launch_test_local()
348- elif env_type == EnvironmentTypes.click:
349- self.launch_test_click()
350- else:
351- raise ValueError("Unknown environment type: %s", env_type)
352-
353- def launch_test_local(self):
354- logger.debug("Launching local gallery-app binary.")
355- self.app = self.launch_test_application(
356- self.local_location,
357- *self.ARGS,
358- emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
359-
360- def launch_test_installed(self):
361- if model() == 'Desktop':
362- logger.debug(
363- "Launching installed gallery-app binary for desktop."
364- )
365- self.app = self.launch_test_application(
366- "gallery-app",
367- *self.ARGS,
368- emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
369- else:
370- logger.debug(
371- "Launching installed gallery-app binary for device."
372- )
373- self.ARGS.append("--desktop_file_hint="
374- "/usr/share/applications/gallery-app.desktop")
375- self.app = self.launch_test_application(
376- "gallery-app",
377- *self.ARGS,
378- app_type='qt',
379- emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
380-
381- def launch_test_click(self):
382- '''
383- Since this test runs under confinement, the only location photos
384- are searchable in is ~/Pictures.
385- '''
386- logger.debug("Launching gallery-app via click package.")
387- self.app = self.launch_click_package(
388- package_id="com.ubuntu.gallery",
389- app_uris=' '.join(self.ARGS),
390- emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
391+ launch_fixture = fixture_setup.LaunchGalleryApp(
392+ env_type, self.local_location, self.arguments)
393+ self.useFixture(launch_fixture)
394+ self.app = launch_fixture.application_proxy
395
396 def ui_update(self):
397 """ Gives the program the time to update the UI"""
398
399=== modified file 'tests/autopilot/gallery_app/tests/test_album_editor.py'
400--- tests/autopilot/gallery_app/tests/test_album_editor.py 2014-09-01 18:24:23 +0000
401+++ tests/autopilot/gallery_app/tests/test_album_editor.py 2014-10-22 17:53:30 +0000
402@@ -30,7 +30,6 @@
403 return MediaSelector(self.app)
404
405 def setUp(self):
406- self.ARGS = []
407 super(TestAlbumEditor, self).setUp()
408 self.switch_to_albums_tab()
409 self.edit_first_album()
410
411=== modified file 'tests/autopilot/gallery_app/tests/test_album_view.py'
412--- tests/autopilot/gallery_app/tests/test_album_view.py 2014-09-03 21:13:03 +0000
413+++ tests/autopilot/gallery_app/tests/test_album_view.py 2014-10-22 17:53:30 +0000
414@@ -43,7 +43,6 @@
415 return PhotoViewer(self.app)
416
417 def setUp(self):
418- self.ARGS = []
419 super(TestAlbumView, self).setUp()
420 self.switch_to_albums_tab()
421
422
423=== modified file 'tests/autopilot/gallery_app/tests/test_albums_view.py'
424--- tests/autopilot/gallery_app/tests/test_albums_view.py 2014-08-27 02:41:33 +0000
425+++ tests/autopilot/gallery_app/tests/test_albums_view.py 2014-10-22 17:53:30 +0000
426@@ -28,8 +28,6 @@
427 return AlbumsView(self.app)
428
429 def setUp(self):
430- self.ARGS = []
431-
432 self.envDesktopMode = env.get("DESKTOP_MODE")
433
434 if model() == "Desktop":
435
436=== modified file 'tests/autopilot/gallery_app/tests/test_events_view.py'
437--- tests/autopilot/gallery_app/tests/test_events_view.py 2014-09-17 13:37:15 +0000
438+++ tests/autopilot/gallery_app/tests/test_events_view.py 2014-10-22 17:53:30 +0000
439@@ -30,8 +30,6 @@
440 return EventsView(self.app)
441
442 def setUp(self):
443- self.ARGS = []
444-
445 self.envDesktopMode = env.get("DESKTOP_MODE")
446
447 if model() == "Desktop":
448
449=== modified file 'tests/autopilot/gallery_app/tests/test_photo_viewer.py'
450--- tests/autopilot/gallery_app/tests/test_photo_viewer.py 2014-09-03 00:14:45 +0000
451+++ tests/autopilot/gallery_app/tests/test_photo_viewer.py 2014-10-22 17:53:30 +0000
452@@ -37,7 +37,6 @@
453 return EventsView(self.app)
454
455 def setUp(self):
456- self.ARGS = []
457 super(TestPhotoViewerBase, self).setUp()
458 self.main_view.switch_to_tab("eventsTab")
459 self.open_first_photo()
460
461=== modified file 'tests/autopilot/gallery_app/tests/test_photos_view.py'
462--- tests/autopilot/gallery_app/tests/test_photos_view.py 2014-08-26 21:54:25 +0000
463+++ tests/autopilot/gallery_app/tests/test_photos_view.py 2014-10-22 17:53:30 +0000
464@@ -30,7 +30,6 @@
465 return PhotosView(self.app)
466
467 def setUp(self):
468- self.ARGS = []
469 self.envDesktopMode = env.get("DESKTOP_MODE")
470
471 if model() == "Desktop":
472
473=== modified file 'tests/autopilot/gallery_app/tests/test_picker_mode.py'
474--- tests/autopilot/gallery_app/tests/test_picker_mode.py 2014-07-15 09:16:18 +0000
475+++ tests/autopilot/gallery_app/tests/test_picker_mode.py 2014-10-22 17:53:30 +0000
476@@ -23,7 +23,7 @@
477 return self.app.wait_select_single(PickerScreen)
478
479 def setUp(self):
480- self.ARGS = ['--pick-mode']
481+ self.arguments = ['--pick-mode']
482 super(TestPickerMode, self).setUp()
483
484 def select_first_event_media(self):

Subscribers

People subscribed via source and target branches

to all changes: