Merge lp:~canonical-platform-qa/gallery-app/fix1376423-no_backup into lp:gallery-app
- fix1376423-no_backup
- Merge into trunk
| 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 |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| PS Jenkins bot | continuous-integration | Needs Fixing | |
| Ubuntu Phablet Team | Pending | ||
| Review via email: | |||
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.
Description of the change
| PS Jenkins bot (ps-jenkins) wrote : | # |
| Leonardo Arias Fonseca (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 Leonardo Arias Fonseca
-
Merged with prerequisite.
- 1104. By Leonardo Arias Fonseca
-
Fixed the method definition.
- 1105. By Leonardo Arias Fonseca
-
Keep the database patching for now.
- 1106. By Leonardo Arias Fonseca
-
Make the pictures dir location and configuration independent.
- 1107. By Leonardo Arias Fonseca
-
Reverted to use the hardcoded path. The phone doesn't have xdg-user-dir.
- 1108. By Leonardo Arias Fonseca
-
Raise an exception if the pictures directory is not empty.
- 1109. By Leonardo Arias Fonseca
-
Clean the pictures directory.
- 1110. By Leonardo Arias Fonseca
-
Clean the pictures directory.
Unmerged revisions
- 1110. By Leonardo Arias Fonseca
-
Clean the pictures directory.
- 1109. By Leonardo Arias Fonseca
-
Clean the pictures directory.
- 1108. By Leonardo Arias Fonseca
-
Raise an exception if the pictures directory is not empty.
- 1107. By Leonardo Arias Fonseca
-
Reverted to use the hardcoded path. The phone doesn't have xdg-user-dir.
- 1106. By Leonardo Arias Fonseca
-
Make the pictures dir location and configuration independent.
- 1105. By Leonardo Arias Fonseca
-
Keep the database patching for now.
- 1104. By Leonardo Arias Fonseca
-
Fixed the method definition.
- 1103. By Leonardo Arias Fonseca
-
Merged with prerequisite.
- 1102. By Leonardo Arias Fonseca
-
Do not backup existing files during autopilot tests. We will assume a clean environment from now on.
Preview Diff
| 1 | === modified file 'debian/control' |
| 2 | --- debian/control 2014-07-26 03:12:53 +0000 |
| 3 | +++ debian/control 2014-10-15 04:41:38 +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 | === added file 'tests/autopilot/gallery_app/fixture_setup.py' |
| 21 | --- tests/autopilot/gallery_app/fixture_setup.py 1970-01-01 00:00:00 +0000 |
| 22 | +++ tests/autopilot/gallery_app/fixture_setup.py 2014-10-15 04:41:38 +0000 |
| 23 | @@ -0,0 +1,136 @@ |
| 24 | +# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
| 25 | +# |
| 26 | +# Copyright (C) 2014 Canonical Ltd. |
| 27 | +# |
| 28 | +# This file is part of gallery-app. |
| 29 | +# |
| 30 | +# gallery-app is free software: you can redistribute it and/or modify it under |
| 31 | +# the terms of the GNU General Public License as published by the Free Software |
| 32 | +# Foundation; version 3. |
| 33 | +# |
| 34 | +# gallery-app is distributed in the hope that it will be useful, but WITHOUT |
| 35 | +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 36 | +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 37 | +# details. |
| 38 | +# |
| 39 | +# You should have received a copy of the GNU General Public License along with |
| 40 | +# this program. If not, see <http://www.gnu.org/licenses/>. |
| 41 | + |
| 42 | +import enum |
| 43 | +import logging |
| 44 | +import os |
| 45 | +import shutil |
| 46 | + |
| 47 | +import fixtures |
| 48 | +import ubuntuuitoolkit |
| 49 | +from autopilot import application |
| 50 | + |
| 51 | + |
| 52 | +logger = logging.getLogger(__name__) |
| 53 | + |
| 54 | + |
| 55 | +_BASE_CLASS = ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase |
| 56 | + |
| 57 | + |
| 58 | +class Launcher(enum.Enum): |
| 59 | + local_binary = 1 |
| 60 | + installed_binary = 2 |
| 61 | + installed_click = 3 |
| 62 | + |
| 63 | + |
| 64 | +class LaunchGalleryApp(fixtures.Fixture): |
| 65 | + |
| 66 | + """Fixture to launch the Gallery App.""" |
| 67 | + |
| 68 | + def __init__(self, type_, binary_path=None): |
| 69 | + """Initialize the fixture. |
| 70 | + |
| 71 | + :param type_: The type of the launcher to use. |
| 72 | + :type type_: One of the values of the Launcher enum. |
| 73 | + :param str binary_path: The path to use with the |
| 74 | + Launcher.installed_binary type. Not used for the other types. |
| 75 | + |
| 76 | + """ |
| 77 | + super().__init__() |
| 78 | + if type_ is Launcher.local_binary: |
| 79 | + self.launcher = _LaunchLocalBinaryGalleryApp(binary_path) |
| 80 | + elif type_ is Launcher.installed_binary: |
| 81 | + self.launcher = _LaunchInstalledBinaryGalleryApp() |
| 82 | + elif type_ is Launcher.installed_click: |
| 83 | + self.launcher = _LaunchInstalledClickGalleryApp() |
| 84 | + else: |
| 85 | + raise TypeError('Unknown launcher type: {}.'.format(type_)) |
| 86 | + |
| 87 | + def setUp(self): |
| 88 | + super().setUp() |
| 89 | + self.useFixture(self.launcher) |
| 90 | + self.application_proxy = self.launcher.application_proxy |
| 91 | + |
| 92 | + |
| 93 | +class _LaunchLocalBinaryGalleryApp(fixtures.Fixture): |
| 94 | + |
| 95 | + """Fixture to launch the Gallery App from the local binary.""" |
| 96 | + |
| 97 | + def __init__(self, binary_path): |
| 98 | + super().__init__() |
| 99 | + self.binary_path = binary_path |
| 100 | + |
| 101 | + def setUp(self): |
| 102 | + """Launch the application when the fixture is used.""" |
| 103 | + super().setUp() |
| 104 | + self._copy_binary_to_right_location() |
| 105 | + self.application_proxy = self._launch_application() |
| 106 | + |
| 107 | + def _copy_binary_to_right_location(self): |
| 108 | + # XXX workaround for bug http://pad.lv/1381312 |
| 109 | + workaround_binary_directory = os.path.abspath(os.path.join('..', '..')) |
| 110 | + workaround_binary_path = os.path.join( |
| 111 | + workaround_binary_directory, os.path.basename(self.binary_path)) |
| 112 | + shutil.copy(self.binary_path, workaround_binary_directory) |
| 113 | + self.addCleanup(os.remove, workaround_binary_path) |
| 114 | + self.binary_path = workaround_binary_path |
| 115 | + |
| 116 | + def _launch_application(self): |
| 117 | + logger.info('Launching gallery-app using the binary at {}.'.format( |
| 118 | + self.binary_path)) |
| 119 | + application_launcher = self.useFixture( |
| 120 | + application.NormalApplicationLauncher(emulator_base=_BASE_CLASS)) |
| 121 | + application_proxy = application_launcher.launch( |
| 122 | + self.binary_path, |
| 123 | + app_type='qt', |
| 124 | + launch_dir=os.path.dirname(self.binary_path), |
| 125 | + ) |
| 126 | + return application_proxy |
| 127 | + |
| 128 | + |
| 129 | +class _LaunchInstalledBinaryGalleryApp(fixtures.Fixture): |
| 130 | + |
| 131 | + """Fixture to launch the Gallery App from the installed binary.""" |
| 132 | + |
| 133 | + def setUp(self): |
| 134 | + super().setUp() |
| 135 | + """Launch the application when the fixture is used.""" |
| 136 | + self.application_proxy = self._launch_application() |
| 137 | + |
| 138 | + def _launch_application(self): |
| 139 | + logger.info('Launching gallery-app using the installed binary.') |
| 140 | + application_launcher = self.useFixture( |
| 141 | + application.UpstartApplicationLauncher(emulator_base=_BASE_CLASS)) |
| 142 | + application_proxy = application_launcher.launch('gallery-app') |
| 143 | + return application_proxy |
| 144 | + |
| 145 | + |
| 146 | +class _LaunchInstalledClickGalleryApp(fixtures.Fixture): |
| 147 | + |
| 148 | + """Fixture to launch the Gallery App from the installed click package.""" |
| 149 | + |
| 150 | + def setUp(self): |
| 151 | + super().setUp() |
| 152 | + self.application_proxy = self._launch_application() |
| 153 | + |
| 154 | + def _launch_application(self): |
| 155 | + logger.info('Launching gallery-app using the installed click package.') |
| 156 | + application_launcher = self.useFixture( |
| 157 | + application.ClickApplicationLauncher(emulator_base=_BASE_CLASS)) |
| 158 | + application_proxy = application_launcher.launch('com.ubuntu.gallery') |
| 159 | + return application_proxy |
| 160 | |
| 161 | === modified file 'tests/autopilot/gallery_app/tests/__init__.py' |
| 162 | --- tests/autopilot/gallery_app/tests/__init__.py 2014-09-19 04:22:12 +0000 |
| 163 | +++ tests/autopilot/gallery_app/tests/__init__.py 2014-10-15 04:41:38 +0000 |
| 164 | @@ -1,9 +1,20 @@ |
| 165 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
| 166 | -# Copyright 2012 Canonical |
| 167 | -# |
| 168 | -# This program is free software: you can redistribute it and/or modify it |
| 169 | -# under the terms of the GNU General Public License version 3, as published |
| 170 | -# by the Free Software Foundation. |
| 171 | +# |
| 172 | +# Copyright (C) 2012, 2014 Canonical Ltd. |
| 173 | +# |
| 174 | +# This file is part of gallery-app. |
| 175 | +# |
| 176 | +# gallery-app is free software: you can redistribute it and/or modify it under |
| 177 | +# the terms of the GNU General Public License as published by the Free Software |
| 178 | +# Foundation; version 3. |
| 179 | +# |
| 180 | +# gallery-app is distributed in the hope that it will be useful, but WITHOUT |
| 181 | +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 182 | +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 183 | +# details. |
| 184 | +# |
| 185 | +# You should have received a copy of the GNU General Public License along with |
| 186 | +# this program. If not, see <http://www.gnu.org/licenses/>. |
| 187 | |
| 188 | """gallery autopilot tests.""" |
| 189 | |
| 190 | @@ -18,8 +29,9 @@ |
| 191 | from autopilot.testcase import AutopilotTestCase |
| 192 | from autopilot.introspection import get_proxy_object_for_existing_process |
| 193 | from pkg_resources import resource_filename |
| 194 | - |
| 195 | from ubuntuuitoolkit import emulators as toolkit_emulators |
| 196 | + |
| 197 | +from gallery_app import fixture_setup |
| 198 | from gallery_app.emulators import main_screen |
| 199 | from gallery_app.emulators.gallery_utils import GalleryUtils |
| 200 | |
| 201 | @@ -28,12 +40,6 @@ |
| 202 | logger = logging.getLogger(__name__) |
| 203 | |
| 204 | |
| 205 | -class EnvironmentTypes: |
| 206 | - installed = "installed" |
| 207 | - local = "local" |
| 208 | - click = "click" |
| 209 | - |
| 210 | - |
| 211 | class GalleryTestCase(AutopilotTestCase): |
| 212 | |
| 213 | """A common test case class that provides several useful methods for |
| 214 | @@ -41,14 +47,12 @@ |
| 215 | |
| 216 | sample_file_source = "/sample01.jpg" |
| 217 | tap_press_time = 1 |
| 218 | - local_location = "../../src/gallery-app" |
| 219 | + local_location = os.path.abspath('../../src/gallery-app') |
| 220 | |
| 221 | _db = '~/.local/share/com.ubuntu.gallery/' \ |
| 222 | 'database/gallery.sqlite' |
| 223 | _thumbs = '~/.cache/com.ubuntu.gallery/thumbnails' |
| 224 | |
| 225 | - _default_sample_destination_dir = "/tmp/gallery-ap_sd" |
| 226 | - |
| 227 | ARGS = [] |
| 228 | |
| 229 | @property |
| 230 | @@ -64,39 +68,18 @@ |
| 231 | gallery-app. |
| 232 | |
| 233 | """ |
| 234 | - # Lets assume we are installed system wide if this file is somewhere |
| 235 | - # in /usr |
| 236 | - if os.path.realpath(__file__).startswith("/usr/"): |
| 237 | - return EnvironmentTypes.installed |
| 238 | - if model() == 'Desktop': |
| 239 | - return EnvironmentTypes.installed |
| 240 | + if os.path.exists(self.local_location): |
| 241 | + return fixture_setup.Launcher.local_binary |
| 242 | + elif model() == 'Desktop': |
| 243 | + return fixture_setup.Launcher.installed_binary |
| 244 | else: |
| 245 | - if os.path.exists(self.local_location): |
| 246 | - return EnvironmentTypes.local |
| 247 | - else: |
| 248 | - return EnvironmentTypes.click |
| 249 | + return fixture_setup.Launcher.installed_click |
| 250 | |
| 251 | def _get_sample_destination_dir(self, env_type): |
| 252 | - if env_type == EnvironmentTypes.click: |
| 253 | - pic_dir = os.path.expanduser("~/Pictures") |
| 254 | - pic_bak_dir = pic_dir + '.apbak' |
| 255 | - # Only save and restore if it previously existed |
| 256 | - if os.path.exists(pic_dir): |
| 257 | - shutil.move(pic_dir, pic_bak_dir) |
| 258 | - self.addCleanup( |
| 259 | - logger.debug, "Restoring backed up pics to %s" % pic_dir) |
| 260 | - self.addCleanup(shutil.move, pic_bak_dir, pic_dir) |
| 261 | - return pic_dir |
| 262 | - else: |
| 263 | - return self._default_sample_destination_dir |
| 264 | + return os.path.expanduser("~/Pictures") |
| 265 | |
| 266 | def configure_db(self): |
| 267 | db = os.path.expanduser(self._db) |
| 268 | - db_bak = db + '.apbak' |
| 269 | - # Only save and restore if it previously existed |
| 270 | - if os.path.exists(db): |
| 271 | - shutil.move(db, db_bak) |
| 272 | - self.addCleanup(shutil.move, db_bak, db) |
| 273 | if not os.path.exists(os.path.dirname(db)): |
| 274 | os.makedirs(os.path.dirname(db)) |
| 275 | mock_db = os.path.join(self.sample_destination_dir, '.database', |
| 276 | @@ -105,11 +88,6 @@ |
| 277 | |
| 278 | def configure_thumbnails(self): |
| 279 | thumbs = os.path.expanduser(self._thumbs) |
| 280 | - thumbs_bak = thumbs + '.apbak' |
| 281 | - # Only save and restore if it previously existed |
| 282 | - if os.path.exists(thumbs): |
| 283 | - shutil.move(thumbs, thumbs_bak) |
| 284 | - self.addCleanup(shutil.move, thumbs_bak, thumbs) |
| 285 | if not os.path.exists(os.path.dirname(thumbs)): |
| 286 | os.makedirs(os.path.dirname(thumbs)) |
| 287 | mock_thumbs = os.path.join(self.sample_destination_dir, '.thumbnails') |
| 288 | @@ -117,8 +95,7 @@ |
| 289 | |
| 290 | def configure_sample_files(self, env_type): |
| 291 | self.sample_dir = resource_filename('gallery_app', 'data') |
| 292 | - self.sample_destination_dir = \ |
| 293 | - self._get_sample_destination_dir(env_type) |
| 294 | + self.sample_destination_dir = self._get_sample_destination_dir() |
| 295 | if (os.path.exists(self.sample_destination_dir)): |
| 296 | shutil.rmtree(self.sample_destination_dir) |
| 297 | self.assertFalse(os.path.exists(self.sample_destination_dir)) |
| 298 | @@ -137,7 +114,7 @@ |
| 299 | self.sample_file_source = \ |
| 300 | default_data_dir + self.sample_file_source |
| 301 | |
| 302 | - if env_type == EnvironmentTypes.click: |
| 303 | + if env_type is fixture_setup.Launcher.installed_click: |
| 304 | self.configure_db() |
| 305 | self.configure_thumbnails() |
| 306 | |
| 307 | @@ -169,56 +146,10 @@ |
| 308 | sleep(2) |
| 309 | |
| 310 | def launch_gallery_app(self, env_type): |
| 311 | - if env_type == EnvironmentTypes.installed: |
| 312 | - self.launch_test_installed() |
| 313 | - elif env_type == EnvironmentTypes.local: |
| 314 | - self.launch_test_local() |
| 315 | - elif env_type == EnvironmentTypes.click: |
| 316 | - self.launch_test_click() |
| 317 | - else: |
| 318 | - raise ValueError("Unknown environment type: %s", env_type) |
| 319 | - |
| 320 | - def launch_test_local(self): |
| 321 | - logger.debug("Launching local gallery-app binary.") |
| 322 | - self.ARGS.append(self.sample_destination_dir) |
| 323 | - self.app = self.launch_test_application( |
| 324 | - self.local_location, |
| 325 | - *self.ARGS, |
| 326 | - emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase) |
| 327 | - |
| 328 | - def launch_test_installed(self): |
| 329 | - if model() == 'Desktop': |
| 330 | - logger.debug( |
| 331 | - "Launching installed gallery-app binary for desktop." |
| 332 | - ) |
| 333 | - self.ARGS.append(self.sample_destination_dir) |
| 334 | - self.app = self.launch_test_application( |
| 335 | - "gallery-app", |
| 336 | - *self.ARGS, |
| 337 | - emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase) |
| 338 | - else: |
| 339 | - logger.debug( |
| 340 | - "Launching installed gallery-app binary for device." |
| 341 | - ) |
| 342 | - self.ARGS.append("--desktop_file_hint=" |
| 343 | - "/usr/share/applications/gallery-app.desktop") |
| 344 | - self.ARGS.append(self.sample_destination_dir) |
| 345 | - self.app = self.launch_test_application( |
| 346 | - "gallery-app", |
| 347 | - *self.ARGS, |
| 348 | - app_type='qt', |
| 349 | - emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase) |
| 350 | - |
| 351 | - def launch_test_click(self): |
| 352 | - ''' |
| 353 | - Since this test runs under confinement, the only location photos |
| 354 | - are searchable in is ~/Pictures. |
| 355 | - ''' |
| 356 | - logger.debug("Launching gallery-app via click package.") |
| 357 | - self.app = self.launch_click_package( |
| 358 | - package_id="com.ubuntu.gallery", |
| 359 | - app_uris=' '.join(self.ARGS), |
| 360 | - emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase) |
| 361 | + launch_fixture = fixture_setup.LaunchGalleryApp( |
| 362 | + env_type, self.local_location) |
| 363 | + self.useFixture(launch_fixture) |
| 364 | + self.app = launch_fixture.application_proxy |
| 365 | |
| 366 | def ui_update(self): |
| 367 | """ Gives the program the time to update the UI""" |
FAILED: Continuous integration, rev:1102 jenkins. qa.ubuntu. com/job/ gallery- app-ci/ 1065/ jenkins. qa.ubuntu. com/job/ gallery- app-utopic- amd64-ci/ 240 jenkins. qa.ubuntu. com/job/ gallery- app-utopic- armhf-ci/ 240 jenkins. qa.ubuntu. com/job/ gallery- app-utopic- armhf-ci/ 240/artifact/ work/output/ *zip*/output. zip jenkins. qa.ubuntu. com/job/ gallery- app-utopic- i386-ci/ 240 jenkins. qa.ubuntu. com/job/ generic- click-autopilot -utopic- touch/488 jenkins. qa.ubuntu. com/job/ generic- mediumtests- utopic/ 4088 jenkins. qa.ubuntu. com/job/ generic- click-autopilot -runner- mako/631 jenkins. qa.ubuntu. com/job/ generic- click-builder- utopic- armhf/810 s-jenkins. ubuntu- ci:8080/ job/touch- flash-device/ 14684 jenkins. qa.ubuntu. com/job/ autopilot- testrunner- otto-utopic/ 3450 jenkins. qa.ubuntu. com/job/ generic- mediumtests- builder- utopic- amd64/4417 jenkins. qa.ubuntu. com/job/ generic- mediumtests- builder- utopic- amd64/4417/ artifact/ work/output/ *zip*/output. zip
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
UNSTABLE: http://
SUCCESS: http://
UNSTABLE: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/gallery- app-ci/ 1065/rebuild
http://