Merge lp:~canonical-platform-qa/gallery-app/fix1376423-no_backup 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/fix1376423-no_backup
Merge into: lp:~canonical-platform-qa/gallery-app/clean_autopilot_setup
Prerequisite: lp:~canonical-platform-qa/gallery-app/fix1381259-launch_fixture
Diff against target: 108 lines (+21/-28)
1 file modified
tests/autopilot/gallery_app/tests/__init__.py (+21/-28)
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 Pending
Ubuntu Phablet Team Pending
Review via email: mp+238383@code.launchpad.net

This proposal supersedes a proposal from 2014-10-14.

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 : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Leo Arias (elopio) wrote : Posted in a previous version of this proposal

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.

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 'tests/autopilot/gallery_app/tests/__init__.py'
--- tests/autopilot/gallery_app/tests/__init__.py 2014-10-20 19:50:32 +0000
+++ tests/autopilot/gallery_app/tests/__init__.py 2014-10-20 19:50:32 +0000
@@ -1,6 +1,6 @@
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#2#
3# Copyright (C) 2014 Canonical Ltd.3# Copyright (C) 2012, 2014 Canonical Ltd.
4#4#
5# This file is part of gallery-app.5# This file is part of gallery-app.
6#6#
@@ -22,6 +22,7 @@
22import logging22import logging
23import shutil23import shutil
24import signal24import signal
25from time import sleep
2526
26from testtools.matchers import Equals, NotEquals, GreaterThan27from testtools.matchers import Equals, NotEquals, GreaterThan
27from autopilot.matchers import Eventually28from autopilot.matchers import Eventually
@@ -35,11 +36,13 @@
35from gallery_app.emulators import main_screen36from gallery_app.emulators import main_screen
36from gallery_app.emulators.gallery_utils import GalleryUtils37from gallery_app.emulators.gallery_utils import GalleryUtils
3738
38from time import sleep
39
40logger = logging.getLogger(__name__)39logger = logging.getLogger(__name__)
4140
4241
42class GalleryException(Exception):
43 pass
44
45
43class GalleryTestCase(AutopilotTestCase):46class GalleryTestCase(AutopilotTestCase):
4447
45 """A common test case class that provides several useful methods for48 """A common test case class that provides several useful methods for
@@ -76,24 +79,13 @@
76 return fixture_setup.Launcher.installed_click79 return fixture_setup.Launcher.installed_click
7780
78 def _get_sample_destination_dir(self):81 def _get_sample_destination_dir(self):
79 pic_dir = os.path.expanduser("~/Pictures")82 return os.path.expanduser('~/Pictures')
80 pic_bak_dir = pic_dir + '.apbak'
81 # Only save and restore if it previously existed
82 if os.path.exists(pic_dir):
83 shutil.move(pic_dir, pic_bak_dir)
84 self.addCleanup(
85 logger.debug, "Restoring backed up pics to %s" % pic_dir)
86 self.addCleanup(shutil.move, pic_bak_dir, pic_dir)
87 return pic_dir
8883
89 def configure_db(self):84 def configure_db(self):
90 db = os.path.expanduser(self._db)85 db = os.path.expanduser(self._db)
91 db_bak = db + '.apbak'
92 # Only save and restore if it previously existed
93 if os.path.exists(db):86 if os.path.exists(db):
94 shutil.move(db, db_bak)87 os.remove(db)
95 self.addCleanup(shutil.move, db_bak, db)88 elif not os.path.exists(os.path.dirname(db)):
96 if not os.path.exists(os.path.dirname(db)):
97 os.makedirs(os.path.dirname(db))89 os.makedirs(os.path.dirname(db))
98 mock_db = os.path.join(self.sample_destination_dir, '.database',90 mock_db = os.path.join(self.sample_destination_dir, '.database',
99 'gallery_confined.sqlite')91 'gallery_confined.sqlite')
@@ -101,12 +93,9 @@
10193
102 def configure_thumbnails(self):94 def configure_thumbnails(self):
103 thumbs = os.path.expanduser(self._thumbs)95 thumbs = os.path.expanduser(self._thumbs)
104 thumbs_bak = thumbs + '.apbak'
105 # Only save and restore if it previously existed
106 if os.path.exists(thumbs):96 if os.path.exists(thumbs):
107 shutil.move(thumbs, thumbs_bak)97 shutil.rmtree(thumbs)
108 self.addCleanup(shutil.move, thumbs_bak, thumbs)98 elif not os.path.exists(os.path.dirname(thumbs)):
109 if not os.path.exists(os.path.dirname(thumbs)):
110 os.makedirs(os.path.dirname(thumbs))99 os.makedirs(os.path.dirname(thumbs))
111 mock_thumbs = os.path.join(self.sample_destination_dir, '.thumbnails')100 mock_thumbs = os.path.join(self.sample_destination_dir, '.thumbnails')
112 shutil.move(mock_thumbs, thumbs)101 shutil.move(mock_thumbs, thumbs)
@@ -114,9 +103,14 @@
114 def configure_sample_files(self, env_type):103 def configure_sample_files(self, env_type):
115 self.sample_dir = resource_filename('gallery_app', 'data')104 self.sample_dir = resource_filename('gallery_app', 'data')
116 self.sample_destination_dir = self._get_sample_destination_dir()105 self.sample_destination_dir = self._get_sample_destination_dir()
117 if (os.path.exists(self.sample_destination_dir)):106 if os.path.exists(self.sample_destination_dir):
118 shutil.rmtree(self.sample_destination_dir)107 try:
119 self.assertFalse(os.path.exists(self.sample_destination_dir))108 os.rmdir(self.sample_destination_dir)
109 except OSError:
110 raise GalleryException('The pictures directory is not empty.')
111
112 self.addCleanup(shutil.rmtree, self.sample_destination_dir)
113 self.addCleanup(os.mkdir, self.sample_destination_dir)
120114
121 self.sample_file = os.path.join(115 self.sample_file = os.path.join(
122 self.sample_destination_dir,116 self.sample_destination_dir,
@@ -132,9 +126,8 @@
132 self.sample_file_source = \126 self.sample_file_source = \
133 default_data_dir + self.sample_file_source127 default_data_dir + self.sample_file_source
134128
135 if env_type is fixture_setup.Launcher.installed_click:129 self.configure_db()
136 self.configure_db()130 self.configure_thumbnails()
137 self.configure_thumbnails()
138131
139 def do_reset_config(self):132 def do_reset_config(self):
140 config = os.path.expanduser(133 config = os.path.expanduser(

Subscribers

People subscribed via source and target branches

to all changes: