35
35
logger = logging.getLogger(__name__)
38
class BaseTestCaseWithPatchedHome(AutopilotTestCase):
38
class BaseTestClassWithPatchedHome(AutopilotTestCase):
40
39
"""A common test case class that provides several useful methods for
45
42
working_dir = os.getcwd()
46
43
local_location_dir = os.path.dirname(os.path.dirname(working_dir))
59
56
test_type = 'click'
60
57
return launch, test_type
63
super(BaseTestCaseWithPatchedHome, self).setUp()
64
self.launcher, self.test_type = self.get_launcher_method_and_type()
65
self.home_dir = self._patch_home()
66
self._create_music_library()
68
59
@autopilot_logging.log_action(logger.info)
69
60
def launch_test_local(self):
70
61
return self.launch_test_application(
90
81
emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
92
83
def _copy_xauthority_file(self, directory):
93
""" Copy .Xauthority file to directory, if it exists in /home
84
""" Copy .Xauthority file to directory, if it exists in /home"""
95
86
# If running under xvfb, as jenkins does,
96
87
# xsession will fail to start without xauthority file
97
88
# Thus if the Xauthority file is in the home directory
107
98
os.path.join(directory, '.Xauthority'))
109
100
def _patch_home(self):
110
""" mock /home for testing purposes to preserve user data
101
""" mock /home for testing purposes to preserve user data"""
113
103
# if running on non-phablet device,
114
104
# run in temp folder to avoid mucking up home
141
131
logger.debug("Patched home to fake home directory %s" % temp_dir)
144
def _create_music_library(self):
134
def _create_music_library(self, db_dir):
145
135
logger.debug("Creating music library for %s test" % self.test_type)
146
136
logger.debug("Home set to %s" % self.home_dir)
147
137
musicpath = os.path.join(self.home_dir, 'Music')
148
138
logger.debug("Music path set to %s" % musicpath)
149
139
mediascannerpath = os.path.join(self.home_dir,
150
140
'.cache/mediascanner-2.0')
141
logger.debug("Mediascanner path set to %s" % mediascannerpath)
151
143
if not os.path.exists(musicpath):
152
144
os.makedirs(musicpath)
153
logger.debug("Mediascanner path set to %s" % mediascannerpath)
155
146
# set content path
156
147
content_dir = os.path.join(os.path.dirname(music_app.__file__),
149
songs_dir = os.path.join(content_dir, 'songs')
159
150
logger.debug("Content dir set to %s" % content_dir)
162
shutil.copy(os.path.join(content_dir, '1.ogg'), musicpath)
163
shutil.copy(os.path.join(content_dir, '2.ogg'), musicpath)
164
shutil.copy(os.path.join(content_dir, '3.mp3'), musicpath)
166
logger.debug("Music copied, files " + str(os.listdir(musicpath)))
153
if os.path.isdir(songs_dir) and db_dir == 'mediascanner-2.0':
154
shutil.copy(os.path.join(songs_dir, '1.ogg'), musicpath)
155
shutil.copy(os.path.join(songs_dir, '2.ogg'), musicpath)
156
shutil.copy(os.path.join(songs_dir, '3.mp3'), musicpath)
158
logger.debug("Music copied, files " + str(os.listdir(musicpath)))
159
# delete content if previously copied
160
elif not os.path.isdir(songs_dir):
162
os.remove(os.path.join(musicpath, '1.ogg'))
164
logger.debug("Error removing" + str(e))
166
os.remove(os.path.join(musicpath, '2.ogg'))
168
logger.debug("Error removing" + str(e))
170
os.remove(os.path.join(musicpath, '3.mp3'))
172
logger.debug("Error removing" + str(e))
174
logger.debug("Music deleted, files " + str(os.listdir(musicpath)))
168
176
if self.test_type is not 'click':
169
177
self._patch_mediascanner_home(content_dir, mediascannerpath)
172
180
# do some inline db patching
173
181
# patch mediaindex to proper home
174
182
# these values are dependent upon our sampled db
176
os.path.join(content_dir, 'mediascanner-2.0'), mediascannerpath)
183
shutil.copytree(content_dir, mediascannerpath)
177
185
logger.debug("Patching fake mediascanner database in %s" %
178
186
mediascannerpath)
213
227
os.rename(out_filename, in_filename)
230
class BaseTestCaseWithPatchedHome(BaseTestClassWithPatchedHome):
232
""" Base test case class for music-app, with viable audio files loaded."""
235
super(BaseTestClassWithPatchedHome, self).setUp()
236
self.launcher, self.test_type = self.get_launcher_method_and_type()
237
self.home_dir = self._patch_home()
238
self._create_music_library('mediascanner-2.0')
241
class EmptyLibraryWithPatchedHome(BaseTestClassWithPatchedHome):
243
""" Base test case class for music-app with empty library. """
246
super(BaseTestClassWithPatchedHome, self).setUp()
247
self.launcher, self.test_type = self.get_launcher_method_and_type()
248
self.home_dir = self._patch_home()
249
self._create_music_library('blank-mediascanner-2.0')
216
252
class MusicAppTestCase(BaseTestCaseWithPatchedHome):
218
254
"""Base test case that launches the music-app."""
221
257
super(MusicAppTestCase, self).setUp()
222
258
self.app = MusicApp(self.launcher())
261
class MusicAppTestCaseEmptyLibrary(EmptyLibraryWithPatchedHome):
263
"""Test case that launches the music-app with no music:
267
super(MusicAppTestCaseEmptyLibrary, self).setUp()
268
self.app = MusicApp(self.launcher())