Merge lp:~canonical-platform-qa/gallery-app/fix1376423-no_backup into lp:gallery-app

Proposed by Leo Arias
Status: Superseded
Proposed branch: lp:~canonical-platform-qa/gallery-app/fix1376423-no_backup
Merge into: lp:gallery-app
Diff against target: 367 lines (+171/-102)
3 files modified
debian/control (+4/-2)
tests/autopilot/gallery_app/fixture_setup.py (+136/-0)
tests/autopilot/gallery_app/tests/__init__.py (+31/-100)
To merge this branch: bzr merge lp:~canonical-platform-qa/gallery-app/fix1376423-no_backup
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing
Ubuntu Phablet Team Pending
Review via email: mp+238348@code.launchpad.net

This proposal has been superseded by a proposal from 2014-10-15.

Commit message

Do not backup existing files during autopilot tests. We will assume a clean environment from now on.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Leo Arias (elopio) wrote :

In order to remove the backups, we need to stop deleting the real folders.
In order to stop deleting the real folders, we need a better hierarchy of test cases and a fixture to launch the app.
I will start with the fixture.

1103. By Leo Arias

Merged with prerequisite.

1104. By Leo Arias

Fixed the method definition.

1105. By Leo Arias

Keep the database patching for now.

1106. By Leo Arias

Make the pictures dir location and configuration independent.

1107. By Leo Arias

Reverted to use the hardcoded path. The phone doesn't have xdg-user-dir.

1108. By Leo Arias

Raise an exception if the pictures directory is not empty.

1109. By Leo Arias

Clean the pictures directory.

1110. By Leo Arias

Clean the pictures directory.

Unmerged revisions

1110. By Leo Arias

Clean the pictures directory.

1109. By Leo Arias

Clean the pictures directory.

1108. By Leo Arias

Raise an exception if the pictures directory is not empty.

1107. By Leo Arias

Reverted to use the hardcoded path. The phone doesn't have xdg-user-dir.

1106. By Leo Arias

Make the pictures dir location and configuration independent.

1105. By Leo Arias

Keep the database patching for now.

1104. By Leo Arias

Fixed the method definition.

1103. By Leo Arias

Merged with prerequisite.

1102. By Leo Arias

Do not backup existing files during autopilot tests. We will assume a clean environment from now on.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/control'
--- debian/control 2014-07-26 03:12:53 +0000
+++ debian/control 2014-10-15 04:41:38 +0000
@@ -49,10 +49,12 @@
49 gallery-app (>= ${source:Version}),49 gallery-app (>= ${source:Version}),
50 libautopilot-qt (>= 1.4),50 libautopilot-qt (>= 1.4),
51 libqt5test5,51 libqt5test5,
52 python3-autopilot,
53 python3-enum34,
54 python3-fixtures,
55 python3-pkg-resources,
52 ubuntu-ui-toolkit-autopilot,56 ubuntu-ui-toolkit-autopilot,
53 unity8-autopilot,57 unity8-autopilot,
54 python3-pkg-resources,
55 python3-autopilot,
56Description: Autopilot tests for the photo gallery for Ubuntu58Description: Autopilot tests for the photo gallery for Ubuntu
57 gallery-app is a photo gallery for the Ubuntu platform. This package contains59 gallery-app is a photo gallery for the Ubuntu platform. This package contains
58 autopilot tests for it.60 autopilot tests for it.
5961
=== added file 'tests/autopilot/gallery_app/fixture_setup.py'
--- tests/autopilot/gallery_app/fixture_setup.py 1970-01-01 00:00:00 +0000
+++ tests/autopilot/gallery_app/fixture_setup.py 2014-10-15 04:41:38 +0000
@@ -0,0 +1,136 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2#
3# Copyright (C) 2014 Canonical Ltd.
4#
5# This file is part of gallery-app.
6#
7# gallery-app is free software: you can redistribute it and/or modify it under
8# the terms of the GNU General Public License as published by the Free Software
9# Foundation; version 3.
10#
11# gallery-app is distributed in the hope that it will be useful, but WITHOUT
12# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14# details.
15#
16# You should have received a copy of the GNU General Public License along with
17# this program. If not, see <http://www.gnu.org/licenses/>.
18
19import enum
20import logging
21import os
22import shutil
23
24import fixtures
25import ubuntuuitoolkit
26from autopilot import application
27
28
29logger = logging.getLogger(__name__)
30
31
32_BASE_CLASS = ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase
33
34
35class Launcher(enum.Enum):
36 local_binary = 1
37 installed_binary = 2
38 installed_click = 3
39
40
41class LaunchGalleryApp(fixtures.Fixture):
42
43 """Fixture to launch the Gallery App."""
44
45 def __init__(self, type_, binary_path=None):
46 """Initialize the fixture.
47
48 :param type_: The type of the launcher to use.
49 :type type_: One of the values of the Launcher enum.
50 :param str binary_path: The path to use with the
51 Launcher.installed_binary type. Not used for the other types.
52
53 """
54 super().__init__()
55 if type_ is Launcher.local_binary:
56 self.launcher = _LaunchLocalBinaryGalleryApp(binary_path)
57 elif type_ is Launcher.installed_binary:
58 self.launcher = _LaunchInstalledBinaryGalleryApp()
59 elif type_ is Launcher.installed_click:
60 self.launcher = _LaunchInstalledClickGalleryApp()
61 else:
62 raise TypeError('Unknown launcher type: {}.'.format(type_))
63
64 def setUp(self):
65 super().setUp()
66 self.useFixture(self.launcher)
67 self.application_proxy = self.launcher.application_proxy
68
69
70class _LaunchLocalBinaryGalleryApp(fixtures.Fixture):
71
72 """Fixture to launch the Gallery App from the local binary."""
73
74 def __init__(self, binary_path):
75 super().__init__()
76 self.binary_path = binary_path
77
78 def setUp(self):
79 """Launch the application when the fixture is used."""
80 super().setUp()
81 self._copy_binary_to_right_location()
82 self.application_proxy = self._launch_application()
83
84 def _copy_binary_to_right_location(self):
85 # XXX workaround for bug http://pad.lv/1381312
86 workaround_binary_directory = os.path.abspath(os.path.join('..', '..'))
87 workaround_binary_path = os.path.join(
88 workaround_binary_directory, os.path.basename(self.binary_path))
89 shutil.copy(self.binary_path, workaround_binary_directory)
90 self.addCleanup(os.remove, workaround_binary_path)
91 self.binary_path = workaround_binary_path
92
93 def _launch_application(self):
94 logger.info('Launching gallery-app using the binary at {}.'.format(
95 self.binary_path))
96 application_launcher = self.useFixture(
97 application.NormalApplicationLauncher(emulator_base=_BASE_CLASS))
98 application_proxy = application_launcher.launch(
99 self.binary_path,
100 app_type='qt',
101 launch_dir=os.path.dirname(self.binary_path),
102 )
103 return application_proxy
104
105
106class _LaunchInstalledBinaryGalleryApp(fixtures.Fixture):
107
108 """Fixture to launch the Gallery App from the installed binary."""
109
110 def setUp(self):
111 super().setUp()
112 """Launch the application when the fixture is used."""
113 self.application_proxy = self._launch_application()
114
115 def _launch_application(self):
116 logger.info('Launching gallery-app using the installed binary.')
117 application_launcher = self.useFixture(
118 application.UpstartApplicationLauncher(emulator_base=_BASE_CLASS))
119 application_proxy = application_launcher.launch('gallery-app')
120 return application_proxy
121
122
123class _LaunchInstalledClickGalleryApp(fixtures.Fixture):
124
125 """Fixture to launch the Gallery App from the installed click package."""
126
127 def setUp(self):
128 super().setUp()
129 self.application_proxy = self._launch_application()
130
131 def _launch_application(self):
132 logger.info('Launching gallery-app using the installed click package.')
133 application_launcher = self.useFixture(
134 application.ClickApplicationLauncher(emulator_base=_BASE_CLASS))
135 application_proxy = application_launcher.launch('com.ubuntu.gallery')
136 return application_proxy
0137
=== modified file 'tests/autopilot/gallery_app/tests/__init__.py'
--- tests/autopilot/gallery_app/tests/__init__.py 2014-09-19 04:22:12 +0000
+++ tests/autopilot/gallery_app/tests/__init__.py 2014-10-15 04:41:38 +0000
@@ -1,9 +1,20 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2# Copyright 2012 Canonical2#
3#3# Copyright (C) 2012, 2014 Canonical Ltd.
4# This program is free software: you can redistribute it and/or modify it4#
5# under the terms of the GNU General Public License version 3, as published5# This file is part of gallery-app.
6# by the Free Software Foundation.6#
7# gallery-app is free software: you can redistribute it and/or modify it under
8# the terms of the GNU General Public License as published by the Free Software
9# Foundation; version 3.
10#
11# gallery-app is distributed in the hope that it will be useful, but WITHOUT
12# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14# details.
15#
16# You should have received a copy of the GNU General Public License along with
17# this program. If not, see <http://www.gnu.org/licenses/>.
718
8"""gallery autopilot tests."""19"""gallery autopilot tests."""
920
@@ -18,8 +29,9 @@
18from autopilot.testcase import AutopilotTestCase29from autopilot.testcase import AutopilotTestCase
19from autopilot.introspection import get_proxy_object_for_existing_process30from autopilot.introspection import get_proxy_object_for_existing_process
20from pkg_resources import resource_filename31from pkg_resources import resource_filename
21
22from ubuntuuitoolkit import emulators as toolkit_emulators32from ubuntuuitoolkit import emulators as toolkit_emulators
33
34from gallery_app import fixture_setup
23from gallery_app.emulators import main_screen35from gallery_app.emulators import main_screen
24from gallery_app.emulators.gallery_utils import GalleryUtils36from gallery_app.emulators.gallery_utils import GalleryUtils
2537
@@ -28,12 +40,6 @@
28logger = logging.getLogger(__name__)40logger = logging.getLogger(__name__)
2941
3042
31class EnvironmentTypes:
32 installed = "installed"
33 local = "local"
34 click = "click"
35
36
37class GalleryTestCase(AutopilotTestCase):43class GalleryTestCase(AutopilotTestCase):
3844
39 """A common test case class that provides several useful methods for45 """A common test case class that provides several useful methods for
@@ -41,14 +47,12 @@
4147
42 sample_file_source = "/sample01.jpg"48 sample_file_source = "/sample01.jpg"
43 tap_press_time = 149 tap_press_time = 1
44 local_location = "../../src/gallery-app"50 local_location = os.path.abspath('../../src/gallery-app')
4551
46 _db = '~/.local/share/com.ubuntu.gallery/' \52 _db = '~/.local/share/com.ubuntu.gallery/' \
47 'database/gallery.sqlite'53 'database/gallery.sqlite'
48 _thumbs = '~/.cache/com.ubuntu.gallery/thumbnails'54 _thumbs = '~/.cache/com.ubuntu.gallery/thumbnails'
4955
50 _default_sample_destination_dir = "/tmp/gallery-ap_sd"
51
52 ARGS = []56 ARGS = []
5357
54 @property58 @property
@@ -64,39 +68,18 @@
64 gallery-app.68 gallery-app.
6569
66 """70 """
67 # Lets assume we are installed system wide if this file is somewhere71 if os.path.exists(self.local_location):
68 # in /usr72 return fixture_setup.Launcher.local_binary
69 if os.path.realpath(__file__).startswith("/usr/"):73 elif model() == 'Desktop':
70 return EnvironmentTypes.installed74 return fixture_setup.Launcher.installed_binary
71 if model() == 'Desktop':
72 return EnvironmentTypes.installed
73 else:75 else:
74 if os.path.exists(self.local_location):76 return fixture_setup.Launcher.installed_click
75 return EnvironmentTypes.local
76 else:
77 return EnvironmentTypes.click
7877
79 def _get_sample_destination_dir(self, env_type):78 def _get_sample_destination_dir(self, env_type):
80 if env_type == EnvironmentTypes.click:79 return os.path.expanduser("~/Pictures")
81 pic_dir = os.path.expanduser("~/Pictures")
82 pic_bak_dir = pic_dir + '.apbak'
83 # Only save and restore if it previously existed
84 if os.path.exists(pic_dir):
85 shutil.move(pic_dir, pic_bak_dir)
86 self.addCleanup(
87 logger.debug, "Restoring backed up pics to %s" % pic_dir)
88 self.addCleanup(shutil.move, pic_bak_dir, pic_dir)
89 return pic_dir
90 else:
91 return self._default_sample_destination_dir
9280
93 def configure_db(self):81 def configure_db(self):
94 db = os.path.expanduser(self._db)82 db = os.path.expanduser(self._db)
95 db_bak = db + '.apbak'
96 # Only save and restore if it previously existed
97 if os.path.exists(db):
98 shutil.move(db, db_bak)
99 self.addCleanup(shutil.move, db_bak, db)
100 if not os.path.exists(os.path.dirname(db)):83 if not os.path.exists(os.path.dirname(db)):
101 os.makedirs(os.path.dirname(db))84 os.makedirs(os.path.dirname(db))
102 mock_db = os.path.join(self.sample_destination_dir, '.database',85 mock_db = os.path.join(self.sample_destination_dir, '.database',
@@ -105,11 +88,6 @@
10588
106 def configure_thumbnails(self):89 def configure_thumbnails(self):
107 thumbs = os.path.expanduser(self._thumbs)90 thumbs = os.path.expanduser(self._thumbs)
108 thumbs_bak = thumbs + '.apbak'
109 # Only save and restore if it previously existed
110 if os.path.exists(thumbs):
111 shutil.move(thumbs, thumbs_bak)
112 self.addCleanup(shutil.move, thumbs_bak, thumbs)
113 if not os.path.exists(os.path.dirname(thumbs)):91 if not os.path.exists(os.path.dirname(thumbs)):
114 os.makedirs(os.path.dirname(thumbs))92 os.makedirs(os.path.dirname(thumbs))
115 mock_thumbs = os.path.join(self.sample_destination_dir, '.thumbnails')93 mock_thumbs = os.path.join(self.sample_destination_dir, '.thumbnails')
@@ -117,8 +95,7 @@
11795
118 def configure_sample_files(self, env_type):96 def configure_sample_files(self, env_type):
119 self.sample_dir = resource_filename('gallery_app', 'data')97 self.sample_dir = resource_filename('gallery_app', 'data')
120 self.sample_destination_dir = \98 self.sample_destination_dir = self._get_sample_destination_dir()
121 self._get_sample_destination_dir(env_type)
122 if (os.path.exists(self.sample_destination_dir)):99 if (os.path.exists(self.sample_destination_dir)):
123 shutil.rmtree(self.sample_destination_dir)100 shutil.rmtree(self.sample_destination_dir)
124 self.assertFalse(os.path.exists(self.sample_destination_dir))101 self.assertFalse(os.path.exists(self.sample_destination_dir))
@@ -137,7 +114,7 @@
137 self.sample_file_source = \114 self.sample_file_source = \
138 default_data_dir + self.sample_file_source115 default_data_dir + self.sample_file_source
139116
140 if env_type == EnvironmentTypes.click:117 if env_type is fixture_setup.Launcher.installed_click:
141 self.configure_db()118 self.configure_db()
142 self.configure_thumbnails()119 self.configure_thumbnails()
143120
@@ -169,56 +146,10 @@
169 sleep(2)146 sleep(2)
170147
171 def launch_gallery_app(self, env_type):148 def launch_gallery_app(self, env_type):
172 if env_type == EnvironmentTypes.installed:149 launch_fixture = fixture_setup.LaunchGalleryApp(
173 self.launch_test_installed()150 env_type, self.local_location)
174 elif env_type == EnvironmentTypes.local:151 self.useFixture(launch_fixture)
175 self.launch_test_local()152 self.app = launch_fixture.application_proxy
176 elif env_type == EnvironmentTypes.click:
177 self.launch_test_click()
178 else:
179 raise ValueError("Unknown environment type: %s", env_type)
180
181 def launch_test_local(self):
182 logger.debug("Launching local gallery-app binary.")
183 self.ARGS.append(self.sample_destination_dir)
184 self.app = self.launch_test_application(
185 self.local_location,
186 *self.ARGS,
187 emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
188
189 def launch_test_installed(self):
190 if model() == 'Desktop':
191 logger.debug(
192 "Launching installed gallery-app binary for desktop."
193 )
194 self.ARGS.append(self.sample_destination_dir)
195 self.app = self.launch_test_application(
196 "gallery-app",
197 *self.ARGS,
198 emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
199 else:
200 logger.debug(
201 "Launching installed gallery-app binary for device."
202 )
203 self.ARGS.append("--desktop_file_hint="
204 "/usr/share/applications/gallery-app.desktop")
205 self.ARGS.append(self.sample_destination_dir)
206 self.app = self.launch_test_application(
207 "gallery-app",
208 *self.ARGS,
209 app_type='qt',
210 emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
211
212 def launch_test_click(self):
213 '''
214 Since this test runs under confinement, the only location photos
215 are searchable in is ~/Pictures.
216 '''
217 logger.debug("Launching gallery-app via click package.")
218 self.app = self.launch_click_package(
219 package_id="com.ubuntu.gallery",
220 app_uris=' '.join(self.ARGS),
221 emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
222153
223 def ui_update(self):154 def ui_update(self):
224 """ Gives the program the time to update the UI"""155 """ Gives the program the time to update the UI"""

Subscribers

People subscribed via source and target branches