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
1=== modified file 'tests/autopilot/music_app/tests/__init__.py'
2--- tests/autopilot/music_app/tests/__init__.py 2014-09-25 00:39:47 +0000
3+++ tests/autopilot/music_app/tests/__init__.py 2014-11-12 22:01:06 +0000
4@@ -1,9 +1,18 @@
5 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
6-# Copyright 2013, 2014 Canonical
7-#
8-# This program is free software: you can redistribute it and/or modify it
9-# under the terms of the GNU General Public License version 3, as published
10-# by the Free Software Foundation.
11+#
12+# Copyright (C) 2013, 2014 Canonical Ltd
13+#
14+# This program is free software: you can redistribute it and/or modify
15+# it under the terms of the GNU General Public License version 3 as
16+# published by the Free Software Foundation.
17+#
18+# This program is distributed in the hope that it will be useful,
19+# but WITHOUT ANY WARRANTY; without even the implied warranty of
20+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+# GNU General Public License for more details.
22+#
23+# You should have received a copy of the GNU General Public License
24+# along with this program. If not, see <http://www.gnu.org/licenses/>.
25
26 """Music app autopilot tests."""
27
28@@ -18,16 +27,10 @@
29 from music_app import MusicApp
30
31 from autopilot import logging as autopilot_logging
32-from autopilot.input import Mouse, Touch
33-from autopilot.platform import model
34 from autopilot.testcase import AutopilotTestCase
35
36 import ubuntuuitoolkit
37-from ubuntuuitoolkit import (
38- base,
39- fixture_setup as toolkit_fixtures
40-)
41-
42+from ubuntuuitoolkit import base
43
44 logger = logging.getLogger(__name__)
45
46@@ -38,10 +41,6 @@
47 music-app tests.
48
49 """
50- if model() == 'Desktop':
51- scenarios = [('with mouse', dict(input_device_class=Mouse))]
52- else:
53- scenarios = [('with touch', dict(input_device_class=Touch))]
54
55 working_dir = os.getcwd()
56 local_location_dir = os.path.dirname(os.path.dirname(working_dir))
57@@ -62,10 +61,9 @@
58
59 def setUp(self):
60 super(BaseTestCaseWithPatchedHome, self).setUp()
61- _, test_type = self.get_launcher_method_and_type()
62- self.home_dir = self._patch_home(test_type)
63-
64- self._create_music_library(test_type)
65+ self.launcher, self.test_type = self.get_launcher_method_and_type()
66+ self.home_dir = self._patch_home()
67+ self._create_music_library()
68
69 @autopilot_logging.log_action(logger.info)
70 def launch_test_local(self):
71@@ -108,63 +106,17 @@
72 '.Xauthority')),
73 os.path.join(directory, '.Xauthority'))
74
75- def _patch_home(self, test_type):
76+ def _patch_home(self):
77 """ mock /home for testing purposes to preserve user data
78 """
79
80- original_home = os.environ.get('HOME')
81- original_ual = os.environ.get('UBUNTU_APP_LAUNCH_LINK_FARM')
82-
83- # click requires apparmor profile, and writing to special dir
84- # but the desktop can write to a traditional /tmp directory
85- if test_type == 'click':
86- env_dir = os.path.join(os.environ.get('HOME'), 'autopilot',
87- 'fakeenv')
88-
89- if not os.path.exists(env_dir):
90- os.makedirs(env_dir)
91-
92- temp_dir_fixture = fixtures.TempDir(env_dir)
93- self.useFixture(temp_dir_fixture)
94-
95- # apparmor doesn't allow the app to create needed directories,
96- # so we create them now
97- temp_dir = temp_dir_fixture.path
98- temp_dir_cache = os.path.join(temp_dir, '.cache')
99- temp_dir_cache_font = os.path.join(temp_dir_cache, 'fontconfig')
100- temp_dir_cache_media = os.path.join(temp_dir_cache, 'media-art')
101- temp_dir_cache_write = os.path.join(temp_dir_cache,
102- 'tncache-write-text.null')
103- temp_dir_config = os.path.join(temp_dir, '.config')
104- temp_dir_toolkit = os.path.join(temp_dir_config,
105- 'ubuntu-ui-toolkit')
106- temp_dir_font = os.path.join(temp_dir_cache, '.fontconfig')
107- temp_dir_local = os.path.join(temp_dir, '.local', 'share')
108- temp_dir_confined = os.path.join(temp_dir, 'confined')
109-
110- if not os.path.exists(temp_dir_cache):
111- os.makedirs(temp_dir_cache)
112- if not os.path.exists(temp_dir_cache_font):
113- os.makedirs(temp_dir_cache_font)
114- if not os.path.exists(temp_dir_cache_media):
115- os.makedirs(temp_dir_cache_media)
116- if not os.path.exists(temp_dir_cache_write):
117- os.makedirs(temp_dir_cache_write)
118- if not os.path.exists(temp_dir_config):
119- os.makedirs(temp_dir_config)
120- if not os.path.exists(temp_dir_toolkit):
121- os.makedirs(temp_dir_toolkit)
122- if not os.path.exists(temp_dir_font):
123- os.makedirs(temp_dir_font)
124- if not os.path.exists(temp_dir_local):
125- os.makedirs(temp_dir_local)
126- if not os.path.exists(temp_dir_confined):
127- os.makedirs(temp_dir_confined)
128-
129- # before we set fixture, copy xauthority if needed
130- self._copy_xauthority_file(temp_dir)
131- self.useFixture(toolkit_fixtures.InitctlEnvironmentVariable(
132- HOME=temp_dir))
133+ # if running on non-phablet device,
134+ # run in temp folder to avoid mucking up home
135+ # bug 1316746
136+ # bug 1376423
137+ if self.test_type is 'click':
138+ # just use home for now on devices
139+ temp_dir = os.environ.get('HOME')
140 else:
141 temp_dir_fixture = fixtures.TempDir()
142 self.useFixture(temp_dir_fixture)
143@@ -175,29 +127,11 @@
144 self.useFixture(fixtures.EnvironmentVariable('HOME',
145 newvalue=temp_dir))
146
147- def undo_patch(key, value):
148- logging.info(
149- "Resetting environment variable '%s' to '%s'",
150- key,
151- value
152- )
153-
154- os.environ[key] = value
155-
156- # TODO: Remove code once pad.lv/1370800 is fixed
157- os.environ["HOME"] = temp_dir
158- os.environ["UBUNTU_APP_LAUNCH_LINK_FARM"] = original_home + "/.cache" \
159- "/ubuntu-app-launch/desktop"
160-
161- self.addCleanup(undo_patch, "HOME", original_home)
162- self.addCleanup(undo_patch, "UBUNTU_APP_LAUNCH_LINK_FARM",
163- original_ual or "")
164-
165- logger.debug("Patched home to fake home directory %s" % temp_dir)
166+ logger.debug("Patched home to fake home directory %s" % temp_dir)
167 return temp_dir
168
169- def _create_music_library(self, test_type):
170- logger.debug("Creating music library for %s test" % test_type)
171+ def _create_music_library(self):
172+ logger.debug("Creating music library for %s test" % self.test_type)
173 logger.debug("Home set to %s" % self.home_dir)
174 musicpath = os.path.join(self.home_dir, 'Music')
175 logger.debug("Music path set to %s" % musicpath)
176@@ -217,21 +151,18 @@
177 shutil.copy(os.path.join(content_dir, '1.ogg'), musicpath)
178 shutil.copy(os.path.join(content_dir, '2.ogg'), musicpath)
179 shutil.copy(os.path.join(content_dir, '3.mp3'), musicpath)
180- shutil.copytree(
181- os.path.join(content_dir, 'mediascanner-2.0'), mediascannerpath)
182
183 logger.debug("Music copied, files " + str(os.listdir(musicpath)))
184
185- self._patch_mediascanner_home(mediascannerpath)
186-
187- logger.debug(
188- "Mediascanner database copied, files " +
189- str(os.listdir(mediascannerpath)))
190-
191- def _patch_mediascanner_home(self, mediascannerpath):
192+ if self.test_type is not 'click':
193+ self._patch_mediascanner_home(content_dir, mediascannerpath)
194+
195+ def _patch_mediascanner_home(self, content_dir, mediascannerpath):
196 # do some inline db patching
197 # patch mediaindex to proper home
198 # these values are dependent upon our sampled db
199+ shutil.copytree(
200+ os.path.join(content_dir, 'mediascanner-2.0'), mediascannerpath)
201 logger.debug("Patching fake mediascanner database in %s" %
202 mediascannerpath)
203 logger.debug(
204@@ -251,6 +182,10 @@
205 cur.executescript(sql)
206 con.close()
207
208+ logger.debug(
209+ "Mediascanner database copied, files " +
210+ str(os.listdir(mediascannerpath)))
211+
212 def _file_find_replace(self, in_filename, find, replace):
213 # replace all occurences of string find with string replace
214 # in the given file
215@@ -273,5 +208,4 @@
216
217 def setUp(self):
218 super(MusicAppTestCase, self).setUp()
219- launcher_method, _ = self.get_launcher_method_and_type()
220- self.app = MusicApp(launcher_method())
221+ self.app = MusicApp(self.launcher())

Subscribers

People subscribed via source and target branches