Merge lp:~ubuntu-filemanager-dev/ubuntu-filemanager-app/force-authentication-parameter into lp:ubuntu-filemanager-app

Proposed by Arto Jalkanen
Status: Merged
Approved by: Nicholas Skaggs
Approved revision: 289
Merged at revision: 286
Proposed branch: lp:~ubuntu-filemanager-dev/ubuntu-filemanager-app/force-authentication-parameter
Merge into: lp:ubuntu-filemanager-app
Diff against target: 2175 lines (+815/-710)
10 files modified
po/com.ubuntu.filemanager.pot (+74/-52)
src/app/main.cpp (+22/-0)
src/app/qml/ui/FolderListPage.qml (+1/-1)
src/plugin/pamauthentication/pamauthentication.cpp (+0/-8)
tests/autopilot/filemanager/__init__.py (+539/-7)
tests/autopilot/filemanager/emulators.py (+0/-518)
tests/autopilot/filemanager/tests/__init__.py (+107/-53)
tests/autopilot/filemanager/tests/test_context_menu.py (+9/-10)
tests/autopilot/filemanager/tests/test_filemanager.py (+55/-53)
tests/autopilot/filemanager/tests/test_places.py (+8/-8)
To merge this branch: bzr merge lp:~ubuntu-filemanager-dev/ubuntu-filemanager-app/force-authentication-parameter
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Nicholas Skaggs (community) Needs Fixing
Review via email: mp+234015@code.launchpad.net

Commit message

Added parameter to force authentication on or off (this is mainly for autopilot tests). Moved the somewhat ugly special case of not using authentication away from pamauthenticaion library into main.cpp.

Description of the change

Added parameter to force authentication on or off (this is mainly for autopilot tests). Moved the somewhat ugly special case of not using authentication away from pamauthenticaion library into main.cpp.

To post a comment you must log in.
Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

Need to remove the excess pot file changes :-)

We'll need to update the tests to call the app via this as well.

I don't want to merge this workaround unless we are unable to get a testability interface for PAM. I'm in conversation with ogra about this. If we are forced to land something as a workaround in the interim, this should suffice.

review: Needs Fixing
Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

Leo has given a good example of passing along the argument to the application;

https://code.launchpad.net/~canonical-platform-qa/reminders-app/fix1363599-upstart_and_sandbox/+merge/233832

You can follow this example to update the tests.

Carla, want to give this a go?

Revision history for this message
Carla Sella (carla-sella) wrote :

@ Nicholas, sure let me try :-)

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

This should work, however the get_installed_version_and_directory method doesn't not take into account non-image versions; hence we are unable to push the new click package and test it easily.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'po/com.ubuntu.filemanager.pot'
2--- po/com.ubuntu.filemanager.pot 2014-08-13 08:39:20 +0000
3+++ po/com.ubuntu.filemanager.pot 2014-09-25 21:51:25 +0000
4@@ -8,7 +8,7 @@
5 msgstr ""
6 "Project-Id-Version: \n"
7 "Report-Msgid-Bugs-To: \n"
8-"POT-Creation-Date: 2014-08-13 10:37+0200\n"
9+"POT-Creation-Date: 2014-09-22 15:39-0400\n"
10 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
11 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
12 "Language-Team: LANGUAGE <LL@li.org>\n"
13@@ -31,39 +31,53 @@
14 msgstr ""
15
16 #: ../src/app/qml/components/PlacesSidebar.qml:54
17-#: ../src/app/qml/ui/FolderListPage.qml:305
18+#: ../src/app/qml/ui/FolderListPage.qml:306
19 msgid "Places"
20 msgstr ""
21
22-#: ../src/app/qml/filemanager.qml:83 ../src/app/qml/ui/SettingsSheet.qml:31
23+#: ../src/app/qml/filemanager.qml:89 ../src/app/qml/ui/SettingsSheet.qml:31
24 msgid "Settings"
25 msgstr ""
26
27-#: ../src/app/qml/filemanager.qml:84
28+#: ../src/app/qml/filemanager.qml:90
29 msgid "Change app settings"
30 msgstr ""
31
32-#: ../src/app/qml/filemanager.qml:246 ../src/app/qml/ui/FolderListPage.qml:408
33+#: ../src/app/qml/filemanager.qml:252 ../src/app/qml/ui/FolderListPage.qml:432
34 #: ../src/app/qml/ui/ViewPopover.qml:70
35 msgid "Icons"
36 msgstr ""
37
38-#: ../src/app/qml/filemanager.qml:246 ../src/app/qml/ui/FolderListPage.qml:425
39+#: ../src/app/qml/filemanager.qml:252 ../src/app/qml/ui/FolderListPage.qml:449
40 #: ../src/app/qml/ui/ViewPopover.qml:71
41 msgid "List"
42 msgstr ""
43
44+#: ../src/app/qml/ui/AuthenticationDialog.qml:25
45+msgid "Authentication required"
46+msgstr ""
47+
48+#: ../src/app/qml/ui/AuthenticationDialog.qml:27
49+msgid "Enter password:"
50+msgstr ""
51+
52+#: ../src/app/qml/ui/AuthenticationDialog.qml:39
53+msgid "password"
54+msgstr ""
55+
56+#: ../src/app/qml/ui/AuthenticationDialog.qml:49
57 #: ../src/app/qml/ui/ConfirmDialog.qml:31
58-#: ../src/app/qml/ui/ConfirmDialogWithInput.qml:41
59+#: ../src/app/qml/ui/ConfirmDialogWithInput.qml:47
60 #: ../src/app/qml/ui/NotifyDialog.qml:25
61 msgid "Ok"
62 msgstr ""
63
64+#: ../src/app/qml/ui/AuthenticationDialog.qml:60
65 #: ../src/app/qml/ui/ConfirmDialog.qml:41
66-#: ../src/app/qml/ui/ConfirmDialogWithInput.qml:51
67+#: ../src/app/qml/ui/ConfirmDialogWithInput.qml:57
68 #: ../src/app/qml/ui/FileActionDialog.qml:45
69 #: ../src/app/qml/ui/FileOperationProgressDialog.qml:44
70-#: ../src/app/qml/ui/FolderListPage.qml:385
71+#: ../src/app/qml/ui/FolderListPage.qml:386
72 #: ../src/app/qml/ui/GoToDialog.qml:66
73 msgid "Cancel"
74 msgstr ""
75@@ -121,74 +135,74 @@
76 msgid "Operation in progress"
77 msgstr ""
78
79-#: ../src/app/qml/ui/FolderListPage.qml:93
80+#: ../src/app/qml/ui/FolderListPage.qml:94
81 #, qt-format
82 msgid "%1 file"
83 msgid_plural "%1 files"
84 msgstr[0] ""
85 msgstr[1] ""
86
87-#: ../src/app/qml/ui/FolderListPage.qml:118
88+#: ../src/app/qml/ui/FolderListPage.qml:119
89 msgid "Open in a new tab"
90 msgstr ""
91
92-#: ../src/app/qml/ui/FolderListPage.qml:126
93+#: ../src/app/qml/ui/FolderListPage.qml:127
94 msgid "Close this tab"
95 msgstr ""
96
97-#: ../src/app/qml/ui/FolderListPage.qml:146
98+#: ../src/app/qml/ui/FolderListPage.qml:147
99 msgid "Create New Folder"
100 msgstr ""
101
102-#: ../src/app/qml/ui/FolderListPage.qml:166
103+#: ../src/app/qml/ui/FolderListPage.qml:167
104 msgid "Paste"
105 msgstr ""
106
107-#: ../src/app/qml/ui/FolderListPage.qml:167
108+#: ../src/app/qml/ui/FolderListPage.qml:168
109 #, qt-format
110 msgid "Paste %1 File"
111 msgid_plural "Paste %1 Files"
112 msgstr[0] ""
113 msgstr[1] ""
114
115-#: ../src/app/qml/ui/FolderListPage.qml:170
116+#: ../src/app/qml/ui/FolderListPage.qml:171
117 msgid "Paste files"
118 msgstr ""
119
120-#: ../src/app/qml/ui/FolderListPage.qml:182
121+#: ../src/app/qml/ui/FolderListPage.qml:183
122 msgid "Open in Terminal"
123 msgstr ""
124
125-#: ../src/app/qml/ui/FolderListPage.qml:194
126-#: ../src/app/qml/ui/FolderListPage.qml:567
127+#: ../src/app/qml/ui/FolderListPage.qml:195
128+#: ../src/app/qml/ui/FolderListPage.qml:591
129 msgid "Properties"
130 msgstr ""
131
132-#: ../src/app/qml/ui/FolderListPage.qml:211
133+#: ../src/app/qml/ui/FolderListPage.qml:212
134 msgid "Create folder"
135 msgstr ""
136
137-#: ../src/app/qml/ui/FolderListPage.qml:212
138+#: ../src/app/qml/ui/FolderListPage.qml:213
139 msgid "Enter name for new folder"
140 msgstr ""
141
142-#: ../src/app/qml/ui/FolderListPage.qml:228
143+#: ../src/app/qml/ui/FolderListPage.qml:229
144 msgid "Create file"
145 msgstr ""
146
147-#: ../src/app/qml/ui/FolderListPage.qml:229
148+#: ../src/app/qml/ui/FolderListPage.qml:230
149 msgid "Enter name for new file"
150 msgstr ""
151
152-#: ../src/app/qml/ui/FolderListPage.qml:251
153+#: ../src/app/qml/ui/FolderListPage.qml:252
154 msgid "Up"
155 msgstr ""
156
157-#: ../src/app/qml/ui/FolderListPage.qml:280
158+#: ../src/app/qml/ui/FolderListPage.qml:281
159 msgid "Actions"
160 msgstr ""
161
162-#: ../src/app/qml/ui/FolderListPage.qml:290
163+#: ../src/app/qml/ui/FolderListPage.qml:291
164 msgid "View"
165 msgstr ""
166
167@@ -196,85 +210,93 @@
168 msgid "Select"
169 msgstr ""
170
171-#: ../src/app/qml/ui/FolderListPage.qml:440
172+#: ../src/app/qml/ui/FolderListPage.qml:394
173+msgid "Unlock full access"
174+msgstr ""
175+
176+#: ../src/app/qml/ui/FolderListPage.qml:408
177+msgid "Authentication failed"
178+msgstr ""
179+
180+#: ../src/app/qml/ui/FolderListPage.qml:464
181 msgid "No files"
182 msgstr ""
183
184-#: ../src/app/qml/ui/FolderListPage.qml:460
185-#: ../src/app/qml/ui/FolderListPage.qml:541
186+#: ../src/app/qml/ui/FolderListPage.qml:484
187+#: ../src/app/qml/ui/FolderListPage.qml:565
188 msgid "Delete"
189 msgstr ""
190
191-#: ../src/app/qml/ui/FolderListPage.qml:461
192+#: ../src/app/qml/ui/FolderListPage.qml:485
193 #, qt-format
194 msgid "Are you sure you want to permanently delete '%1'?"
195 msgstr ""
196
197-#: ../src/app/qml/ui/FolderListPage.qml:484
198-#: ../src/app/qml/ui/FolderListPage.qml:554
199+#: ../src/app/qml/ui/FolderListPage.qml:508
200+#: ../src/app/qml/ui/FolderListPage.qml:578
201 msgid "Rename"
202 msgstr ""
203
204-#: ../src/app/qml/ui/FolderListPage.qml:485
205+#: ../src/app/qml/ui/FolderListPage.qml:509
206 msgid "Enter a new name"
207 msgstr ""
208
209-#: ../src/app/qml/ui/FolderListPage.qml:494
210+#: ../src/app/qml/ui/FolderListPage.qml:518
211 msgid "Could not rename"
212 msgstr ""
213
214-#: ../src/app/qml/ui/FolderListPage.qml:495
215+#: ../src/app/qml/ui/FolderListPage.qml:519
216 msgid "Insufficient permissions or name already exists?"
217 msgstr ""
218
219-#: ../src/app/qml/ui/FolderListPage.qml:518
220+#: ../src/app/qml/ui/FolderListPage.qml:542
221 msgid "Cut"
222 msgstr ""
223
224-#: ../src/app/qml/ui/FolderListPage.qml:529
225+#: ../src/app/qml/ui/FolderListPage.qml:553
226 msgid "Copy"
227 msgstr ""
228
229-#: ../src/app/qml/ui/FolderListPage.qml:586
230-#: ../src/app/qml/ui/FolderListPage.qml:709
231+#: ../src/app/qml/ui/FolderListPage.qml:610
232+#: ../src/app/qml/ui/FolderListPage.qml:733
233 msgid "File operation error"
234 msgstr ""
235
236-#: ../src/app/qml/ui/FolderListPage.qml:635
237+#: ../src/app/qml/ui/FolderListPage.qml:659
238 msgid "~/Desktop"
239 msgstr ""
240
241-#: ../src/app/qml/ui/FolderListPage.qml:645
242+#: ../src/app/qml/ui/FolderListPage.qml:669
243 msgid "~/Public"
244 msgstr ""
245
246-#: ../src/app/qml/ui/FolderListPage.qml:647
247+#: ../src/app/qml/ui/FolderListPage.qml:671
248 msgid "~/Programs"
249 msgstr ""
250
251-#: ../src/app/qml/ui/FolderListPage.qml:649
252+#: ../src/app/qml/ui/FolderListPage.qml:673
253 msgid "~/Templates"
254 msgstr ""
255
256-#: ../src/app/qml/ui/FolderListPage.qml:662
257+#: ../src/app/qml/ui/FolderListPage.qml:686
258 msgid "Home"
259 msgstr ""
260
261-#: ../src/app/qml/ui/FolderListPage.qml:664
262+#: ../src/app/qml/ui/FolderListPage.qml:688
263 msgid "Device"
264 msgstr ""
265
266-#: ../src/app/qml/ui/FolderListPage.qml:709
267+#: ../src/app/qml/ui/FolderListPage.qml:733
268 #, qt-format
269 msgid "Unable to open '%1'"
270 msgstr ""
271
272-#: ../src/app/qml/ui/FolderListPage.qml:721
273+#: ../src/app/qml/ui/FolderListPage.qml:745
274 msgid "Folder not accessible"
275 msgstr ""
276
277 #. TRANSLATORS: this refers to a folder name
278-#: ../src/app/qml/ui/FolderListPage.qml:723
279+#: ../src/app/qml/ui/FolderListPage.qml:747
280 #, qt-format
281 msgid "Can not access %1"
282 msgstr ""
283@@ -339,19 +361,19 @@
284 msgid "Filter"
285 msgstr ""
286
287-#: ../src/plugin/folderlistmodel/dirmodel.cpp:414
288+#: ../src/plugin/folderlistmodel/dirmodel.cpp:441
289 msgid "path or url may not exist or cannot be read"
290 msgstr ""
291
292-#: ../src/plugin/folderlistmodel/dirmodel.cpp:527
293+#: ../src/plugin/folderlistmodel/dirmodel.cpp:611
294 msgid "Rename error"
295 msgstr ""
296
297-#: ../src/plugin/folderlistmodel/dirmodel.cpp:547
298+#: ../src/plugin/folderlistmodel/dirmodel.cpp:636
299 msgid "Error creating new folder"
300 msgstr ""
301
302-#: ../src/plugin/folderlistmodel/dirmodel.cpp:1145
303+#: ../src/plugin/folderlistmodel/dirmodel.cpp:1264
304 msgid "items"
305 msgstr ""
306
307
308=== modified file 'src/app/main.cpp'
309--- src/app/main.cpp 2014-04-28 10:21:05 +0000
310+++ src/app/main.cpp 2014-09-25 21:51:25 +0000
311@@ -47,6 +47,7 @@
312 qDebug() << "usage: " + args.at(0) + " [-p|--phone] [-t|--tablet] [-h|--help] [-I <path>]";
313 qDebug() << " -p|--phone If running on Desktop, start in a phone sized window.";
314 qDebug() << " -t|--tablet If running on Desktop, start in a tablet sized window.";
315+ qDebug() << " --forceAuth <true|false> Force authentication on or off.";
316 qDebug() << " -h|--help Print this help.";
317 qDebug() << " -I <path> Give a path for an additional QML import directory. May be used multiple times.";
318 qDebug() << " -q <qmlfile> Give an alternative location for the main qml file.";
319@@ -54,6 +55,15 @@
320 }
321
322 QString qmlfile;
323+ // Desktop doesn't have yet Unity8 and so no unity greeter either. Consequently it doesn't
324+ // also have any "PIN code" or "Password" extra authentication. Don't require any extra
325+ // authentication there by default
326+ if (qgetenv("QT_QPA_PLATFORM") != "ubuntumirclient") {
327+ qDebug() << Q_FUNC_INFO << "Running on non-MIR desktop, not requiring authentication by default";
328+ view.engine()->rootContext()->setContextProperty("noAuthentication", QVariant(true));
329+ } else {
330+ view.engine()->rootContext()->setContextProperty("noAuthentication", QVariant(false));
331+ }
332 for (int i = 0; i < args.count(); i++) {
333 if (args.at(i) == "-I" && args.count() > i + 1) {
334 QString addedPath = args.at(i+1);
335@@ -64,6 +74,17 @@
336 importPathList.append(addedPath);
337 } else if (args.at(i) == "-q" && args.count() > i + 1) {
338 qmlfile = args.at(i+1);
339+ } else if (args.at(i) == "--forceAuth" && args.count() > i + 1) {
340+ QString value = args.at(i+1);
341+ if (value == "true") {
342+ qDebug() << Q_FUNC_INFO << "Forcing authentication on";
343+ view.engine()->rootContext()->setContextProperty("noAuthentication", QVariant(false));
344+ } else if (value == "false") {
345+ qDebug() << Q_FUNC_INFO << "Forcing authentication off";
346+ view.engine()->rootContext()->setContextProperty("noAuthentication", QVariant(true));
347+ } else {
348+ qWarning() << Q_FUNC_INFO << "Invalid forceAuth option '" << value << "', keeping default";
349+ }
350 }
351 }
352
353@@ -84,6 +105,7 @@
354
355 view.engine()->rootContext()->setContextProperty("tablet", QVariant(false));
356 view.engine()->rootContext()->setContextProperty("phone", QVariant(false));
357+
358 if (args.contains("-t") || args.contains("--tablet")) {
359 qDebug() << "running in tablet mode";
360 view.engine()->rootContext()->setContextProperty("tablet", QVariant(true));
361
362=== modified file 'src/app/qml/ui/FolderListPage.qml'
363--- src/app/qml/ui/FolderListPage.qml 2014-09-08 10:18:09 +0000
364+++ src/app/qml/ui/FolderListPage.qml 2014-09-25 21:51:25 +0000
365@@ -86,7 +86,7 @@
366 id: pageModel
367 path: folderListPage.folder
368 enableExternalFSWatcher: true
369- onlyMTPPaths: pamAuthentication.requireAuthentication()
370+ onlyMTPPaths: !noAuthentication && pamAuthentication.requireAuthentication()
371
372 // Properties to emulate a model entry for use by FileDetailsPopover
373 property bool isDir: true
374
375=== modified file 'src/plugin/pamauthentication/pamauthentication.cpp'
376--- src/plugin/pamauthentication/pamauthentication.cpp 2014-08-19 20:51:10 +0000
377+++ src/plugin/pamauthentication/pamauthentication.cpp 2014-09-25 21:51:25 +0000
378@@ -48,14 +48,6 @@
379
380 bool
381 PamAuthentication::requireAuthentication() {
382- // Desktop doesn't have yet Unity8 and so no unity greeter either. Consequently it doesn't
383- // also have any "PIN code" or "Password" extra authentication. Don't require any extra
384- // authentication there.
385- if (qgetenv("QT_QPA_PLATFORM") != "ubuntumirclient") {
386- qDebug() << Q_FUNC_INFO << "Running on non-MIR desktop, not requiring authentication";
387- return false;
388- }
389-
390 QDBusInterface dbus_iface(UNITYGREETER_SERVICE, UNITYGREETER_PATH, UNITYGREETER_INTERFACE);
391
392 qDebug() << Q_FUNC_INFO << "Querying if authentication required";
393
394=== modified file 'tests/autopilot/filemanager/__init__.py'
395--- tests/autopilot/filemanager/__init__.py 2014-04-14 17:29:54 +0000
396+++ tests/autopilot/filemanager/__init__.py 2014-09-25 21:51:25 +0000
397@@ -1,8 +1,540 @@
398 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
399-# Copyright 2013 Canonical
400-#
401-# This program is free software: you can redistribute it and/or modify it
402-# under the terms of the GNU General Public License version 3, as published
403-# by the Free Software Foundation.
404-
405-"""filemanager-app tests and emulators - top level package."""
406+#
407+# Copyright (C) 2013, 2014 Canonical Ltd.
408+#
409+# This program is free software; you can redistribute it and/or modify
410+# it under the terms of the GNU Lesser General Public License as published by
411+# the Free Software Foundation; version 3.
412+#
413+# This program is distributed in the hope that it will be useful,
414+# but WITHOUT ANY WARRANTY; without even the implied warranty of
415+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
416+# GNU Lesser General Public License for more details.
417+#
418+# You should have received a copy of the GNU Lesser General Public License
419+# along with this program. If not, see <http://www.gnu.org/licenses/>.
420+
421+"""File Manager app autopilot emulators."""
422+
423+import logging
424+import re
425+import time
426+
427+import autopilot.logging
428+from autopilot import input
429+from autopilot.introspection import dbus
430+import ubuntuuitoolkit
431+
432+from filemanager import _common
433+
434+logger = logging.getLogger(__name__)
435+
436+
437+class FilemanagerException(ubuntuuitoolkit.ToolkitException):
438+
439+ """Exception raised when there are problems with the Filemanager."""
440+
441+
442+class Filemanager(object):
443+
444+ """Autopilot helper object for the filemanager application."""
445+
446+ def __init__(self, app_proxy, test_type):
447+ self.app = app_proxy
448+ self.test_type = test_type
449+ self.main_view = self.app.select_single(MainView)
450+
451+ @property
452+ def pointing_device(self):
453+ return self.app.pointing_device
454+
455+
456+class MainView(ubuntuuitoolkit.MainView):
457+ """File Manager MainView Autopilot emulator."""
458+
459+ def __init__(self, *args):
460+ super(MainView, self).__init__(*args)
461+
462+ @autopilot.logging.log_action(logger.info)
463+ def go_to_place(self, object_name):
464+ """Open one of the bookmarked place folders.
465+
466+ :param object_name: The objectName property of the place to open.
467+
468+ """
469+ if self.showSidebar:
470+ self._go_to_place_from_side_bar(object_name)
471+ else:
472+ self._go_to_place_from_popover(object_name)
473+
474+ def _go_to_place_from_side_bar(self, object_name):
475+ side_bar = self.get_folder_list_page().get_sidebar()
476+ side_bar.go_to_place(object_name)
477+
478+ def get_folder_list_page(self):
479+ """Return the FolderListPage emulator of the MainView."""
480+ page = self.wait_select_single(FolderListPage)
481+ page.main_view = self
482+ return page
483+
484+ def _go_to_place_from_popover(self, object_name):
485+ popover = self.open_places()
486+ place = popover.wait_select_single('Standard', objectName=object_name)
487+ self.pointing_device.click_object(place)
488+
489+ @autopilot.logging.log_action(logger.info)
490+ def open_places(self):
491+ if not self.showSidebar:
492+ self.open_toolbar().click_button('places')
493+ return self._get_places_popover()
494+ else:
495+ raise _common('The places popover cannot be opened on wide mode.')
496+
497+ def _get_places_popover(self):
498+ """Return the Places popover."""
499+ # XXX It would be easier if the places popover was an object
500+ # that inherits from Popover, like the
501+ # ActionSelectionPopover does.
502+ # --elopio - 2013-07-25
503+ return self.wait_select_single('Popover', objectName='placesPopover')
504+
505+ @autopilot.logging.log_action(logger.info)
506+ def rename(self, original_name, new_name):
507+ """Rename a file or directory.
508+
509+ :param original_name: The name of the file or directory to rename.
510+ :param new_name: The new name to set for the file or directory.
511+
512+ """
513+ actions_popover = self.open_actions(original_name)
514+ actions_popover.click_button_by_text('Rename')
515+ confirm_dialog = self.wait_select_single(ConfirmDialogWithInput)
516+ confirm_dialog.enter_text(new_name)
517+ confirm_dialog.ok()
518+
519+ @autopilot.logging.log_action(logger.info)
520+ def open_actions(self, name):
521+ """Open the list of available actions of a file or directory."""
522+ folder_list_page = self.get_folder_list_page()
523+ folder_list_page.open_file_actions(name)
524+ actions_popover = self.get_action_selection_popover(
525+ 'fileActionsPopover')
526+ actions_popover.visible.wait_for(True)
527+ return actions_popover
528+
529+ @autopilot.logging.log_action(logger.info)
530+ def delete(self, name):
531+ """Delete a file or directory.
532+
533+ :param name: The name of the file or directory to delete.
534+
535+ """
536+ actions_popover = self.open_actions(name)
537+ actions_popover.click_button_by_text('Delete')
538+ confirm_dialog = self.wait_select_single(ConfirmDialog)
539+ confirm_dialog.ok()
540+
541+ def get_file_actions_popover(self):
542+ """Return the ActionSelectionPopover emulator of the file actions."""
543+ return self.get_action_selection_popover('fileActionsPopover')
544+
545+ def get_folder_actions_popover(self):
546+ """Return the ActionSelectionPopover emulator of the folder actions."""
547+ return self.get_action_selection_popover('folderActionsPopover')
548+
549+ def folder_actions_popover_exists(self):
550+ """Boolean, checks if the folder actions popover exists."""
551+ try:
552+ popover = self.get_folder_actions_popover()
553+ if popover:
554+ return True
555+ except:
556+ return False
557+
558+ def file_actions_popover_exists(self):
559+ """Boolean, checks if the file actions popover exists."""
560+ try:
561+ popover = self.get_file_actions_popover()
562+ if popover:
563+ return True
564+ except:
565+ return False
566+
567+ def get_file_details_popover(self):
568+ """Return the FileDetailsPopover emulator."""
569+ return self.wait_select_single(FileDetailsPopover)
570+
571+ def get_file_action_dialog(self):
572+ """Return the FileActionDialog emulator."""
573+ return self.wait_select_single(FileActionDialog)
574+
575+ def file_action_dialog_exists(self):
576+ """Boolean checks if the FileActionDialog exists."""
577+ dialog = self.select_many(FileActionDialog)
578+ if dialog == '[]':
579+ return True
580+ return False
581+
582+ def get_confirm_dialog(self):
583+ """Return a confirm dialog emulator"""
584+ try:
585+ dialog = self.wait_select_single(ConfirmDialog)
586+ except dbus.StateNotFoundError:
587+ dialog = self.wait_select_single(ConfirmDialogWithInput)
588+ return dialog
589+
590+ def confirm_dialog_exists(self):
591+ """Boolean checks if a confirm dialog exists"""
592+ dialog = self.select_many(ConfirmDialog)
593+ if dialog == '[]':
594+ dialog = self.select_many(ConfirmDialogWithInput)
595+ if dialog == '[]':
596+ return True
597+ return False
598+
599+ def get_dialog(self):
600+ """Return a dialog emulator"""
601+ return self.wait_select_single(Dialog)
602+
603+ def get_popover(self):
604+ """Return a popover emulator"""
605+ return self.wait_select_single(Popover)
606+
607+
608+class PlacesSidebar(ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
609+ """PlacesSidebar Autopilot emulator."""
610+
611+ @autopilot.logging.log_action(logger.info)
612+ def go_to_place(self, object_name):
613+ """Open one of the bookmarked place folders.
614+
615+ :param object_name: The objectName property of the place to open.
616+
617+ """
618+ place = self.select_single('Standard', objectName=object_name)
619+ self.pointing_device.click_object(place)
620+
621+
622+class FolderListPage(ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
623+ """FolderListPage Autopilot emulator."""
624+
625+ def open_file_actions(self, name):
626+ """Open the actions menu of a file or folder.
627+
628+ :param name: The name of the file or folder.
629+
630+ """
631+ delegate = self.get_file_by_name(name)
632+ delegate.open_actions_popover()
633+
634+ def get_files_and_folders(self):
635+ """Return the list of files and folders of the opened directory.
636+
637+ The list returned will contain the names of the files and folders.
638+
639+ """
640+ if self.showingListView:
641+ view = self.select_single(FolderListView)
642+ else:
643+ view = self.select_single(FolderIconView)
644+ return view.get_files_and_folders()
645+
646+ def get_number_of_files_from_list(self):
647+ """Return the number of files shown on the folder."""
648+ if self.showingListView:
649+ return len(self.select_many(FolderListDelegate))
650+ else:
651+ return len(self.select_many(FolderIconDelegate))
652+
653+ def get_file_by_index(self, index):
654+ """Return the FolderListDelegate emulator of the file or folder.
655+
656+ :parameter index: The index of file or folder.
657+
658+ """
659+ if self.showingListView:
660+ file_ = self.select_many(FolderListDelegate)[index]
661+ else:
662+ file_ = self.select_many(FolderIconDelegate)[index]
663+ file_.list_view = self.select_single(FolderListView)
664+ return file_
665+
666+ def get_file_by_name(self, name):
667+ """Return the FolderListDelegate emulator of the file or folder.
668+
669+ :parameter name: The name of the file or folder.
670+
671+ """
672+ files = self.select_many(FolderListDelegate)
673+ if not self.showingListView:
674+ files = self.select_many(FolderIconDelegate)
675+ for file_ in files:
676+ if file_.fileName == name:
677+ if self.showingListView:
678+ file_.list_view = self.select_single(FolderListView)
679+ else:
680+ file_.list_view = self.select_single(FolderIconView)
681+ return file_
682+ raise ValueError(
683+ 'File with name "{0}" not found.'.format(name))
684+
685+ def get_current_path(self):
686+ """Get the path of the folder currently displayed."""
687+ if self.showingListView:
688+ return self.select_single(FolderListView).get_current_path()
689+ else:
690+ return self.select_single(FolderIconView).get_current_path()
691+
692+ def get_number_of_files_from_header(self):
693+ if self.showingListView:
694+ return self.select_single(FolderListView).get_number_of_files()
695+ else:
696+ return self.select_single(FolderIconView).get_number_of_files()
697+
698+ def get_sidebar(self):
699+ if self.main_view.showSidebar:
700+ return self.select_single(PlacesSidebar)
701+ else:
702+ raise ValueError(
703+ 'Places sidebar is hidden in small mode.')
704+
705+ def get_pathbar(self):
706+ if self.main_view.showSidebar:
707+ return self.main_view.get_toolbar().select_single(PathBar)
708+ else:
709+ raise ValueError(
710+ 'Path bar is hidden in small mode.')
711+
712+
713+class FolderListView(ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
714+ """FolderListView Autopilot emulator."""
715+
716+ SPLIT_HEADER_REGEX = '(.+) \((\d+) \w+\)$'
717+ # Regular expression to split the header text. The header text has the form
718+ # /path/to/dir (# files). So with this expression, we can split the header
719+ # in two groups, (.+) will match the path and (\d+) the number of files.
720+
721+ def get_current_path(self):
722+ path, _ = self._split_header_text()
723+ return path
724+
725+ def _split_header_text(self):
726+ header_text = self.select_single(
727+ 'Header', objectName='listViewSmallHeader').text
728+ match = re.match(self.SPLIT_HEADER_REGEX, header_text)
729+ if match:
730+ path = match.group(1)
731+ number_of_files = match.group(2)
732+ return path, number_of_files
733+
734+ def get_number_of_files(self):
735+ _, number_of_files = self._split_header_text()
736+ return int(number_of_files)
737+
738+ def get_files_and_folders(self):
739+ """Return the list of files and folders of the opened directory."""
740+ list_delegates = self.select_many(FolderListDelegate)
741+ # sort by y, x
742+ list_delegates = sorted(
743+ list_delegates,
744+ key=lambda item: (item.globalRect.y, item.globalRect.x))
745+
746+ return [item.fileName for item in list_delegates]
747+
748+
749+class FolderIconView(ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
750+ """FolderListView Autopilot emulator."""
751+
752+ SPLIT_HEADER_REGEX = '(.+) \((\d+) \w+\)$'
753+ # Regular expression to split the header text. The header text has the form
754+ # /path/to/dir (# files). So with this expression, we can split the header
755+ # in two groups, (.+) will match the path and (\d+) the number of files.
756+
757+ def get_current_path(self):
758+ path, _ = self._split_header_text()
759+ return path
760+
761+ def _split_header_text(self):
762+ header_text = self.select_single(
763+ 'Header', objectName='iconViewHeader').text
764+ match = re.match(self.SPLIT_HEADER_REGEX, header_text)
765+ if match:
766+ path = match.group(1)
767+ number_of_files = match.group(2)
768+ return path, number_of_files
769+
770+ def get_number_of_files(self):
771+ _, number_of_files = self._split_header_text()
772+ return int(number_of_files)
773+
774+ def get_files_and_folders(self):
775+ """Return the list of files and folders of the opened directory."""
776+ icon_delegates = self.select_many(FolderIconDelegate)
777+ # sort by y, x
778+ icon_delegates = sorted(
779+ icon_delegates,
780+ key=lambda icon: (icon.globalRect.y, icon.globalRect.x))
781+
782+ return [icon.fileName for icon in icon_delegates]
783+
784+
785+class FolderListDelegate(ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
786+ """FolderListPage Autopilot emulator.
787+
788+ This is a file or folder on the FolderListPage.
789+
790+ """
791+
792+ def __init__(self, *args):
793+ super(FolderListDelegate, self).__init__(*args)
794+ self.pointing_device = ubuntuuitoolkit.get_pointing_device()
795+
796+ def open_directory(self):
797+ """Open the directory."""
798+ # TODO Check if it is a directory. If not, raise an error.
799+ # This is not currently possible because Autopilot is overwriting the
800+ # path attribute. Reported on
801+ # https://bugs.launchpad.net/autopilot/+bug/1205204
802+ # --elopio - 2013-07-25
803+ self.pointing_device.click_object(self)
804+
805+ def open_file(self):
806+ # TODO For this we would need to access the FileActionDialog that's
807+ # child of the MainView, but that's not currently possible with
808+ # autopilot. Reported on
809+ # bug https://bugs.launchpad.net/autopilot/+bug/1195141
810+ # --elopio - 2013-07-25
811+ raise NotImplementedError()
812+
813+ def open_actions_popover(self):
814+ """Open the actions popover of the file or folder."""
815+ self.pointing_device.move_to_object(self)
816+ self.pointing_device.press()
817+ time.sleep(2)
818+ self.pointing_device.release()
819+
820+
821+class FolderIconDelegate(ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
822+ """FolderIconPage Autopilot emulator.
823+
824+ This is a file or folder on the FolderListPage.
825+
826+ """
827+
828+ def __init__(self, *args):
829+ super(FolderIconDelegate, self).__init__(*args)
830+ self.pointing_device = ubuntuuitoolkit.get_pointing_device()
831+
832+ def open_directory(self):
833+ """Open the directory."""
834+ # TODO Check if it is a directory. If not, raise an error.
835+ # This is not currently possible because Autopilot is overwriting the
836+ # path attribute. Reported on
837+ # https://bugs.launchpad.net/autopilot/+bug/1205204
838+ # --elopio - 2013-07-25
839+ self.pointing_device.click_object(self)
840+
841+ def open_file(self):
842+ # TODO For this we would need to access the FileActionDialog that's
843+ # child of the MainView, but that's not currently possible with
844+ # autopilot. Reported on
845+ # bug https://bugs.launchpad.net/autopilot/+bug/1195141
846+ # --elopio - 2013-07-25
847+ raise NotImplementedError
848+
849+ def open_actions_popover(self):
850+ """Open the actions popover of the file or folder."""
851+ self.pointing_device.move_to_object(self)
852+ self.pointing_device.press()
853+ time.sleep(2)
854+ self.pointing_device.release()
855+
856+
857+class FileActionDialog(ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
858+ """FileActionDialog Autopilot emulator."""
859+
860+ def __init__(self, *args):
861+ super(FileActionDialog, self).__init__(*args)
862+ self.pointing_device = ubuntuuitoolkit.get_pointing_device()
863+
864+ def open(self):
865+ open_button = self.select_single('Button', objectName='openButton')
866+ self.pointing_device.click_object(open_button)
867+
868+ def cancel(self):
869+ cancel_button = self.select_single('Button', objectName='cancelButton')
870+ self.pointing_device.click_object(cancel_button)
871+
872+
873+class ConfirmDialog(ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
874+ """ConfirmDialog Autopilot emulator."""
875+
876+ def __init__(self, *args):
877+ super(ConfirmDialog, self).__init__(*args)
878+ self.pointing_device = ubuntuuitoolkit.get_pointing_device()
879+
880+ def ok(self):
881+ okButton = self.select_single('Button', objectName='okButton')
882+ self.pointing_device.click_object(okButton)
883+
884+ def cancel(self):
885+ cancel_button = self.select_single('Button', objectName='cancelButton')
886+ self.pointing_device.click_object(cancel_button)
887+
888+
889+class ConfirmDialogWithInput(ConfirmDialog):
890+ """ConfirmDialogWithInput Autopilot emulator."""
891+
892+ def __init__(self, *args):
893+ super(ConfirmDialogWithInput, self).__init__(*args)
894+ self.keyboard = input.Keyboard.create()
895+
896+ def enter_text(self, text, clear=True):
897+ text_field = self._select_text_field()
898+ text_field.write(text, clear)
899+
900+ def _select_text_field(self):
901+ return self.select_single(
902+ ubuntuuitoolkit.TextField, objectName='inputField')
903+
904+
905+class Dialog(ConfirmDialogWithInput):
906+ """Dialog Autopilot emulator."""
907+
908+
909+class Popover(ConfirmDialogWithInput):
910+ """Popover Autopilot emulator, containing buttons and an inputfield"""
911+
912+ def click_button(self, text):
913+ """Click a button on the popover.
914+
915+ XXX We are receiving the text because there's no way to set the
916+ objectName on the action. This is reported at
917+ https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1205144
918+ --elopio - 2013-07-25
919+
920+ :parameter text: The text of the button.
921+
922+ """
923+ button = self._get_button(text)
924+ self.pointing_device.click_object(button)
925+
926+ def _get_button(self, text):
927+ buttons = self.select_many('Empty')
928+ for button in buttons:
929+ if button.text == text:
930+ return button
931+
932+
933+class FileDetailsPopover(ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
934+ """FileDetailsPopover Autopilot emulator."""
935+
936+ def get_path(self):
937+ return self.select_single('Label', objectName='pathLabel').text
938+
939+
940+class PathBar(ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
941+
942+ def go_to_location(self):
943+ editButton = self.select_single(objectName='goToButton')
944+ self.pointing_device.click_object(editButton)
945
946=== removed file 'tests/autopilot/filemanager/emulators.py'
947--- tests/autopilot/filemanager/emulators.py 2014-07-15 21:55:29 +0000
948+++ tests/autopilot/filemanager/emulators.py 1970-01-01 00:00:00 +0000
949@@ -1,518 +0,0 @@
950-# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
951-#
952-# Copyright (C) 2013, 2014 Canonical Ltd.
953-#
954-# This program is free software; you can redistribute it and/or modify
955-# it under the terms of the GNU Lesser General Public License as published by
956-# the Free Software Foundation; version 3.
957-#
958-# This program is distributed in the hope that it will be useful,
959-# but WITHOUT ANY WARRANTY; without even the implied warranty of
960-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
961-# GNU Lesser General Public License for more details.
962-#
963-# You should have received a copy of the GNU Lesser General Public License
964-# along with this program. If not, see <http://www.gnu.org/licenses/>.
965-
966-"""File Manager app autopilot emulators."""
967-
968-import logging
969-import re
970-import time
971-
972-import autopilot.logging
973-from autopilot import input
974-from autopilot.introspection import dbus
975-from ubuntuuitoolkit import emulators as toolkit_emulators
976-
977-from filemanager import _common
978-
979-logger = logging.getLogger(__name__)
980-
981-
982-class MainView(toolkit_emulators.MainView):
983- """File Manager MainView Autopilot emulator."""
984-
985- @autopilot.logging.log_action(logger.info)
986- def go_to_place(self, object_name):
987- """Open one of the bookmarked place folders.
988-
989- :param object_name: The objectName property of the place to open.
990-
991- """
992- if self.showSidebar:
993- self._go_to_place_from_side_bar(object_name)
994- else:
995- self._go_to_place_from_popover(object_name)
996-
997- def _go_to_place_from_side_bar(self, object_name):
998- side_bar = self.get_folder_list_page().get_sidebar()
999- side_bar.go_to_place(object_name)
1000-
1001- def get_folder_list_page(self):
1002- """Return the FolderListPage emulator of the MainView."""
1003- page = self.wait_select_single(FolderListPage)
1004- page.main_view = self
1005- return page
1006-
1007- def _go_to_place_from_popover(self, object_name):
1008- popover = self.open_places()
1009- place = popover.wait_select_single('Standard', objectName=object_name)
1010- self.pointing_device.click_object(place)
1011-
1012- @autopilot.logging.log_action(logger.info)
1013- def open_places(self):
1014- if not self.showSidebar:
1015- self.open_toolbar().click_button('places')
1016- return self._get_places_popover()
1017- else:
1018- raise _common('The places popover cannot be opened on wide mode.')
1019-
1020- def _get_places_popover(self):
1021- """Return the Places popover."""
1022- # XXX It would be easier if the places popover was an object
1023- # that inherits from Popover, like the
1024- # ActionSelectionPopover does.
1025- # --elopio - 2013-07-25
1026- return self.wait_select_single('Popover', objectName='placesPopover')
1027-
1028- @autopilot.logging.log_action(logger.info)
1029- def rename(self, original_name, new_name):
1030- """Rename a file or directory.
1031-
1032- :param original_name: The name of the file or directory to rename.
1033- :param new_name: The new name to set for the file or directory.
1034-
1035- """
1036- actions_popover = self.open_actions(original_name)
1037- actions_popover.click_button_by_text('Rename')
1038- confirm_dialog = self.wait_select_single(ConfirmDialogWithInput)
1039- confirm_dialog.enter_text(new_name)
1040- confirm_dialog.ok()
1041-
1042- @autopilot.logging.log_action(logger.info)
1043- def open_actions(self, name):
1044- """Open the list of available actions of a file or directory."""
1045- folder_list_page = self.get_folder_list_page()
1046- folder_list_page.open_file_actions(name)
1047- actions_popover = self.get_action_selection_popover(
1048- 'fileActionsPopover')
1049- actions_popover.visible.wait_for(True)
1050- return actions_popover
1051-
1052- @autopilot.logging.log_action(logger.info)
1053- def delete(self, name):
1054- """Delete a file or directory.
1055-
1056- :param name: The name of the file or directory to delete.
1057-
1058- """
1059- actions_popover = self.open_actions(name)
1060- actions_popover.click_button_by_text('Delete')
1061- confirm_dialog = self.wait_select_single(ConfirmDialog)
1062- confirm_dialog.ok()
1063-
1064- def get_file_actions_popover(self):
1065- """Return the ActionSelectionPopover emulator of the file actions."""
1066- return self.get_action_selection_popover('fileActionsPopover')
1067-
1068- def get_folder_actions_popover(self):
1069- """Return the ActionSelectionPopover emulator of the folder actions."""
1070- return self.get_action_selection_popover('folderActionsPopover')
1071-
1072- def folder_actions_popover_exists(self):
1073- """Boolean, checks if the folder actions popover exists."""
1074- try:
1075- popover = self.get_folder_actions_popover()
1076- if popover:
1077- return True
1078- except:
1079- return False
1080-
1081- def file_actions_popover_exists(self):
1082- """Boolean, checks if the file actions popover exists."""
1083- try:
1084- popover = self.get_file_actions_popover()
1085- if popover:
1086- return True
1087- except:
1088- return False
1089-
1090- def get_file_details_popover(self):
1091- """Return the FileDetailsPopover emulator."""
1092- return self.wait_select_single(FileDetailsPopover)
1093-
1094- def get_file_action_dialog(self):
1095- """Return the FileActionDialog emulator."""
1096- return self.wait_select_single(FileActionDialog)
1097-
1098- def file_action_dialog_exists(self):
1099- """Boolean checks if the FileActionDialog exists."""
1100- dialog = self.select_many(FileActionDialog)
1101- if dialog == '[]':
1102- return True
1103- return False
1104-
1105- def get_confirm_dialog(self):
1106- """Return a confirm dialog emulator"""
1107- try:
1108- dialog = self.wait_select_single(ConfirmDialog)
1109- except dbus.StateNotFoundError:
1110- dialog = self.wait_select_single(ConfirmDialogWithInput)
1111- return dialog
1112-
1113- def confirm_dialog_exists(self):
1114- """Boolean checks if a confirm dialog exists"""
1115- dialog = self.select_many(ConfirmDialog)
1116- if dialog == '[]':
1117- dialog = self.select_many(ConfirmDialogWithInput)
1118- if dialog == '[]':
1119- return True
1120- return False
1121-
1122- def get_dialog(self):
1123- """Return a dialog emulator"""
1124- return self.wait_select_single(Dialog)
1125-
1126- def get_popover(self):
1127- """Return a popover emulator"""
1128- return self.wait_select_single(Popover)
1129-
1130-
1131-class PlacesSidebar(toolkit_emulators.UbuntuUIToolkitEmulatorBase):
1132- """PlacesSidebar Autopilot emulator."""
1133-
1134- @autopilot.logging.log_action(logger.info)
1135- def go_to_place(self, object_name):
1136- """Open one of the bookmarked place folders.
1137-
1138- :param object_name: The objectName property of the place to open.
1139-
1140- """
1141- place = self.select_single('Standard', objectName=object_name)
1142- self.pointing_device.click_object(place)
1143-
1144-
1145-class FolderListPage(toolkit_emulators.UbuntuUIToolkitEmulatorBase):
1146- """FolderListPage Autopilot emulator."""
1147-
1148- def open_file_actions(self, name):
1149- """Open the actions menu of a file or folder.
1150-
1151- :param name: The name of the file or folder.
1152-
1153- """
1154- delegate = self.get_file_by_name(name)
1155- delegate.open_actions_popover()
1156-
1157- def get_files_and_folders(self):
1158- """Return the list of files and folders of the opened directory.
1159-
1160- The list returned will contain the names of the files and folders.
1161-
1162- """
1163- if self.showingListView:
1164- view = self.select_single(FolderListView)
1165- else:
1166- view = self.select_single(FolderIconView)
1167- return view.get_files_and_folders()
1168-
1169- def get_number_of_files_from_list(self):
1170- """Return the number of files shown on the folder."""
1171- if self.showingListView:
1172- return len(self.select_many(FolderListDelegate))
1173- else:
1174- return len(self.select_many(FolderIconDelegate))
1175-
1176- def get_file_by_index(self, index):
1177- """Return the FolderListDelegate emulator of the file or folder.
1178-
1179- :parameter index: The index of file or folder.
1180-
1181- """
1182- if self.showingListView:
1183- file_ = self.select_many(FolderListDelegate)[index]
1184- else:
1185- file_ = self.select_many(FolderIconDelegate)[index]
1186- file_.list_view = self.select_single(FolderListView)
1187- return file_
1188-
1189- def get_file_by_name(self, name):
1190- """Return the FolderListDelegate emulator of the file or folder.
1191-
1192- :parameter name: The name of the file or folder.
1193-
1194- """
1195- files = self.select_many(FolderListDelegate)
1196- if not self.showingListView:
1197- files = self.select_many(FolderIconDelegate)
1198- for file_ in files:
1199- if file_.fileName == name:
1200- if self.showingListView:
1201- file_.list_view = self.select_single(FolderListView)
1202- else:
1203- file_.list_view = self.select_single(FolderIconView)
1204- return file_
1205- raise ValueError(
1206- 'File with name "{0}" not found.'.format(name))
1207-
1208- def get_current_path(self):
1209- """Get the path of the folder currently displayed."""
1210- if self.showingListView:
1211- return self.select_single(FolderListView).get_current_path()
1212- else:
1213- return self.select_single(FolderIconView).get_current_path()
1214-
1215- def get_number_of_files_from_header(self):
1216- if self.showingListView:
1217- return self.select_single(FolderListView).get_number_of_files()
1218- else:
1219- return self.select_single(FolderIconView).get_number_of_files()
1220-
1221- def get_sidebar(self):
1222- if self.main_view.showSidebar:
1223- return self.select_single(PlacesSidebar)
1224- else:
1225- raise ValueError(
1226- 'Places sidebar is hidden in small mode.')
1227-
1228- def get_pathbar(self):
1229- if self.main_view.showSidebar:
1230- return self.main_view.get_toolbar().select_single(PathBar)
1231- else:
1232- raise ValueError(
1233- 'Path bar is hidden in small mode.')
1234-
1235-
1236-class FolderListView(toolkit_emulators.UbuntuUIToolkitEmulatorBase):
1237- """FolderListView Autopilot emulator."""
1238-
1239- SPLIT_HEADER_REGEX = '(.+) \((\d+) \w+\)$'
1240- # Regular expression to split the header text. The header text has the form
1241- # /path/to/dir (# files). So with this expression, we can split the header
1242- # in two groups, (.+) will match the path and (\d+) the number of files.
1243-
1244- def get_current_path(self):
1245- path, _ = self._split_header_text()
1246- return path
1247-
1248- def _split_header_text(self):
1249- header_text = self.select_single(
1250- 'Header', objectName='listViewSmallHeader').text
1251- match = re.match(self.SPLIT_HEADER_REGEX, header_text)
1252- if match:
1253- path = match.group(1)
1254- number_of_files = match.group(2)
1255- return path, number_of_files
1256-
1257- def get_number_of_files(self):
1258- _, number_of_files = self._split_header_text()
1259- return int(number_of_files)
1260-
1261- def get_files_and_folders(self):
1262- """Return the list of files and folders of the opened directory."""
1263- list_delegates = self.select_many(FolderListDelegate)
1264- # sort by y, x
1265- list_delegates = sorted(
1266- list_delegates,
1267- key=lambda item: (item.globalRect.y, item.globalRect.x))
1268-
1269- return [item.fileName for item in list_delegates]
1270-
1271-
1272-class FolderIconView(toolkit_emulators.UbuntuUIToolkitEmulatorBase):
1273- """FolderListView Autopilot emulator."""
1274-
1275- SPLIT_HEADER_REGEX = '(.+) \((\d+) \w+\)$'
1276- # Regular expression to split the header text. The header text has the form
1277- # /path/to/dir (# files). So with this expression, we can split the header
1278- # in two groups, (.+) will match the path and (\d+) the number of files.
1279-
1280- def get_current_path(self):
1281- path, _ = self._split_header_text()
1282- return path
1283-
1284- def _split_header_text(self):
1285- header_text = self.select_single(
1286- 'Header', objectName='iconViewHeader').text
1287- match = re.match(self.SPLIT_HEADER_REGEX, header_text)
1288- if match:
1289- path = match.group(1)
1290- number_of_files = match.group(2)
1291- return path, number_of_files
1292-
1293- def get_number_of_files(self):
1294- _, number_of_files = self._split_header_text()
1295- return int(number_of_files)
1296-
1297- def get_files_and_folders(self):
1298- """Return the list of files and folders of the opened directory."""
1299- icon_delegates = self.select_many(FolderIconDelegate)
1300- # sort by y, x
1301- icon_delegates = sorted(
1302- icon_delegates,
1303- key=lambda icon: (icon.globalRect.y, icon.globalRect.x))
1304-
1305- return [icon.fileName for icon in icon_delegates]
1306-
1307-
1308-class FolderListDelegate(toolkit_emulators.UbuntuUIToolkitEmulatorBase):
1309- """FolderListPage Autopilot emulator.
1310-
1311- This is a file or folder on the FolderListPage.
1312-
1313- """
1314-
1315- def __init__(self, *args):
1316- super(FolderListDelegate, self).__init__(*args)
1317- self.pointing_device = toolkit_emulators.get_pointing_device()
1318-
1319- def open_directory(self):
1320- """Open the directory."""
1321- # TODO Check if it is a directory. If not, raise an error.
1322- # This is not currently possible because Autopilot is overwriting the
1323- # path attribute. Reported on
1324- # https://bugs.launchpad.net/autopilot/+bug/1205204
1325- # --elopio - 2013-07-25
1326- self.pointing_device.click_object(self)
1327-
1328- def open_file(self):
1329- # TODO For this we would need to access the FileActionDialog that's
1330- # child of the MainView, but that's not currently possible with
1331- # autopilot. Reported on
1332- # bug https://bugs.launchpad.net/autopilot/+bug/1195141
1333- # --elopio - 2013-07-25
1334- raise NotImplementedError()
1335-
1336- def open_actions_popover(self):
1337- """Open the actions popover of the file or folder."""
1338- self.pointing_device.move_to_object(self)
1339- self.pointing_device.press()
1340- time.sleep(2)
1341- self.pointing_device.release()
1342-
1343-
1344-class FolderIconDelegate(toolkit_emulators.UbuntuUIToolkitEmulatorBase):
1345- """FolderIconPage Autopilot emulator.
1346-
1347- This is a file or folder on the FolderListPage.
1348-
1349- """
1350-
1351- def __init__(self, *args):
1352- super(FolderIconDelegate, self).__init__(*args)
1353- self.pointing_device = toolkit_emulators.get_pointing_device()
1354-
1355- def open_directory(self):
1356- """Open the directory."""
1357- # TODO Check if it is a directory. If not, raise an error.
1358- # This is not currently possible because Autopilot is overwriting the
1359- # path attribute. Reported on
1360- # https://bugs.launchpad.net/autopilot/+bug/1205204
1361- # --elopio - 2013-07-25
1362- self.pointing_device.click_object(self)
1363-
1364- def open_file(self):
1365- # TODO For this we would need to access the FileActionDialog that's
1366- # child of the MainView, but that's not currently possible with
1367- # autopilot. Reported on
1368- # bug https://bugs.launchpad.net/autopilot/+bug/1195141
1369- # --elopio - 2013-07-25
1370- raise NotImplementedError
1371-
1372- def open_actions_popover(self):
1373- """Open the actions popover of the file or folder."""
1374- self.pointing_device.move_to_object(self)
1375- self.pointing_device.press()
1376- time.sleep(2)
1377- self.pointing_device.release()
1378-
1379-
1380-class FileActionDialog(toolkit_emulators.UbuntuUIToolkitEmulatorBase):
1381- """FileActionDialog Autopilot emulator."""
1382-
1383- def __init__(self, *args):
1384- super(FileActionDialog, self).__init__(*args)
1385- self.pointing_device = toolkit_emulators.get_pointing_device()
1386-
1387- def open(self):
1388- open_button = self.select_single('Button', objectName='openButton')
1389- self.pointing_device.click_object(open_button)
1390-
1391- def cancel(self):
1392- cancel_button = self.select_single('Button', objectName='cancelButton')
1393- self.pointing_device.click_object(cancel_button)
1394-
1395-
1396-class ConfirmDialog(toolkit_emulators.UbuntuUIToolkitEmulatorBase):
1397- """ConfirmDialog Autopilot emulator."""
1398-
1399- def __init__(self, *args):
1400- super(ConfirmDialog, self).__init__(*args)
1401- self.pointing_device = toolkit_emulators.get_pointing_device()
1402-
1403- def ok(self):
1404- okButton = self.select_single('Button', objectName='okButton')
1405- self.pointing_device.click_object(okButton)
1406-
1407- def cancel(self):
1408- cancel_button = self.select_single('Button', objectName='cancelButton')
1409- self.pointing_device.click_object(cancel_button)
1410-
1411-
1412-class ConfirmDialogWithInput(ConfirmDialog):
1413- """ConfirmDialogWithInput Autopilot emulator."""
1414-
1415- def __init__(self, *args):
1416- super(ConfirmDialogWithInput, self).__init__(*args)
1417- self.keyboard = input.Keyboard.create()
1418-
1419- def enter_text(self, text, clear=True):
1420- text_field = self._select_text_field()
1421- text_field.write(text, clear)
1422-
1423- def _select_text_field(self):
1424- return self.select_single(
1425- toolkit_emulators.TextField, objectName='inputField')
1426-
1427-
1428-class Dialog(ConfirmDialogWithInput):
1429- """Dialog Autopilot emulator."""
1430-
1431-
1432-class Popover(ConfirmDialogWithInput):
1433- """Popover Autopilot emulator, containing buttons and an inputfield"""
1434-
1435- def click_button(self, text):
1436- """Click a button on the popover.
1437-
1438- XXX We are receiving the text because there's no way to set the
1439- objectName on the action. This is reported at
1440- https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1205144
1441- --elopio - 2013-07-25
1442-
1443- :parameter text: The text of the button.
1444-
1445- """
1446- button = self._get_button(text)
1447- self.pointing_device.click_object(button)
1448-
1449- def _get_button(self, text):
1450- buttons = self.select_many('Empty')
1451- for button in buttons:
1452- if button.text == text:
1453- return button
1454-
1455-
1456-class FileDetailsPopover(toolkit_emulators.UbuntuUIToolkitEmulatorBase):
1457- """FileDetailsPopover Autopilot emulator."""
1458-
1459- def get_path(self):
1460- return self.select_single('Label', objectName='pathLabel').text
1461-
1462-
1463-class PathBar(toolkit_emulators.UbuntuUIToolkitEmulatorBase):
1464-
1465- def go_to_location(self):
1466- editButton = self.select_single(objectName='goToButton')
1467- self.pointing_device.click_object(editButton)
1468
1469=== modified file 'tests/autopilot/filemanager/tests/__init__.py'
1470--- tests/autopilot/filemanager/tests/__init__.py 2014-08-13 04:03:32 +0000
1471+++ tests/autopilot/filemanager/tests/__init__.py 2014-09-25 21:51:25 +0000
1472@@ -19,36 +19,30 @@
1473 import logging
1474 import os
1475 import shutil
1476+import tempfile
1477
1478 import fixtures
1479 from autopilot import logging as autopilot_logging
1480 from filemanager import CMakePluginParser
1481
1482-from autopilot.input import Mouse, Touch, Pointer
1483 from autopilot.matchers import Eventually
1484-from autopilot.platform import model
1485 from autopilot.testcase import AutopilotTestCase
1486 from testtools.matchers import Equals
1487-from ubuntuuitoolkit import (
1488- emulators as toolkit_emulators,
1489- fixture_setup as toolkit_fixtures
1490-)
1491+import ubuntuuitoolkit
1492
1493-from filemanager import emulators, fixture_setup
1494+import filemanager
1495+from filemanager import fixture_setup as fm_fixtures
1496+from gi.repository import Click
1497
1498 logger = logging.getLogger(__name__)
1499
1500
1501-class FileManagerTestCase(AutopilotTestCase):
1502+class BaseTestCaseWithPatchedHome(AutopilotTestCase):
1503
1504 """A common test case class that provides several useful methods for
1505 filemanager-app tests.
1506
1507 """
1508- if model() == 'Desktop':
1509- scenarios = [('with mouse', dict(input_device_class=Mouse))]
1510- else:
1511- scenarios = [('with touch', dict(input_device_class=Touch))]
1512
1513 def get_launcher_and_type(self):
1514 if os.path.exists(self.local_location_binary):
1515@@ -63,24 +57,25 @@
1516 return launcher, test_type
1517
1518 def setUp(self):
1519- self.EXEC = 'filemanager'
1520+ self.binary = 'filemanager'
1521 self.source_dir = os.path.dirname(
1522 os.path.dirname(os.path.abspath('.')))
1523 self.build_dir = self._get_build_dir()
1524+
1525 self.local_location = self.build_dir
1526 self.local_location_qml = os.path.join(self.build_dir,
1527 'src', 'app',
1528- 'qml', self.EXEC + '.qml')
1529+ 'qml', self.binary + '.qml')
1530 self.local_location_binary = os.path.join(self.build_dir,
1531- 'src', 'app', self.EXEC)
1532- self.installed_location_binary = os.path.join('/usr/bin/', self.EXEC)
1533+ 'src', 'app', self.binary)
1534+ self.installed_location_binary = os.path.join('/usr/bin/', self.binary)
1535 self.installed_location_qml = \
1536 '/usr/share/filemanager/qml/filemanager.qml'
1537
1538- launcher, self.test_type = self.get_launcher_and_type()
1539+ super(BaseTestCaseWithPatchedHome, self).setUp()
1540+ self.launcher, self.test_type = self.get_launcher_and_type()
1541+ self.real_home_dir = os.environ.get('HOME')
1542 self.home_dir = self._patch_home()
1543- self.pointing_device = Pointer(self.input_device_class.create())
1544- super(FileManagerTestCase, self).setUp()
1545
1546 self.original_file_count = \
1547 len([i for i in os.listdir(self.home_dir)
1548@@ -89,8 +84,6 @@
1549 os.listdir(self.home_dir))
1550 logger.debug('File count in HOME is %s' % self.original_file_count)
1551
1552- self.app = launcher()
1553-
1554 def _get_build_dir(self):
1555 """
1556 Returns the build dir after having parsed the CMake config file
1557@@ -115,7 +108,7 @@
1558 self.local_location_binary,
1559 '-q', self.local_location_qml,
1560 app_type='qt',
1561- emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
1562+ emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
1563
1564 @autopilot_logging.log_action(logger.info)
1565 def launch_test_installed(self):
1566@@ -123,52 +116,104 @@
1567 self.installed_location_binary,
1568 '-q', self.installed_location_qml,
1569 app_type='qt',
1570- emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
1571+ emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
1572
1573 @autopilot_logging.log_action(logger.info)
1574 def launch_test_click(self):
1575- return self.launch_click_package(
1576- 'com.ubuntu.filemanager',
1577- emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
1578+ # We need to pass the "--forceAuth false" argument to the filemanager
1579+ # binary, but ubuntu-app-launch doesn't pass arguments to the exec line
1580+ # on the desktop file. So we make a test desktop file that has the
1581+ # "--forceAuth false" on the exec line.
1582+ desktop_file_path = self.write_sandbox_desktop_file()
1583+ desktop_file_name = os.path.basename(desktop_file_path)
1584+ application_name, _ = os.path.splitext(desktop_file_name)
1585+ return self.launch_upstart_application(
1586+ application_name,
1587+ emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
1588+
1589+ def write_sandbox_desktop_file(self):
1590+ desktop_file_dir = self.get_local_desktop_file_directory()
1591+ desktop_file = self.get_named_temporary_file(
1592+ suffix='.desktop', dir=desktop_file_dir)
1593+ desktop_file.write('[Desktop Entry]\n')
1594+ version, installed_path = self.get_installed_version_and_directory()
1595+ filemanager_sandbox_exec = (
1596+ 'aa-exec-click -p com.ubuntu.filemanager_filemanager_{}'
1597+ ' -- filemanager --forceAuth false'.format(version))
1598+ desktop_file_dict = {
1599+ 'Type': 'Application',
1600+ 'Name': 'filemanager',
1601+ 'Exec': filemanager_sandbox_exec,
1602+ 'Icon': 'Not important',
1603+ 'Path': installed_path
1604+ }
1605+ for key, value in desktop_file_dict.items():
1606+ desktop_file.write('{key}={value}\n'.format(key=key, value=value))
1607+ desktop_file.close()
1608+ logger.debug(filemanager_sandbox_exec)
1609+ for key, value in desktop_file_dict.items():
1610+ logger.debug("%s: %s" % (key, value))
1611+ return desktop_file.name
1612+
1613+ def get_local_desktop_file_directory(self):
1614+ return os.path.join(
1615+ self.real_home_dir, '.local', 'share', 'applications')
1616+
1617+ def get_named_temporary_file(
1618+ self, dir=None, mode='w+t', delete=False, suffix=''):
1619+ # Discard files with underscores which look like an APP_ID to Unity
1620+ # See https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1329141
1621+ chars = tempfile._RandomNameSequence.characters.strip("_")
1622+ tempfile._RandomNameSequence.characters = chars
1623+ return tempfile.NamedTemporaryFile(
1624+ dir=dir, mode=mode, delete=delete, suffix=suffix)
1625+
1626+ def get_installed_version_and_directory(self):
1627+ db = Click.DB()
1628+ db.read()
1629+ package_name = 'com.ubuntu.filemanager'
1630+ registry = Click.User.for_user(db, name=os.environ.get('USER'))
1631+ version = registry.get_version(package_name)
1632+ directory = registry.get_path(package_name)
1633+ return version, directory
1634
1635 def _copy_xauthority_file(self, directory):
1636- """Copy .Xauthority file to directory, if it exists in /home"""
1637- xauth = os.path.join(os.environ.get('HOME'), '.Xauthority')
1638+ """ Copy .Xauthority file to directory, if it exists in /home
1639+ """
1640+ # If running under xvfb, as jenkins does,
1641+ # xsession will fail to start without xauthority file
1642+ # Thus if the Xauthority file is in the home directory
1643+ # make sure we copy it to our temp home directory
1644+
1645+ xauth = os.path.expanduser(os.path.join(os.environ.get('HOME'),
1646+ '.Xauthority'))
1647 if os.path.isfile(xauth):
1648- logger.debug("Copying .Xauthority to " + directory)
1649+ logger.debug("Copying .Xauthority to %s" % directory)
1650 shutil.copyfile(
1651- os.path.join(os.environ.get('HOME'), '.Xauthority'),
1652+ os.path.expanduser(os.path.join(os.environ.get('HOME'),
1653+ '.Xauthority')),
1654 os.path.join(directory, '.Xauthority'))
1655
1656 def _patch_home(self):
1657- """mock /home for testing purposes to preserve user data"""
1658+ """ mock /home for testing purposes to preserve user data
1659+ """
1660 temp_dir_fixture = fixtures.TempDir()
1661 self.useFixture(temp_dir_fixture)
1662 temp_dir = temp_dir_fixture.path
1663+ temp_xdg_config_home = os.path.join(temp_dir, '.config')
1664
1665- # If running under xvfb, as jenkins does,
1666- # xsession will fail to start without xauthority file
1667- # Thus if the Xauthority file is in the home directory
1668- # make sure we copy it to our temp home directory
1669+ # before we set fixture, copy xauthority if needed
1670 self._copy_xauthority_file(temp_dir)
1671
1672- # click requires using initctl env (upstart), but the desktop can set
1673- # an environment variable instead
1674- if self.test_type == 'click':
1675- self.useFixture(toolkit_fixtures.InitctlEnvironmentVariable(
1676- HOME=temp_dir))
1677- else:
1678- self.useFixture(fixtures.EnvironmentVariable('HOME',
1679- newvalue=temp_dir))
1680-
1681- logger.debug('Patched home to fake home directory ' + temp_dir)
1682-
1683+ self.useFixture(
1684+ fixtures.EnvironmentVariable('HOME', newvalue=temp_dir))
1685+ self.useFixture(
1686+ fixtures.EnvironmentVariable(
1687+ 'XDG_CONFIG_HOME', newvalue=temp_xdg_config_home))
1688+
1689+ logger.debug("Patched home to fake home directory %s" % temp_dir)
1690 return temp_dir
1691
1692- @property
1693- def main_view(self):
1694- return self.app.wait_select_single(emulators.MainView)
1695-
1696 def make_file_in_home(self):
1697 return self.make_content_in_home('file')
1698
1699@@ -179,11 +224,11 @@
1700 if type_ != 'file' and type_ != 'directory':
1701 raise ValueError('Unknown content type: "{0}"', type_)
1702 if type_ == 'file':
1703- temp_file = fixture_setup.TemporaryFileInDirectory(self.home_dir)
1704+ temp_file = fm_fixtures.TemporaryFileInDirectory(self.home_dir)
1705 self.useFixture(temp_file)
1706 path = temp_file.path
1707 else:
1708- temp_dir = fixture_setup.TemporaryDirectoryInDirectory(
1709+ temp_dir = fm_fixtures.TemporaryDirectoryInDirectory(
1710 self.home_dir)
1711 self.useFixture(temp_dir)
1712 path = temp_dir.path
1713@@ -195,10 +240,19 @@
1714 def _assert_number_of_files(self, expected_number_of_files, home=True):
1715 if home:
1716 expected_number_of_files += self.original_file_count
1717- folder_list_page = self.main_view.get_folder_list_page()
1718+ folder_list_page = self.app.main_view.get_folder_list_page()
1719 self.assertThat(
1720 folder_list_page.get_number_of_files_from_list,
1721 Eventually(Equals(expected_number_of_files), timeout=60))
1722 self.assertThat(
1723 folder_list_page.get_number_of_files_from_header,
1724 Eventually(Equals(expected_number_of_files), timeout=60))
1725+
1726+
1727+class FileManagerTestCase(BaseTestCaseWithPatchedHome):
1728+
1729+ """Base test case that launches the filemanager-app."""
1730+
1731+ def setUp(self):
1732+ super(FileManagerTestCase, self).setUp()
1733+ self.app = filemanager.Filemanager(self.launcher(), self.test_type)
1734
1735=== modified file 'tests/autopilot/filemanager/tests/test_context_menu.py'
1736--- tests/autopilot/filemanager/tests/test_context_menu.py 2014-08-13 03:37:20 +0000
1737+++ tests/autopilot/filemanager/tests/test_context_menu.py 2014-09-25 21:51:25 +0000
1738@@ -15,15 +15,14 @@
1739 # along with this program. If not, see <http://www.gnu.org/licenses/>.
1740
1741 import os
1742-
1743-from filemanager import tests
1744-
1745-
1746-class ContextMenuTestCase(tests.FileManagerTestCase):
1747+from filemanager.tests import FileManagerTestCase
1748+
1749+
1750+class ContextMenuTestCase(FileManagerTestCase):
1751 """Test cases for the context menu of the file manager app."""
1752
1753 def get_current_directory_files_and_folders(self):
1754- folder_list_page = self.main_view.get_folder_list_page()
1755+ folder_list_page = self.app.main_view.get_folder_list_page()
1756 return folder_list_page.get_files_and_folders()
1757
1758 def test_rename_directory(self):
1759@@ -36,7 +35,7 @@
1760 original_directory = os.path.basename(self.make_directory_in_home())
1761 new_name = original_directory + 'edit'
1762
1763- self.main_view.rename(original_directory, new_name)
1764+ self.app.main_view.rename(original_directory, new_name)
1765
1766 files_and_folders = self.get_current_directory_files_and_folders()
1767 self.assertEquals(files_and_folders, [new_name])
1768@@ -50,7 +49,7 @@
1769 original_file = os.path.basename(self.make_file_in_home())
1770 new_name = original_file + 'edit'
1771
1772- self.main_view.rename(original_file, new_name)
1773+ self.app.main_view.rename(original_file, new_name)
1774
1775 files_and_folders = self.get_current_directory_files_and_folders()
1776 self.assertEquals(files_and_folders, [new_name])
1777@@ -64,7 +63,7 @@
1778 """
1779 dir_name = os.path.basename(self.make_directory_in_home())
1780
1781- self.main_view.delete(dir_name)
1782+ self.app.main_view.delete(dir_name)
1783
1784 files_and_folders = self.get_current_directory_files_and_folders()
1785 self.assertEquals(files_and_folders, [])
1786@@ -77,7 +76,7 @@
1787 """
1788 file_name = os.path.basename(self.make_file_in_home())
1789
1790- self.main_view.delete(file_name)
1791+ self.app.main_view.delete(file_name)
1792
1793 files_and_folders = self.get_current_directory_files_and_folders()
1794 self.assertEquals(files_and_folders, [])
1795
1796=== modified file 'tests/autopilot/filemanager/tests/test_filemanager.py'
1797--- tests/autopilot/filemanager/tests/test_filemanager.py 2014-06-26 06:19:38 +0000
1798+++ tests/autopilot/filemanager/tests/test_filemanager.py 2014-09-25 21:51:25 +0000
1799@@ -34,7 +34,7 @@
1800 class TestFolderListPage(FileManagerTestCase):
1801
1802 def _get_file_by_name(self, name):
1803- folder_list_page = self.main_view.get_folder_list_page()
1804+ folder_list_page = self.app.main_view.get_folder_list_page()
1805 fileDelegate = lambda: folder_list_page.get_file_by_name(name)
1806 self.assertThat(
1807 fileDelegate,
1808@@ -42,7 +42,7 @@
1809 return folder_list_page.get_file_by_name(name)
1810
1811 def _get_file_by_index(self, index):
1812- folder_list_page = self.main_view.get_folder_list_page()
1813+ folder_list_page = self.app.main_view.get_folder_list_page()
1814 fileDelegate = lambda: folder_list_page.get_file_by_index(index)
1815 self.assertThat(
1816 fileDelegate,
1817@@ -54,15 +54,15 @@
1818 # on wide UI display, we get the location dialog
1819 # on phone UI display, we get places popover
1820 device = model()
1821- if self.main_view.showSidebar:
1822+ if self.app.main_view.showSidebar:
1823 logger.debug("Using goto to goto %s on %s" % (location, device))
1824- (self.main_view.get_folder_list_page().get_pathbar()
1825+ (self.app.main_view.get_folder_list_page().get_pathbar()
1826 .go_to_location())
1827- goto_location = self.main_view.get_dialog()
1828+ goto_location = self.app.main_view.get_dialog()
1829 else:
1830 logger.debug("Using places to goto %s on %s" % (location, device))
1831- self._safe_open_popover(self.main_view.open_places)
1832- goto_location = self.main_view.get_popover()
1833+ self._safe_open_popover(self.app.main_view.open_places)
1834+ goto_location = self.app.main_view.get_popover()
1835 goto_location.enter_text(location)
1836 goto_location.ok()
1837
1838@@ -71,7 +71,7 @@
1839 list_view = item.list_view
1840
1841 # item.open_directory()
1842- self.pointing_device.click_object(item)
1843+ self.app.pointing_device.click_object(item)
1844 self.assertThat(
1845 list_view.get_current_path, Eventually(Equals(expected_path)))
1846
1847@@ -79,12 +79,12 @@
1848 """Boolean, checks if popover exists."""
1849 try:
1850 popover = \
1851- self.main_view.wait_select_single('ActionSelectionPopover')
1852+ self.app.main_view.wait_select_single('ActionSelectionPopover')
1853 if popover:
1854 return True
1855 except:
1856 try:
1857- popover = self.main_view.wait_select_single('Popover')
1858+ popover = self.app.main_view.wait_select_single('Popover')
1859 if popover:
1860 return True
1861 except:
1862@@ -101,15 +101,15 @@
1863 def _do_action_on_file(self, file_, action):
1864 logger.debug("Performing %s on file %s" % (action, file_))
1865 self._safe_open_popover(file_.open_actions_popover)
1866- file_actions_popover = self.main_view.get_file_actions_popover()
1867+ file_actions_popover = self.app.main_view.get_file_actions_popover()
1868 file_actions_popover.click_button_by_text(action)
1869
1870 def _cancel_confirm_dialog(self):
1871- confirm_dialog = self.main_view.get_confirm_dialog()
1872+ confirm_dialog = self.app.main_view.get_confirm_dialog()
1873 confirm_dialog.cancel()
1874
1875 def _confirm_dialog(self, text=None):
1876- confirm_dialog = self.main_view.get_confirm_dialog()
1877+ confirm_dialog = self.app.main_view.get_confirm_dialog()
1878 if text:
1879 confirm_dialog.enter_text(text)
1880 confirm_dialog.ok()
1881@@ -122,9 +122,9 @@
1882 self.make_file_in_home()
1883
1884 first_file = self._get_file_by_index(0)
1885- self.pointing_device.click_object(first_file)
1886+ self.app.pointing_device.click_object(first_file)
1887
1888- dialog = self.main_view.get_file_action_dialog()
1889+ dialog = self.app.main_view.get_file_action_dialog()
1890 dialog.visible.wait_for(True)
1891
1892 process_manager = process.ProcessManager.create()
1893@@ -132,7 +132,7 @@
1894
1895 dialog.open()
1896 # make sure the dialog is open
1897- self.main_view.get_file_action_dialog()
1898+ self.app.main_view.get_file_action_dialog()
1899 # Filtering copied from
1900 # AutopilotTestCase._compare_system_with_app_snapshot.
1901 current_apps = self.process_manager.get_running_applications()
1902@@ -158,7 +158,7 @@
1903
1904 self._open_directory(first_dir)
1905
1906- folder_list_page = self.main_view.get_folder_list_page()
1907+ folder_list_page = self.app.main_view.get_folder_list_page()
1908 self.assertThat(
1909 folder_list_page.get_current_path, Eventually(Equals(dir_path)))
1910 self._assert_number_of_files(0, home=False)
1911@@ -188,7 +188,8 @@
1912 self._cancel_confirm_dialog()
1913
1914 self.assertThat(
1915- self.main_view.confirm_dialog_exists, Eventually(Equals(False)))
1916+ self.app.main_view.confirm_dialog_exists,
1917+ Eventually(Equals(False)))
1918 self.assertThat(
1919 lambda: first_dir.fileName, Eventually(Equals(dir_name)))
1920
1921@@ -201,7 +202,8 @@
1922 self._cancel_confirm_dialog()
1923
1924 self.assertThat(
1925- self.main_view.confirm_dialog_exists, Eventually(Equals(False)))
1926+ self.app.main_view.confirm_dialog_exists,
1927+ Eventually(Equals(False)))
1928 self.assertThat(
1929 lambda: first_file.fileName,
1930 Eventually(Equals(file_name)))
1931@@ -228,11 +230,11 @@
1932 dir_name = 'Test Directory'
1933
1934 open_popover = lambda: \
1935- self.main_view.open_toolbar().click_button('actions')
1936+ self.app.main_view.open_toolbar().click_button('actions')
1937 self._safe_open_popover(open_popover)
1938
1939- folder_actions_popover = self.main_view.get_folder_actions_popover()
1940- folder_actions_popover.click_button_by_text('Create New Folder')
1941+ folder_popover = self.app.main_view.get_folder_actions_popover()
1942+ folder_popover.click_button_by_text('Create New Folder')
1943 self._confirm_dialog(dir_name)
1944
1945 self._assert_number_of_files(1)
1946@@ -242,11 +244,11 @@
1947
1948 def test_cancel_create_directory(self):
1949 open_popover = lambda: \
1950- self.main_view.open_toolbar().click_button('actions')
1951+ self.app.main_view.open_toolbar().click_button('actions')
1952 self._safe_open_popover(open_popover)
1953
1954- folder_actions_popover = self.main_view.get_folder_actions_popover()
1955- folder_actions_popover.click_button_by_text('Create New Folder')
1956+ folder_popover = self.app.main_view.get_folder_actions_popover()
1957+ folder_popover.click_button_by_text('Create New Folder')
1958 self._cancel_confirm_dialog()
1959
1960 self._assert_number_of_files(0)
1961@@ -257,7 +259,7 @@
1962 first_dir = self._get_file_by_name(dir_name)
1963
1964 self._do_action_on_file(first_dir, 'Properties')
1965- file_details_popover = self.main_view.get_file_details_popover()
1966+ file_details_popover = self.app.main_view.get_file_details_popover()
1967 self.assertThat(file_details_popover.visible, Eventually(Equals(True)))
1968 self.assertThat(
1969 file_details_popover.get_path, Eventually(Equals(dir_path)))
1970@@ -271,7 +273,7 @@
1971 first_file = self._get_file_by_name(file_name)
1972
1973 self._do_action_on_file(first_file, 'Properties')
1974- file_details_popover = self.main_view.get_file_details_popover()
1975+ file_details_popover = self.app.main_view.get_file_details_popover()
1976 self.assertThat(file_details_popover.visible, Eventually(Equals(True)))
1977 self.assertThat(
1978 file_details_popover.get_path, Eventually(Equals(file_path)))
1979@@ -287,7 +289,7 @@
1980 dir_to_copy_name = os.path.basename(dir_to_copy_path)
1981 os.mkdir(dir_to_copy_path)
1982
1983- folder_list_page = self.main_view.get_folder_list_page()
1984+ folder_list_page = self.app.main_view.get_folder_list_page()
1985 self._assert_number_of_files(2)
1986
1987 # Copy the directory.
1988@@ -301,13 +303,13 @@
1989
1990 # Paste the directory.
1991 open_popover = lambda: \
1992- self.main_view.open_toolbar().click_button('actions')
1993+ self.app.main_view.open_toolbar().click_button('actions')
1994 self._safe_open_popover(open_popover)
1995
1996- folder_actions_popover = self.main_view.get_folder_actions_popover()
1997- folder_actions_popover.click_button_by_text('Paste 1 File')
1998+ folder_popover = self.app.main_view.get_folder_actions_popover()
1999+ folder_popover.click_button_by_text('Paste 1 File')
2000 self.assertThat(
2001- self.main_view.folder_actions_popover_exists,
2002+ self.app.main_view.folder_actions_popover_exists,
2003 Eventually(Equals(False)))
2004
2005 # Check that the directory is there.
2006@@ -317,7 +319,7 @@
2007 first_dir.fileName, Eventually(Equals(dir_to_copy_name)))
2008
2009 # Go back.
2010- toolbar = self.main_view.open_toolbar()
2011+ toolbar = self.app.main_view.open_toolbar()
2012 toolbar.click_button('up')
2013
2014 # Check that the directory is still there.
2015@@ -333,7 +335,7 @@
2016 dir_to_cut_name = os.path.basename(dir_to_cut_path)
2017 os.mkdir(dir_to_cut_path)
2018
2019- folder_list_page = self.main_view.get_folder_list_page()
2020+ folder_list_page = self.app.main_view.get_folder_list_page()
2021 self._assert_number_of_files(2)
2022
2023 # Cut the directory.
2024@@ -347,13 +349,13 @@
2025
2026 # Paste the directory.
2027 open_popover = lambda: \
2028- self.main_view.open_toolbar().click_button('actions')
2029+ self.app.main_view.open_toolbar().click_button('actions')
2030 self._safe_open_popover(open_popover)
2031
2032- folder_actions_popover = self.main_view.get_folder_actions_popover()
2033- folder_actions_popover.click_button_by_text('Paste 1 File')
2034+ folder_popover = self.app.main_view.get_folder_actions_popover()
2035+ folder_popover.click_button_by_text('Paste 1 File')
2036 self.assertThat(
2037- self.main_view.folder_actions_popover_exists,
2038+ self.app.main_view.folder_actions_popover_exists,
2039 Eventually(Equals(False)))
2040
2041 # Check that the directory is there.
2042@@ -363,7 +365,7 @@
2043 first_dir.fileName, Eventually(Equals(dir_to_cut_name)))
2044
2045 # Go back.
2046- toolbar = self.main_view.open_toolbar()
2047+ toolbar = self.app.main_view.open_toolbar()
2048 toolbar.click_button('up')
2049
2050 # Check that the directory is not there.
2051@@ -379,7 +381,7 @@
2052 file_to_copy_path = self.make_file_in_home()
2053 file_to_copy_name = os.path.basename(file_to_copy_path)
2054
2055- folder_list_page = self.main_view.get_folder_list_page()
2056+ folder_list_page = self.app.main_view.get_folder_list_page()
2057 self._assert_number_of_files(2)
2058
2059 # Copy the file.
2060@@ -393,14 +395,14 @@
2061
2062 # Paste the file.
2063 open_popover = lambda: \
2064- self.main_view.open_toolbar().click_button('actions')
2065+ self.app.main_view.open_toolbar().click_button('actions')
2066 self._safe_open_popover(open_popover)
2067
2068- folder_actions_popover = self.main_view.get_folder_actions_popover()
2069- folder_actions_popover.click_button_by_text('Paste 1 File')
2070+ folder_popover = self.app.main_view.get_folder_actions_popover()
2071+ folder_popover.click_button_by_text('Paste 1 File')
2072
2073 self.assertThat(
2074- self.main_view.folder_actions_popover_exists,
2075+ self.app.main_view.folder_actions_popover_exists,
2076 Eventually(Equals(False)))
2077
2078 # Check that the file is there.
2079@@ -410,7 +412,7 @@
2080 first_dir.fileName, Eventually(Equals(file_to_copy_name)))
2081
2082 # Go back.
2083- toolbar = self.main_view.open_toolbar()
2084+ toolbar = self.app.main_view.open_toolbar()
2085 toolbar.click_button('up')
2086
2087 # Check that the file is still there.
2088@@ -426,7 +428,7 @@
2089 file_to_cut_path = self.make_file_in_home()
2090 file_to_cut_name = os.path.basename(file_to_cut_path)
2091
2092- folder_list_page = self.main_view.get_folder_list_page()
2093+ folder_list_page = self.app.main_view.get_folder_list_page()
2094 self._assert_number_of_files(2)
2095
2096 # Cut the file.
2097@@ -440,13 +442,13 @@
2098
2099 # Paste the file.
2100 open_popover = lambda: \
2101- self.main_view.open_toolbar().click_button('actions')
2102+ self.app.main_view.open_toolbar().click_button('actions')
2103 self._safe_open_popover(open_popover)
2104
2105- folder_actions_popover = self.main_view.get_folder_actions_popover()
2106- folder_actions_popover.click_button_by_text('Paste 1 File')
2107+ folder_popover = self.app.main_view.get_folder_actions_popover()
2108+ folder_popover.click_button_by_text('Paste 1 File')
2109 self.assertThat(
2110- self.main_view.folder_actions_popover_exists,
2111+ self.app.main_view.folder_actions_popover_exists,
2112 Eventually(Equals(False)))
2113
2114 # Check that the file is there.
2115@@ -456,7 +458,7 @@
2116 first_dir.fileName, Eventually(Equals(file_to_cut_name)))
2117
2118 # Go back.
2119- toolbar = self.main_view.open_toolbar()
2120+ toolbar = self.app.main_view.open_toolbar()
2121 toolbar.click_button('up')
2122
2123 # Check that the file is not there.
2124@@ -470,10 +472,10 @@
2125 first_dir = self._get_file_by_name(dir_name)
2126 self._open_directory(first_dir)
2127
2128- toolbar = self.main_view.open_toolbar()
2129+ toolbar = self.app.main_view.open_toolbar()
2130 toolbar.click_button('up')
2131
2132- folder_list_page = self.main_view.get_folder_list_page()
2133+ folder_list_page = self.app.main_view.get_folder_list_page()
2134 self.assertThat(
2135 folder_list_page.get_current_path,
2136 Eventually(Equals(self.home_dir)))
2137
2138=== modified file 'tests/autopilot/filemanager/tests/test_places.py'
2139--- tests/autopilot/filemanager/tests/test_places.py 2014-06-22 16:51:44 +0000
2140+++ tests/autopilot/filemanager/tests/test_places.py 2014-09-25 21:51:25 +0000
2141@@ -17,26 +17,26 @@
2142 from autopilot.matchers import Eventually
2143 from testtools.matchers import Equals
2144
2145-from filemanager import tests
2146-
2147-
2148-class PlacesTestCase(tests.FileManagerTestCase):
2149+from filemanager.tests import FileManagerTestCase
2150+
2151+
2152+class PlacesTestCase(FileManagerTestCase):
2153 """Test cases for the places section of the file manager app."""
2154
2155 def test_go_home_must_open_the_home_directory(self):
2156 """Test that opens the Home bookmark from the places section."""
2157- self.main_view.go_to_place('placeHome')
2158+ self.app.main_view.go_to_place('placeHome')
2159
2160- folder_list_page = self.main_view.get_folder_list_page()
2161+ folder_list_page = self.app.main_view.get_folder_list_page()
2162 self.assertThat(
2163 folder_list_page.get_current_path,
2164 Eventually(Equals(self.home_dir)))
2165
2166 def test_go_to_root_must_open_the_root_directory(self):
2167 """Test that opens the Device bookmark from the places section."""
2168- self.main_view.go_to_place('placeDevice')
2169+ self.app.main_view.go_to_place('placeDevice')
2170
2171- folder_list_page = self.main_view.get_folder_list_page()
2172+ folder_list_page = self.app.main_view.get_folder_list_page()
2173 self.assertThat(
2174 folder_list_page.get_current_path,
2175 Eventually(Equals('/')))

Subscribers

People subscribed via source and target branches