Merge lp:~sergiusens/ubuntu-filemanager-app/fix_ap into lp:ubuntu-filemanager-app
- fix_ap
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Francis Ginther |
Approved revision: | 80 |
Merged at revision: | 79 |
Proposed branch: | lp:~sergiusens/ubuntu-filemanager-app/fix_ap |
Merge into: | lp:ubuntu-filemanager-app |
Diff against target: |
444 lines (+110/-63) 4 files modified
plugins.json (+6/-0) tests/autopilot/ubuntu_filemanager_app/tests/__init__.py (+37/-6) tests/autopilot/ubuntu_filemanager_app/tests/test_filemanager.py (+66/-56) ubuntu-filemanager-app.qml (+1/-1) |
To merge this branch: | bzr merge lp:~sergiusens/ubuntu-filemanager-app/fix_ap |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu Phone Apps Jenkins Bot | continuous-integration | Approve | |
Loïc Minier (community) | Approve | ||
Review via email: mp+191051@code.launchpad.net |
Commit message
Making tests use real home when testing under click.
Description of the change
I'm adding a hug TODO for myslef to clean up these tests to avoid the code duplication
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
PASSED: Continuous integration, rev:80
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Loïc Minier (lool) wrote : | # |
LGTM! Great to see the tests passing
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
FAILED: Autolanding.
More details in the following jenkins job:
http://
Executed test runs:
UNSTABLE: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) : | # |
Preview Diff
1 | === added file 'plugins.json' |
2 | --- plugins.json 1970-01-01 00:00:00 +0000 |
3 | +++ plugins.json 2013-10-14 20:58:22 +0000 |
4 | @@ -0,0 +1,6 @@ |
5 | +[ |
6 | +{ |
7 | + "package": "qtdeclarative5-nemo-qml-plugin-folderlistmodel", |
8 | + "ppa": "ppa:ubuntu-touch-coreapps-drivers/daily" |
9 | +} |
10 | +] |
11 | |
12 | === modified file 'tests/autopilot/ubuntu_filemanager_app/tests/__init__.py' |
13 | --- tests/autopilot/ubuntu_filemanager_app/tests/__init__.py 2013-10-04 17:25:56 +0000 |
14 | +++ tests/autopilot/ubuntu_filemanager_app/tests/__init__.py 2013-10-14 20:58:22 +0000 |
15 | @@ -7,7 +7,10 @@ |
16 | |
17 | """Filemanager app autopilot tests.""" |
18 | |
19 | +import mock |
20 | import os.path |
21 | +import shutil |
22 | +import tempfile |
23 | |
24 | from autopilot.input import Mouse, Touch, Pointer |
25 | from autopilot.platform import model |
26 | @@ -32,15 +35,43 @@ |
27 | installed_location = "/usr/share/ubuntu-filemanager-app/" \ |
28 | "ubuntu-filemanager-app.qml" |
29 | |
30 | + def setup_environment(self): |
31 | + if os.path.exists(self.local_location): |
32 | + launch = self.launch_test_local |
33 | + test_type = 'local' |
34 | + elif os.path.exists(self.installed_location): |
35 | + launch = self.launch_test_installed |
36 | + test_type = 'deb' |
37 | + else: |
38 | + launch = self.launch_test_click |
39 | + test_type = 'click' |
40 | + return launch, test_type |
41 | + |
42 | def setUp(self): |
43 | + launch, self.test_type = self.setup_environment() |
44 | + if self.test_type != 'click': |
45 | + self._patch_home() |
46 | self.pointing_device = Pointer(self.input_device_class.create()) |
47 | super(FileManagerTestCase, self).setUp() |
48 | - if os.path.exists(self.local_location): |
49 | - self.launch_test_local() |
50 | - elif os.path.exists(self.installed_location): |
51 | - self.launch_test_installed() |
52 | - else: |
53 | - self.launch_test_click() |
54 | + self.original_file_count = \ |
55 | + len([i for i in os.listdir(os.environ['HOME']) |
56 | + if not i.startswith('.')]) |
57 | + launch() |
58 | + |
59 | + def _patch_home(self): |
60 | + #create a temporary home for testing purposes |
61 | + temp_dir = tempfile.mkdtemp() |
62 | + #if the Xauthority file is in home directory |
63 | + #make sure we copy it to temp home, otherwise do nothing |
64 | + xauth = os.path.expanduser(os.path.join('~', '.Xauthority')) |
65 | + if os.path.isfile(xauth): |
66 | + shutil.copyfile( |
67 | + os.path.expanduser(os.path.join('~', '.Xauthority')), |
68 | + os.path.join(temp_dir, '.Xauthority')) |
69 | + self.addCleanup(shutil.rmtree, temp_dir) |
70 | + patcher = mock.patch.dict('os.environ', {'HOME': temp_dir}) |
71 | + patcher.start() |
72 | + self.addCleanup(patcher.stop) |
73 | |
74 | def launch_test_local(self): |
75 | self.app = self.launch_test_application( |
76 | |
77 | === modified file 'tests/autopilot/ubuntu_filemanager_app/tests/test_filemanager.py' |
78 | --- tests/autopilot/ubuntu_filemanager_app/tests/test_filemanager.py 2013-09-09 21:34:54 +0000 |
79 | +++ tests/autopilot/ubuntu_filemanager_app/tests/test_filemanager.py 2013-10-14 20:58:22 +0000 |
80 | @@ -21,7 +21,6 @@ |
81 | import tempfile |
82 | import unittest |
83 | |
84 | -import mock |
85 | import os |
86 | import shutil |
87 | |
88 | @@ -36,44 +35,29 @@ |
89 | class TestFolderListPage(FileManagerTestCase): |
90 | |
91 | def setUp(self): |
92 | - self._patch_home() |
93 | super(TestFolderListPage, self).setUp() |
94 | self.assertThat( |
95 | self.main_view.visible, Eventually(Equals(True))) |
96 | |
97 | - def _patch_home(self): |
98 | - #create a temporary home for testing purposes |
99 | - temp_dir = tempfile.mkdtemp() |
100 | - #if the Xauthority file is in home directory |
101 | - #make sure we copy it to temp home, otherwise do nothing |
102 | - xauth = os.path.expanduser(os.path.join('~', '.Xauthority')) |
103 | - if os.path.isfile(xauth): |
104 | - shutil.copyfile( |
105 | - os.path.expanduser(os.path.join('~', '.Xauthority')), |
106 | - os.path.join(temp_dir, '.Xauthority')) |
107 | - self.addCleanup(shutil.rmtree, temp_dir) |
108 | - patcher = mock.patch.dict('os.environ', {'HOME': temp_dir}) |
109 | - patcher.start() |
110 | - self.addCleanup(patcher.stop) |
111 | - |
112 | def _make_file_in_home(self): |
113 | return self._make_content_in_home('file') |
114 | |
115 | def _make_content_in_home(self, type_): |
116 | if type_ != 'file' and type_ != 'directory': |
117 | raise ValueError('Unknown content type: "{0}"', type_) |
118 | - folder_list_page = self.main_view.get_folder_list_page() |
119 | - original_count = ( |
120 | - folder_list_page.get_number_of_files_from_list()) |
121 | if type_ == 'file': |
122 | _, path = tempfile.mkstemp(dir=os.environ['HOME']) |
123 | + self.addCleanup(self._unlink_cleanup, path) |
124 | else: |
125 | path = tempfile.mkdtemp(dir=os.environ['HOME']) |
126 | + self.addCleanup(self._rmdir_cleanup, path) |
127 | |
128 | - self._assert_number_of_files(original_count + 1) |
129 | + self._assert_number_of_files(1) |
130 | return path |
131 | |
132 | - def _assert_number_of_files(self, expected_number_of_files): |
133 | + def _assert_number_of_files(self, expected_number_of_files, home=True): |
134 | + if home: |
135 | + expected_number_of_files += self.original_file_count |
136 | self.assertThat( |
137 | self.main_view.get_folder_list_page, |
138 | Eventually(Not(Is(None)))) |
139 | @@ -85,6 +69,13 @@ |
140 | folder_list_page.get_number_of_files_from_header, |
141 | Eventually(Equals(expected_number_of_files))) |
142 | |
143 | + def _get_file_by_name(self, name): |
144 | + self.assertThat( |
145 | + self.main_view.get_folder_list_page, |
146 | + Eventually(Not(Is(None)))) |
147 | + folder_list_page = self.main_view.get_folder_list_page() |
148 | + return folder_list_page.get_file_by_name(name) |
149 | + |
150 | def _get_file_by_index(self, index): |
151 | self.assertThat( |
152 | self.main_view.get_folder_list_page, |
153 | @@ -149,6 +140,14 @@ |
154 | confirm_dialog.enter_text(text) |
155 | confirm_dialog.ok() |
156 | |
157 | + def _unlink_cleanup(self, filename): |
158 | + if os.path.exists(filename): |
159 | + os.unlink(filename) |
160 | + |
161 | + def _rmdir_cleanup(self, directory): |
162 | + if os.path.exists(directory): |
163 | + shutil.rmtree(directory) |
164 | + |
165 | # We can't do this testcase on phablet devices because of a lack of |
166 | # Mir backend in autopilot |
167 | # see https://bugs.launchpad.net/autopilot/+bug/1209004 |
168 | @@ -189,10 +188,12 @@ |
169 | window.close() |
170 | |
171 | def test_rename_directory(self): |
172 | - self._make_directory_in_home() |
173 | + orig_dir = os.path.basename(self._make_directory_in_home()) |
174 | new_name = 'Renamed directory' |
175 | + self.addCleanup(self._rmdir_cleanup, |
176 | + os.path.join(os.environ['HOME'], new_name)) |
177 | |
178 | - first_dir = self._get_file_by_index(0) |
179 | + first_dir = self._get_file_by_name(orig_dir) |
180 | self._do_action_on_file(first_dir, action='Rename') |
181 | self._confirm_dialog(new_name) |
182 | |
183 | @@ -203,22 +204,22 @@ |
184 | |
185 | def test_open_directory(self): |
186 | dir_path = self._make_directory_in_home() |
187 | - first_dir = self._get_file_by_index(0) |
188 | + first_dir = self._get_file_by_name(os.path.basename(dir_path)) |
189 | |
190 | self._open_directory(first_dir) |
191 | |
192 | folder_list_page = self.main_view.get_folder_list_page() |
193 | self.assertThat( |
194 | folder_list_page.get_current_path, Eventually(Equals(dir_path))) |
195 | - self._assert_number_of_files(0) |
196 | + self._assert_number_of_files(0, home=False) |
197 | # TODO check the label that says the directory is empty. |
198 | # --elopio - 2013-07-25 |
199 | |
200 | def test_folder_context_menu_shows(self): |
201 | """Checks to make sure that the folder actions popover is shown.""" |
202 | - self._make_directory_in_home() |
203 | + dir_path = os.path.basename(self._make_directory_in_home()) |
204 | |
205 | - first_file = self._get_file_by_index(0) |
206 | + first_file = self._get_file_by_name(dir_path) |
207 | first_file.open_actions_popover() |
208 | |
209 | self.assertThat( |
210 | @@ -236,16 +237,16 @@ |
211 | |
212 | self._assert_number_of_files(2) |
213 | |
214 | - dir_ = self._get_file_by_index(0) |
215 | + dir_ = self._get_file_by_name(dir_name) |
216 | self.assertThat(dir_.fileName, Eventually(Equals(dir_name))) |
217 | |
218 | - file_ = self._get_file_by_index(1) |
219 | + file_ = self._get_file_by_name(file_name) |
220 | self.assertThat(file_.fileName, Eventually(Equals(file_name))) |
221 | |
222 | def test_cancel_file_action_dialog(self): |
223 | - self._make_file_in_home() |
224 | + file_name = os.path.basename(self._make_file_in_home()) |
225 | |
226 | - first_file = self._get_file_by_index(0) |
227 | + first_file = self._get_file_by_name(file_name) |
228 | self.pointing_device.click_object(first_file) |
229 | |
230 | dialog = self.main_view.get_file_action_dialog() |
231 | @@ -258,7 +259,7 @@ |
232 | dir_path = self._make_directory_in_home() |
233 | dir_name = os.path.basename(dir_path) |
234 | |
235 | - first_dir = self._get_file_by_index(0) |
236 | + first_dir = self._get_file_by_name(dir_name) |
237 | self._do_action_on_file(first_dir, action='Rename') |
238 | self._cancel_confirm_dialog() |
239 | |
240 | @@ -271,7 +272,7 @@ |
241 | file_path = self._make_file_in_home() |
242 | file_name = os.path.basename(file_path) |
243 | |
244 | - first_file = self._get_file_by_index(0) |
245 | + first_file = self._get_file_by_name(file_name) |
246 | self._do_action_on_file(first_file, action='Rename') |
247 | self._cancel_confirm_dialog() |
248 | |
249 | @@ -283,10 +284,11 @@ |
250 | Eventually(Equals(file_name))) |
251 | |
252 | def test_rename_file(self): |
253 | - self._make_file_in_home() |
254 | + file_name = os.path.basename(self._make_file_in_home()) |
255 | new_name = 'Renamed file' |
256 | + self.addCleanup(self._unlink_cleanup, new_name) |
257 | |
258 | - first_file = self._get_file_by_index(0) |
259 | + first_file = self._get_file_by_name(file_name) |
260 | self._do_action_on_file(first_file, action='Rename') |
261 | self._confirm_dialog(new_name) |
262 | |
263 | @@ -296,8 +298,8 @@ |
264 | lambda: first_file.fileName, Eventually(Equals(new_name))) |
265 | |
266 | def test_cancel_delete_directory(self): |
267 | - self._make_directory_in_home() |
268 | - first_dir = self._get_file_by_index(0) |
269 | + dir_name = os.path.basename(self._make_directory_in_home()) |
270 | + first_dir = self._get_file_by_name(dir_name) |
271 | |
272 | self._do_action_on_file(first_dir, 'Delete') |
273 | self._cancel_confirm_dialog() |
274 | @@ -305,8 +307,8 @@ |
275 | self._assert_number_of_files(1) |
276 | |
277 | def test_delete_directory(self): |
278 | - self._make_directory_in_home() |
279 | - first_dir = self._get_file_by_index(0) |
280 | + dir_name = os.path.basename(self._make_directory_in_home()) |
281 | + first_dir = self._get_file_by_name(dir_name) |
282 | |
283 | self._do_action_on_file(first_dir, 'Delete') |
284 | self._confirm_dialog() |
285 | @@ -314,8 +316,8 @@ |
286 | self._assert_number_of_files(0) |
287 | |
288 | def test_cancel_delete_file(self): |
289 | - self._make_file_in_home() |
290 | - first_file = self._get_file_by_index(0) |
291 | + file_name = os.path.basename(self._make_file_in_home()) |
292 | + first_file = self._get_file_by_name(file_name) |
293 | |
294 | self._do_action_on_file(first_file, 'Delete') |
295 | self._cancel_confirm_dialog() |
296 | @@ -323,8 +325,8 @@ |
297 | self._assert_number_of_files(1) |
298 | |
299 | def test_delete_file(self): |
300 | - self._make_file_in_home() |
301 | - first_file = self._get_file_by_index(0) |
302 | + file_name = os.path.basename(self._make_file_in_home()) |
303 | + first_file = self._get_file_by_name(file_name) |
304 | |
305 | self._do_action_on_file(first_file, 'Delete') |
306 | self._confirm_dialog() |
307 | @@ -333,6 +335,8 @@ |
308 | |
309 | def test_create_directory(self): |
310 | dir_name = 'Test Directory' |
311 | + self.addCleanup(self._rmdir_cleanup, |
312 | + os.path.join(os.environ['HOME'], dir_name)) |
313 | |
314 | toolbar = self.main_view.open_toolbar() |
315 | toolbar.click_button('actions') |
316 | @@ -347,13 +351,14 @@ |
317 | |
318 | self._assert_number_of_files(1) |
319 | |
320 | - dir_ = self._get_file_by_index(0) |
321 | + dir_ = self._get_file_by_name(dir_name) |
322 | self.assertThat(dir_.fileName, Eventually(Equals(dir_name))) |
323 | # TODO missing test, cancel create directory. --elopio - 2013-07-25 |
324 | |
325 | def test_show_directory_properties_from_list(self): |
326 | dir_path = self._make_directory_in_home() |
327 | - first_dir = self._get_file_by_index(0) |
328 | + dir_name = os.path.basename(dir_path) |
329 | + first_dir = self._get_file_by_name(dir_name) |
330 | |
331 | self._do_action_on_file(first_dir, 'Properties') |
332 | file_details_popover = self.main_view.get_file_details_popover() |
333 | @@ -366,7 +371,8 @@ |
334 | |
335 | def test_show_file_properties(self): |
336 | file_path = self._make_file_in_home() |
337 | - first_file = self._get_file_by_index(0) |
338 | + file_name = os.path.basename(file_path) |
339 | + first_file = self._get_file_by_name(file_name) |
340 | |
341 | self._do_action_on_file(first_file, 'Properties') |
342 | file_details_popover = self.main_view.get_file_details_popover() |
343 | @@ -380,9 +386,11 @@ |
344 | destination_dir_path = os.path.join(os.environ['HOME'], 'destination') |
345 | destination_dir_name = os.path.basename(destination_dir_path) |
346 | os.mkdir(destination_dir_path) |
347 | + self.addCleanup(self._rmdir_cleanup, destination_dir_path) |
348 | dir_to_copy_path = os.path.join(os.environ['HOME'], 'to_copy') |
349 | dir_to_copy_name = os.path.basename(dir_to_copy_path) |
350 | os.mkdir(dir_to_copy_path) |
351 | + self.addCleanup(self._rmdir_cleanup, dir_to_copy_path) |
352 | |
353 | folder_list_page = self.main_view.get_folder_list_page() |
354 | self._assert_number_of_files(2) |
355 | @@ -411,7 +419,7 @@ |
356 | Eventually(Equals(None))) |
357 | |
358 | # Check that the directory is there. |
359 | - self._assert_number_of_files(1) |
360 | + self._assert_number_of_files(1, home=False) |
361 | first_dir = self._get_file_by_index(0) |
362 | self.assertThat( |
363 | first_dir.fileName, Eventually(Equals(dir_to_copy_name))) |
364 | @@ -428,9 +436,11 @@ |
365 | destination_dir_path = os.path.join(os.environ['HOME'], 'destination') |
366 | destination_dir_name = os.path.basename(destination_dir_path) |
367 | os.mkdir(destination_dir_path) |
368 | + self.addCleanup(self._rmdir_cleanup, destination_dir_path) |
369 | dir_to_cut_path = os.path.join(os.environ['HOME'], 'to_cut') |
370 | dir_to_cut_name = os.path.basename(dir_to_cut_path) |
371 | os.mkdir(dir_to_cut_path) |
372 | + self.addCleanup(self._rmdir_cleanup, dir_to_cut_path) |
373 | |
374 | folder_list_page = self.main_view.get_folder_list_page() |
375 | self._assert_number_of_files(2) |
376 | @@ -459,7 +469,7 @@ |
377 | Eventually(Equals(None))) |
378 | |
379 | # Check that the directory is there. |
380 | - self._assert_number_of_files(1) |
381 | + self._assert_number_of_files(1, home=False) |
382 | first_dir = self._get_file_by_index(0) |
383 | self.assertThat( |
384 | first_dir.fileName, Eventually(Equals(dir_to_cut_name))) |
385 | @@ -470,7 +480,7 @@ |
386 | |
387 | # Check that the directory is not there. |
388 | self._assert_number_of_files(1) |
389 | - first_dir = self._get_file_by_index(0) |
390 | + first_dir = self._get_file_by_name(destination_dir_name) |
391 | self.assertThat( |
392 | first_dir.fileName, Eventually(Equals(destination_dir_name))) |
393 | |
394 | @@ -559,7 +569,7 @@ |
395 | Eventually(Equals(None))) |
396 | |
397 | # Check that the file is there. |
398 | - self._assert_number_of_files(1) |
399 | + self._assert_number_of_files(1, home=False) |
400 | first_dir = self._get_file_by_index(0) |
401 | self.assertThat( |
402 | first_dir.fileName, Eventually(Equals(file_to_cut_name))) |
403 | @@ -570,13 +580,13 @@ |
404 | |
405 | # Check that the file is not there. |
406 | self._assert_number_of_files(1) |
407 | - first_dir = self._get_file_by_index(0) |
408 | + first_dir = self._get_file_by_name(destination_dir_name) |
409 | self.assertThat( |
410 | first_dir.fileName, Eventually(Equals(destination_dir_name))) |
411 | |
412 | def test_go_up(self): |
413 | - self._make_directory_in_home() |
414 | - first_dir = self._get_file_by_index(0) |
415 | + dir_name = os.path.basename(self._make_directory_in_home()) |
416 | + first_dir = self._get_file_by_name(dir_name) |
417 | self._open_directory(first_dir) |
418 | |
419 | toolbar = self.main_view.open_toolbar() |
420 | @@ -605,9 +615,9 @@ |
421 | |
422 | def test_file_context_menu_shows(self): |
423 | """Checks to make sure that the file actions popover is shown.""" |
424 | - self._make_file_in_home() |
425 | + file_name = os.path.basename(self._make_file_in_home()) |
426 | |
427 | - first_file = self._get_file_by_index(0) |
428 | + first_file = self._get_file_by_name(file_name) |
429 | first_file.open_actions_popover() |
430 | |
431 | self.assertThat( |
432 | |
433 | === modified file 'ubuntu-filemanager-app.qml' |
434 | --- ubuntu-filemanager-app.qml 2013-09-17 16:47:57 +0000 |
435 | +++ ubuntu-filemanager-app.qml 2013-10-14 20:58:22 +0000 |
436 | @@ -31,7 +31,7 @@ |
437 | id: root |
438 | // objectName for functional testing purposes (autopilot-qt5) |
439 | objectName: "filemanager" |
440 | - applicationName: "ubuntu-filemanager-app" |
441 | + applicationName: "com.ubuntu.filemanager" |
442 | |
443 | width: units.gu(100) |
444 | height: units.gu(75) |
FAILED: Continuous integration, rev:80 91.189. 93.70:8080/ job/ubuntu- filemanager- app-ci/ 47/ 91.189. 93.70:8080/ job/generic- mediumtests/ 1010/console 91.189. 93.70:8080/ job/ubuntu- filemanager- app-precise- amd64-ci/ 47 91.189. 93.70:8080/ job/ubuntu- filemanager- app-quantal- amd64-ci/ 47 91.189. 93.70:8080/ job/ubuntu- filemanager- app-raring- amd64-ci/ 47 91.189. 93.70:8080/ job/ubuntu- filemanager- app-saucy- amd64-ci/ 47
http://
Executed test runs:
FAILURE: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild: 91.189. 93.70:8080/ job/ubuntu- filemanager- app-ci/ 47/rebuild
http://