~popey/ubuntu-filemanager-app/refix-1336764

« back to all changes in this revision

Viewing changes to tests/autopilot/filemanager/tests/test_filemanager.py

Refactored the first group of context menu tests.

Approved by Nicholas Skaggs, Ubuntu Phone Apps Jenkins Bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""File Manager app autopilot tests."""
18
18
 
19
 
import tempfile
20
19
import unittest
21
20
import logging
22
21
 
23
22
import os
24
 
import shutil
25
23
 
26
24
from autopilot import process
27
25
from autopilot.platform import model
35
33
 
36
34
class TestFolderListPage(FileManagerTestCase):
37
35
 
38
 
    def _make_file_in_home(self):
39
 
        return self._make_content_in_home('file')
40
 
 
41
 
    def _make_content_in_home(self, type_):
42
 
        if type_ != 'file' and type_ != 'directory':
43
 
            raise ValueError('Unknown content type: "{0}"', type_)
44
 
        if type_ == 'file':
45
 
            _, path = tempfile.mkstemp(prefix='tmpfm',
46
 
                                       dir=self.home_dir)
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)
51
 
        else:
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)
57
 
 
58
 
        logger.debug("Directory Listing for HOME\n%s" %
59
 
                     os.listdir(self.home_dir))
60
 
        self._assert_number_of_files(1)
61
 
        return path
62
 
 
63
 
    def _assert_number_of_files(self, expected_number_of_files, home=True):
64
 
        if home:
65
 
            expected_number_of_files += self.original_file_count
66
 
        folder_list_page = self.main_view.get_folder_list_page()
67
 
        self.assertThat(
68
 
            folder_list_page.get_number_of_files_from_list,
69
 
            Eventually(Equals(expected_number_of_files), timeout=60))
70
 
        self.assertThat(
71
 
            folder_list_page.get_number_of_files_from_header,
72
 
            Eventually(Equals(expected_number_of_files), timeout=60))
73
 
 
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()
106
68
 
107
 
    def _make_directory_in_home(self):
108
 
        return self._make_content_in_home('directory')
109
 
 
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()
157
116
 
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)
162
 
            os.unlink(filename)
163
 
 
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)
169
 
 
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()
176
123
 
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]
206
153
        window.close()
207
154
 
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))
213
 
 
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)
217
 
 
218
 
        self.assertThat(
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)))
222
 
 
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))
226
158
 
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
235
167
 
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())
239
 
 
240
 
        first_file = self._get_file_by_name(dir_path)
241
 
        self._safe_open_popover(first_file.open_actions_popover)
242
 
 
243
 
        file_actions_popover = self.main_view.get_file_actions_popover()
244
 
        self.assertThat(
245
 
            lambda: file_actions_popover.visible, Eventually(Equals(True)))
246
 
 
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)
252
173
 
253
174
        self._assert_number_of_files(2)
259
180
        self.assertThat(file_.fileName, Eventually(Equals(file_name)))
260
181
 
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)
264
185
 
265
186
        first_dir = self._get_file_by_name(dir_name)
272
193
            lambda: first_dir.fileName, Eventually(Equals(dir_name)))
273
194
 
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)
277
198
 
278
199
        first_file = self._get_file_by_name(file_name)
285
206
            lambda: first_file.fileName,
286
207
            Eventually(Equals(file_name)))
287
208
 
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)
292
 
 
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)
296
 
 
297
 
        self.assertThat(
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)))
301
 
 
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)
305
212
 
306
213
        self._do_action_on_file(first_dir, 'Delete')
308
215
 
309
216
        self._assert_number_of_files(1)
310
217
 
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)
314
 
 
315
 
        self._do_action_on_file(first_dir, 'Delete')
316
 
        self._confirm_dialog()
317
 
 
318
 
        self._assert_number_of_files(0)
319
 
 
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)
323
221
 
324
222
        self._do_action_on_file(first_file, 'Delete')
326
224
 
327
225
        self._assert_number_of_files(1)
328
226
 
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)
332
 
 
333
 
        self._do_action_on_file(first_file, 'Delete')
334
 
        self._confirm_dialog()
335
 
 
336
 
        self._assert_number_of_files(0)
337
 
 
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))
342
229
 
343
230
        open_popover = lambda: \
344
231
            self.main_view.open_toolbar().click_button('actions')
365
252
        self._assert_number_of_files(0)
366
253
 
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)
371
258
 
379
266
        # --elopio - 2013-07-25
380
267
 
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)
385
272
 
396
283
                                            'destination')
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)
404
289
 
405
290
        folder_list_page = self.main_view.get_folder_list_page()
406
291
        self._assert_number_of_files(2)
444
329
                                            'destination')
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)
452
335
 
453
336
        folder_list_page = self.main_view.get_folder_list_page()
454
337
        self._assert_number_of_files(2)
491
374
 
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)
498
381
 
499
382
        folder_list_page = self.main_view.get_folder_list_page()
538
421
 
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)
545
428
 
546
429
        folder_list_page = self.main_view.get_folder_list_page()
583
466
            first_dir.fileName, Eventually(Equals(destination_dir_name)))
584
467
 
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)
589
472
 
594
477
        self.assertThat(
595
478
            folder_list_page.get_current_path,
596
479
            Eventually(Equals(self.home_dir)))
597
 
 
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())
601
 
 
602
 
        first_file = self._get_file_by_name(file_name)
603
 
        self._safe_open_popover(first_file.open_actions_popover)
604
 
 
605
 
        file_actions_popover = self.main_view.get_file_actions_popover()
606
 
        self.assertThat(
607
 
            lambda: file_actions_popover.visible, Eventually(Equals(True)))