36
34
class TestFolderListPage(FileManagerTestCase):
38
def _make_file_in_home(self):
39
return self._make_content_in_home('file')
41
def _make_content_in_home(self, type_):
42
if type_ != 'file' and type_ != 'directory':
43
raise ValueError('Unknown content type: "{0}"', type_)
45
_, path = tempfile.mkstemp(prefix='tmpfm',
47
#path = self.home_dir + "/tmpfmFile"
48
#os.system("touch " + path)
49
logger.debug("Created %s, a file in HOME" % path)
50
self.addCleanup(self._unlink_cleanup, path)
52
path = tempfile.mkdtemp(prefix='tmpfm', dir=self.home_dir)
53
#path = self.home_dir + "/tmpfmDir"
54
#os.system("mkdir " + path)
55
logger.debug("Created %s, a directory in HOME" % path)
56
self.addCleanup(self._rmdir_cleanup, path)
58
logger.debug("Directory Listing for HOME\n%s" %
59
os.listdir(self.home_dir))
60
self._assert_number_of_files(1)
63
def _assert_number_of_files(self, expected_number_of_files, home=True):
65
expected_number_of_files += self.original_file_count
66
folder_list_page = self.main_view.get_folder_list_page()
68
folder_list_page.get_number_of_files_from_list,
69
Eventually(Equals(expected_number_of_files), timeout=60))
71
folder_list_page.get_number_of_files_from_header,
72
Eventually(Equals(expected_number_of_files), timeout=60))
74
36
def _get_file_by_name(self, name):
75
37
folder_list_page = self.main_view.get_folder_list_page()
76
38
fileDelegate = lambda: folder_list_page.get_file_by_name(name)
104
66
goto_location.enter_text(location)
105
67
goto_location.ok()
107
def _make_directory_in_home(self):
108
return self._make_content_in_home('directory')
110
69
def _open_directory(self, item):
111
70
expected_path = item.filePath
112
71
list_view = item.list_view
155
114
confirm_dialog.enter_text(text)
156
115
confirm_dialog.ok()
158
def _unlink_cleanup(self, filename):
159
logger.debug("Cleanup; checking to remove %s file" % filename)
160
if os.path.exists(filename):
161
logger.debug("Removing %s file" % filename)
164
def _rmdir_cleanup(self, directory):
165
logger.debug("Cleanup; checking to remove %s directory" % directory)
166
if os.path.exists(directory):
167
logger.debug("Removing %s directory" % directory)
168
shutil.rmtree(directory)
170
117
# We can't do this testcase on phablet devices because of a lack of
171
118
# Mir backend in autopilot
172
119
# see https://bugs.launchpad.net/autopilot/+bug/1209004
173
120
@unittest.skip("Can't do this properly on desktop or phablet")
174
121
def test_open_file(self):
175
self._make_file_in_home()
122
self.make_file_in_home()
177
124
first_file = self._get_file_by_index(0)
178
125
self.pointing_device.click_object(first_file)
205
152
window = new_app.get_windows()[0]
208
def test_rename_directory(self):
209
orig_dir = os.path.basename(self._make_directory_in_home())
210
new_name = 'Renamed directory'
211
self.addCleanup(self._rmdir_cleanup,
212
os.path.join(self.home_dir, new_name))
214
first_dir = self._get_file_by_name(orig_dir)
215
self._do_action_on_file(first_dir, action='Rename')
216
self._confirm_dialog(new_name)
219
self.main_view.confirm_dialog_exists, Eventually(Equals(False)))
220
self.assertThat(self._get_file_by_index(0).fileName,
221
Eventually(Equals(new_name)))
223
155
def test_open_directory(self):
224
dir_path = self._make_directory_in_home()
156
dir_path = self.make_directory_in_home()
225
157
first_dir = self._get_file_by_name(os.path.basename(dir_path))
227
159
self._open_directory(first_dir)
233
165
# TODO check the label that says the directory is empty.
234
166
# --elopio - 2013-07-25
236
def test_folder_context_menu_shows(self):
237
"""Checks to make sure that the folder actions popover is shown."""
238
dir_path = os.path.basename(self._make_directory_in_home())
240
first_file = self._get_file_by_name(dir_path)
241
self._safe_open_popover(first_file.open_actions_popover)
243
file_actions_popover = self.main_view.get_file_actions_popover()
245
lambda: file_actions_popover.visible, Eventually(Equals(True)))
247
168
def test_list_folder_contents(self):
248
dir_path = self._make_directory_in_home()
169
dir_path = self.make_directory_in_home()
249
170
dir_name = os.path.basename(dir_path)
250
file_path = self._make_file_in_home()
171
file_path = self.make_file_in_home()
251
172
file_name = os.path.basename(file_path)
253
174
self._assert_number_of_files(2)
259
180
self.assertThat(file_.fileName, Eventually(Equals(file_name)))
261
182
def test_cancel_rename_directory(self):
262
dir_path = self._make_directory_in_home()
183
dir_path = self.make_directory_in_home()
263
184
dir_name = os.path.basename(dir_path)
265
186
first_dir = self._get_file_by_name(dir_name)
272
193
lambda: first_dir.fileName, Eventually(Equals(dir_name)))
274
195
def test_cancel_rename_file(self):
275
file_path = self._make_file_in_home()
196
file_path = self.make_file_in_home()
276
197
file_name = os.path.basename(file_path)
278
199
first_file = self._get_file_by_name(file_name)
285
206
lambda: first_file.fileName,
286
207
Eventually(Equals(file_name)))
288
def test_rename_file(self):
289
file_name = os.path.basename(self._make_file_in_home())
290
new_name = 'Renamed file'
291
self.addCleanup(self._unlink_cleanup, new_name)
293
first_file = self._get_file_by_name(file_name)
294
self._do_action_on_file(first_file, action='Rename')
295
self._confirm_dialog(new_name)
298
self.main_view.confirm_dialog_exists, Eventually(Equals(False)))
299
self.assertThat(self._get_file_by_index(0).fileName,
300
Eventually(Equals(new_name)))
302
209
def test_cancel_delete_directory(self):
303
dir_name = os.path.basename(self._make_directory_in_home())
210
dir_name = os.path.basename(self.make_directory_in_home())
304
211
first_dir = self._get_file_by_name(dir_name)
306
213
self._do_action_on_file(first_dir, 'Delete')
309
216
self._assert_number_of_files(1)
311
def test_delete_directory(self):
312
dir_name = os.path.basename(self._make_directory_in_home())
313
first_dir = self._get_file_by_name(dir_name)
315
self._do_action_on_file(first_dir, 'Delete')
316
self._confirm_dialog()
318
self._assert_number_of_files(0)
320
218
def test_cancel_delete_file(self):
321
file_name = os.path.basename(self._make_file_in_home())
219
file_name = os.path.basename(self.make_file_in_home())
322
220
first_file = self._get_file_by_name(file_name)
324
222
self._do_action_on_file(first_file, 'Delete')
327
225
self._assert_number_of_files(1)
329
def test_delete_file(self):
330
file_name = os.path.basename(self._make_file_in_home())
331
first_file = self._get_file_by_name(file_name)
333
self._do_action_on_file(first_file, 'Delete')
334
self._confirm_dialog()
336
self._assert_number_of_files(0)
338
227
def test_create_directory(self):
339
228
dir_name = 'Test Directory'
340
self.addCleanup(self._rmdir_cleanup,
341
os.path.join(self.home_dir, dir_name))
343
230
open_popover = lambda: \
344
231
self.main_view.open_toolbar().click_button('actions')
365
252
self._assert_number_of_files(0)
367
254
def test_show_directory_properties_from_list(self):
368
dir_path = self._make_directory_in_home()
255
dir_path = self.make_directory_in_home()
369
256
dir_name = os.path.basename(dir_path)
370
257
first_dir = self._get_file_by_name(dir_name)
379
266
# --elopio - 2013-07-25
381
268
def test_show_file_properties(self):
382
file_path = self._make_file_in_home()
269
file_path = self.make_file_in_home()
383
270
file_name = os.path.basename(file_path)
384
271
first_file = self._get_file_by_name(file_name)
397
284
destination_dir_name = os.path.basename(destination_dir_path)
398
285
os.mkdir(destination_dir_path)
399
self.addCleanup(self._rmdir_cleanup, destination_dir_path)
400
286
dir_to_copy_path = os.path.join(self.home_dir, 'to_copy')
401
287
dir_to_copy_name = os.path.basename(dir_to_copy_path)
402
288
os.mkdir(dir_to_copy_path)
403
self.addCleanup(self._rmdir_cleanup, dir_to_copy_path)
405
290
folder_list_page = self.main_view.get_folder_list_page()
406
291
self._assert_number_of_files(2)
445
330
destination_dir_name = os.path.basename(destination_dir_path)
446
331
os.mkdir(destination_dir_path)
447
self.addCleanup(self._rmdir_cleanup, destination_dir_path)
448
332
dir_to_cut_path = os.path.join(self.home_dir, 'to_cut')
449
333
dir_to_cut_name = os.path.basename(dir_to_cut_path)
450
334
os.mkdir(dir_to_cut_path)
451
self.addCleanup(self._rmdir_cleanup, dir_to_cut_path)
453
336
folder_list_page = self.main_view.get_folder_list_page()
454
337
self._assert_number_of_files(2)
492
375
def test_copy_file(self):
493
376
# Set up a file to copy and a directory to copy it into.
494
destination_dir_path = self._make_directory_in_home()
377
destination_dir_path = self.make_directory_in_home()
495
378
destination_dir_name = os.path.basename(destination_dir_path)
496
file_to_copy_path = self._make_file_in_home()
379
file_to_copy_path = self.make_file_in_home()
497
380
file_to_copy_name = os.path.basename(file_to_copy_path)
499
382
folder_list_page = self.main_view.get_folder_list_page()
539
422
def test_cut_file(self):
540
423
# Set up a file to cut and a directory to move it into.
541
destination_dir_path = self._make_directory_in_home()
424
destination_dir_path = self.make_directory_in_home()
542
425
destination_dir_name = os.path.basename(destination_dir_path)
543
file_to_cut_path = self._make_file_in_home()
426
file_to_cut_path = self.make_file_in_home()
544
427
file_to_cut_name = os.path.basename(file_to_cut_path)
546
429
folder_list_page = self.main_view.get_folder_list_page()
583
466
first_dir.fileName, Eventually(Equals(destination_dir_name)))
585
468
def test_go_up(self):
586
dir_name = os.path.basename(self._make_directory_in_home())
469
dir_name = os.path.basename(self.make_directory_in_home())
587
470
first_dir = self._get_file_by_name(dir_name)
588
471
self._open_directory(first_dir)
595
478
folder_list_page.get_current_path,
596
479
Eventually(Equals(self.home_dir)))
598
def test_file_context_menu_shows(self):
599
"""Checks to make sure that the file actions popover is shown."""
600
file_name = os.path.basename(self._make_file_in_home())
602
first_file = self._get_file_by_name(file_name)
603
self._safe_open_popover(first_file.open_actions_popover)
605
file_actions_popover = self.main_view.get_file_actions_popover()
607
lambda: file_actions_popover.visible, Eventually(Equals(True)))