Merge lp:~nskaggs/music-app/drop-ap-mocking into lp:music-app/remix

Proposed by Nicholas Skaggs
Status: Superseded
Proposed branch: lp:~nskaggs/music-app/drop-ap-mocking
Merge into: lp:music-app/remix
Diff against target: 221 lines (+40/-106)
1 file modified
tests/autopilot/music_app/tests/__init__.py (+40/-106)
To merge this branch: bzr merge lp:~nskaggs/music-app/drop-ap-mocking
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Music App Developers Pending
Review via email: mp+241627@code.launchpad.net

This proposal has been superseded by a proposal from 2014-11-12.

Commit message

Drop AP mocking

Description of the change

Drop AP mocking

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
738. By Nicholas Skaggs

don't patch ms on devices

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'tests/autopilot/music_app/tests/__init__.py'
--- tests/autopilot/music_app/tests/__init__.py 2014-09-25 00:39:47 +0000
+++ tests/autopilot/music_app/tests/__init__.py 2014-11-12 22:01:06 +0000
@@ -1,9 +1,18 @@
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 2013, 2014 Canonical2#
3#3# Copyright (C) 2013, 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 program is free software: you can redistribute it and/or modify
6# by the Free Software Foundation.6# it under the terms of the GNU General Public License version 3 as
7# published by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
716
8"""Music app autopilot tests."""17"""Music app autopilot tests."""
918
@@ -18,16 +27,10 @@
18from music_app import MusicApp27from music_app import MusicApp
1928
20from autopilot import logging as autopilot_logging29from autopilot import logging as autopilot_logging
21from autopilot.input import Mouse, Touch
22from autopilot.platform import model
23from autopilot.testcase import AutopilotTestCase30from autopilot.testcase import AutopilotTestCase
2431
25import ubuntuuitoolkit32import ubuntuuitoolkit
26from ubuntuuitoolkit import (33from ubuntuuitoolkit import base
27 base,
28 fixture_setup as toolkit_fixtures
29)
30
3134
32logger = logging.getLogger(__name__)35logger = logging.getLogger(__name__)
3336
@@ -38,10 +41,6 @@
38 music-app tests.41 music-app tests.
3942
40 """43 """
41 if model() == 'Desktop':
42 scenarios = [('with mouse', dict(input_device_class=Mouse))]
43 else:
44 scenarios = [('with touch', dict(input_device_class=Touch))]
4544
46 working_dir = os.getcwd()45 working_dir = os.getcwd()
47 local_location_dir = os.path.dirname(os.path.dirname(working_dir))46 local_location_dir = os.path.dirname(os.path.dirname(working_dir))
@@ -62,10 +61,9 @@
6261
63 def setUp(self):62 def setUp(self):
64 super(BaseTestCaseWithPatchedHome, self).setUp()63 super(BaseTestCaseWithPatchedHome, self).setUp()
65 _, test_type = self.get_launcher_method_and_type()64 self.launcher, self.test_type = self.get_launcher_method_and_type()
66 self.home_dir = self._patch_home(test_type)65 self.home_dir = self._patch_home()
6766 self._create_music_library()
68 self._create_music_library(test_type)
6967
70 @autopilot_logging.log_action(logger.info)68 @autopilot_logging.log_action(logger.info)
71 def launch_test_local(self):69 def launch_test_local(self):
@@ -108,63 +106,17 @@
108 '.Xauthority')),106 '.Xauthority')),
109 os.path.join(directory, '.Xauthority'))107 os.path.join(directory, '.Xauthority'))
110108
111 def _patch_home(self, test_type):109 def _patch_home(self):
112 """ mock /home for testing purposes to preserve user data110 """ mock /home for testing purposes to preserve user data
113 """111 """
114112
115 original_home = os.environ.get('HOME')113 # if running on non-phablet device,
116 original_ual = os.environ.get('UBUNTU_APP_LAUNCH_LINK_FARM')114 # run in temp folder to avoid mucking up home
117115 # bug 1316746
118 # click requires apparmor profile, and writing to special dir116 # bug 1376423
119 # but the desktop can write to a traditional /tmp directory117 if self.test_type is 'click':
120 if test_type == 'click':118 # just use home for now on devices
121 env_dir = os.path.join(os.environ.get('HOME'), 'autopilot',119 temp_dir = os.environ.get('HOME')
122 'fakeenv')
123
124 if not os.path.exists(env_dir):
125 os.makedirs(env_dir)
126
127 temp_dir_fixture = fixtures.TempDir(env_dir)
128 self.useFixture(temp_dir_fixture)
129
130 # apparmor doesn't allow the app to create needed directories,
131 # so we create them now
132 temp_dir = temp_dir_fixture.path
133 temp_dir_cache = os.path.join(temp_dir, '.cache')
134 temp_dir_cache_font = os.path.join(temp_dir_cache, 'fontconfig')
135 temp_dir_cache_media = os.path.join(temp_dir_cache, 'media-art')
136 temp_dir_cache_write = os.path.join(temp_dir_cache,
137 'tncache-write-text.null')
138 temp_dir_config = os.path.join(temp_dir, '.config')
139 temp_dir_toolkit = os.path.join(temp_dir_config,
140 'ubuntu-ui-toolkit')
141 temp_dir_font = os.path.join(temp_dir_cache, '.fontconfig')
142 temp_dir_local = os.path.join(temp_dir, '.local', 'share')
143 temp_dir_confined = os.path.join(temp_dir, 'confined')
144
145 if not os.path.exists(temp_dir_cache):
146 os.makedirs(temp_dir_cache)
147 if not os.path.exists(temp_dir_cache_font):
148 os.makedirs(temp_dir_cache_font)
149 if not os.path.exists(temp_dir_cache_media):
150 os.makedirs(temp_dir_cache_media)
151 if not os.path.exists(temp_dir_cache_write):
152 os.makedirs(temp_dir_cache_write)
153 if not os.path.exists(temp_dir_config):
154 os.makedirs(temp_dir_config)
155 if not os.path.exists(temp_dir_toolkit):
156 os.makedirs(temp_dir_toolkit)
157 if not os.path.exists(temp_dir_font):
158 os.makedirs(temp_dir_font)
159 if not os.path.exists(temp_dir_local):
160 os.makedirs(temp_dir_local)
161 if not os.path.exists(temp_dir_confined):
162 os.makedirs(temp_dir_confined)
163
164 # before we set fixture, copy xauthority if needed
165 self._copy_xauthority_file(temp_dir)
166 self.useFixture(toolkit_fixtures.InitctlEnvironmentVariable(
167 HOME=temp_dir))
168 else:120 else:
169 temp_dir_fixture = fixtures.TempDir()121 temp_dir_fixture = fixtures.TempDir()
170 self.useFixture(temp_dir_fixture)122 self.useFixture(temp_dir_fixture)
@@ -175,29 +127,11 @@
175 self.useFixture(fixtures.EnvironmentVariable('HOME',127 self.useFixture(fixtures.EnvironmentVariable('HOME',
176 newvalue=temp_dir))128 newvalue=temp_dir))
177129
178 def undo_patch(key, value):130 logger.debug("Patched home to fake home directory %s" % temp_dir)
179 logging.info(
180 "Resetting environment variable '%s' to '%s'",
181 key,
182 value
183 )
184
185 os.environ[key] = value
186
187 # TODO: Remove code once pad.lv/1370800 is fixed
188 os.environ["HOME"] = temp_dir
189 os.environ["UBUNTU_APP_LAUNCH_LINK_FARM"] = original_home + "/.cache" \
190 "/ubuntu-app-launch/desktop"
191
192 self.addCleanup(undo_patch, "HOME", original_home)
193 self.addCleanup(undo_patch, "UBUNTU_APP_LAUNCH_LINK_FARM",
194 original_ual or "")
195
196 logger.debug("Patched home to fake home directory %s" % temp_dir)
197 return temp_dir131 return temp_dir
198132
199 def _create_music_library(self, test_type):133 def _create_music_library(self):
200 logger.debug("Creating music library for %s test" % test_type)134 logger.debug("Creating music library for %s test" % self.test_type)
201 logger.debug("Home set to %s" % self.home_dir)135 logger.debug("Home set to %s" % self.home_dir)
202 musicpath = os.path.join(self.home_dir, 'Music')136 musicpath = os.path.join(self.home_dir, 'Music')
203 logger.debug("Music path set to %s" % musicpath)137 logger.debug("Music path set to %s" % musicpath)
@@ -217,21 +151,18 @@
217 shutil.copy(os.path.join(content_dir, '1.ogg'), musicpath)151 shutil.copy(os.path.join(content_dir, '1.ogg'), musicpath)
218 shutil.copy(os.path.join(content_dir, '2.ogg'), musicpath)152 shutil.copy(os.path.join(content_dir, '2.ogg'), musicpath)
219 shutil.copy(os.path.join(content_dir, '3.mp3'), musicpath)153 shutil.copy(os.path.join(content_dir, '3.mp3'), musicpath)
220 shutil.copytree(
221 os.path.join(content_dir, 'mediascanner-2.0'), mediascannerpath)
222154
223 logger.debug("Music copied, files " + str(os.listdir(musicpath)))155 logger.debug("Music copied, files " + str(os.listdir(musicpath)))
224156
225 self._patch_mediascanner_home(mediascannerpath)157 if self.test_type is not 'click':
226158 self._patch_mediascanner_home(content_dir, mediascannerpath)
227 logger.debug(159
228 "Mediascanner database copied, files " +160 def _patch_mediascanner_home(self, content_dir, mediascannerpath):
229 str(os.listdir(mediascannerpath)))
230
231 def _patch_mediascanner_home(self, mediascannerpath):
232 # do some inline db patching161 # do some inline db patching
233 # patch mediaindex to proper home162 # patch mediaindex to proper home
234 # these values are dependent upon our sampled db163 # these values are dependent upon our sampled db
164 shutil.copytree(
165 os.path.join(content_dir, 'mediascanner-2.0'), mediascannerpath)
235 logger.debug("Patching fake mediascanner database in %s" %166 logger.debug("Patching fake mediascanner database in %s" %
236 mediascannerpath)167 mediascannerpath)
237 logger.debug(168 logger.debug(
@@ -251,6 +182,10 @@
251 cur.executescript(sql)182 cur.executescript(sql)
252 con.close()183 con.close()
253184
185 logger.debug(
186 "Mediascanner database copied, files " +
187 str(os.listdir(mediascannerpath)))
188
254 def _file_find_replace(self, in_filename, find, replace):189 def _file_find_replace(self, in_filename, find, replace):
255 # replace all occurences of string find with string replace190 # replace all occurences of string find with string replace
256 # in the given file191 # in the given file
@@ -273,5 +208,4 @@
273208
274 def setUp(self):209 def setUp(self):
275 super(MusicAppTestCase, self).setUp()210 super(MusicAppTestCase, self).setUp()
276 launcher_method, _ = self.get_launcher_method_and_type()211 self.app = MusicApp(self.launcher())
277 self.app = MusicApp(launcher_method())

Subscribers

People subscribed via source and target branches