20
23
'''Set-up method'''
21
24
super(FileRollerTests, self).setUp()
25
#mock out the home dir
26
self.home_dir = self._patch_home()
22
29
self.app = self.launch_test_application('file-roller')
24
31
# only instantiate these once for multiple tests
40
47
#create symbolic link for fast test content location
41
link_loc = os.getenv("HOME") + '/__000'
42
link_cmd = 'ln -s /usr/share/example-content '
43
p = subprocess.Popen(link_cmd + link_loc, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
44
self.assertThat(p.wait(), Equals(0))
45
self.addCleanup(os.remove, link_loc)
48
src_dir = '/usr/share/example-content/Ubuntu_Free_Culture_Showcase/'
49
files = os.listdir(src_dir)
51
shutil.copyfile(src_dir + str(f), os.getenv("HOME") + '/' + str(f))
47
53
def test_create_archive(self):
48
54
'''Creates an archive and adds sample data,
129
135
self.add_files_dialog = self.app.select_single('FrFileSelectorDialog')
130
136
self.assertThat(self.add_files_dialog.title,
131
137
Eventually(Equals('Add Files')))
133
138
# This is a horrible hacky workaround to add sample
134
139
# files from /usr/share/example-content/*
135
140
# Need to find a better workaround :S Location GtkEntry
141
146
self.keyboard.press_and_release("Alt+l")
142
147
self.keyboard.press_and_release("Tab")
143
148
self.keyboard.press_and_release("Tab")
144
for x in range(0, 10):
145
self.keyboard.press_and_release("Up")
147
self.keyboard.press_and_release("Down")
148
self.keyboard.press_and_release("Enter")
150
#then select the sample content link
151
self.keyboard.press_and_release("Alt+l")
152
self.keyboard.press_and_release("Tab")
153
self.keyboard.press_and_release("Tab")
154
self.keyboard.press_and_release("Tab")
155
self.keyboard.press_and_release("Right")
156
self.keyboard.press_and_release("Enter")
157
self.keyboard.press_and_release("Left")
158
self.keyboard.press_and_release("Enter")
149
self.keyboard.press_and_release("Tab")
151
self.keyboard.press_and_release("Space")
152
self.keyboard.press_and_release("Down")
153
self.keyboard.press_and_release("Down")
154
self.keyboard.press_and_release("Space")
160
156
# We must be able to click the '_Add' button
161
157
self.add_folder_button = self.app.select_single('GtkLabel',
202
198
self.keyboard.press_and_release("Alt+l")
203
199
self.keyboard.type(tempArchive)
200
self.keyboard.press_and_release('Enter')
205
202
self.extract_archive_button = self.app.select_single(
206
203
'GtkLabel', label=u'_Extract')
226
223
#check the files have actually been extracted
227
224
self.assertThat(tempArchive, DirExists())
228
srcdir = '/Ubuntu_Free_Culture_Showcase'
229
self.assertThat(tempArchive + srcdir, DirExists())
230
self.assertThat(tempArchive + srcdir + '/How fast.ogg', FileExists())
231
self.assertThat(tempArchive + srcdir + '/Josh Woodward - Swansong.ogg', FileExists())
225
self.assertThat(tempArchive + '/' + '/How fast.ogg', FileExists())
226
self.assertThat(tempArchive + '/' + '/Josh Woodward - Swansong.ogg', FileExists())
233
228
# This sleep is needed as we can't introspect
234
229
# nautilus when it shows the files
277
272
extract_path = os.path.join('/tmp/' + fileName)
278
273
self.addCleanup(shutil.rmtree, extract_path)
275
def _save_home(self):
276
logger.debug('Saving HOME')
277
home_dir = os.environ['HOME']
278
backup_list = ('Music', ) # '.cache/mediascanner')
279
backup_path = [os.path.join(home_dir, i) for i in backup_list]
280
backups = [(i, '%s.bak' % i) for i in backup_path if os.path.exists(i)]
282
logger.debug('backing up %s to %s' % b)
287
shutil.move(b[0], b[1])
288
#self.addCleanup(shutil.move(b[1], b[0]))
291
def _patch_home(self):
293
temp_dir = tempfile.mkdtemp()
294
#delete it, and recreate it to the length
295
#required so our patching the db works
296
#require a length of 25
297
shutil.rmtree(temp_dir)
298
temp_dir = temp_dir.ljust(25, 'X')
300
logger.debug("Created fake home directory " + temp_dir)
301
self.addCleanup(shutil.rmtree, temp_dir)
302
#if the Xauthority file is in home directory
303
#make sure we copy it to temp home, otherwise do nothing
304
xauth = os.path.expanduser(os.path.join('~', '.Xauthority'))
305
if os.path.isfile(xauth):
306
logger.debug("Copying .Xauthority to fake home " + temp_dir)
308
os.path.expanduser(os.path.join('~', '.Xauthority')),
309
os.path.join(temp_dir, '.Xauthority'))
310
patcher = mock.patch.dict('os.environ', {'HOME': temp_dir})
312
logger.debug("Patched home to fake home directory " + temp_dir)
313
self.addCleanup(patcher.stop)
281
317
#hardcoded global archiveName
282
318
def _tempArchiveName():