Merge lp:~diegosarmentero/ubuntuone-control-panel/search-shared-files into lp:ubuntuone-control-panel

Proposed by Diego Sarmentero
Status: Merged
Approved by: Diego Sarmentero
Approved revision: 374
Merged at revision: 373
Proposed branch: lp:~diegosarmentero/ubuntuone-control-panel/search-shared-files
Merge into: lp:ubuntuone-control-panel
Diff against target: 623 lines (+130/-197)
8 files modified
ubuntuone/controlpanel/backend.py (+7/-0)
ubuntuone/controlpanel/gui/qt/share_links_search.py (+30/-91)
ubuntuone/controlpanel/gui/qt/tests/__init__.py (+1/-0)
ubuntuone/controlpanel/gui/qt/tests/test_gui.py (+0/-3)
ubuntuone/controlpanel/gui/qt/tests/test_share_links.py (+0/-2)
ubuntuone/controlpanel/gui/qt/tests/test_share_links_search.py (+73/-101)
ubuntuone/controlpanel/sd_client/__init__.py (+4/-0)
ubuntuone/controlpanel/tests/test_backend.py (+15/-0)
To merge this branch: bzr merge lp:~diegosarmentero/ubuntuone-control-panel/search-shared-files
Reviewer Review Type Date Requested Status
Mike McCracken (community) Approve
Roberto Alsina (community) Approve
Review via email: mp+131019@code.launchpad.net

Commit message

- Use the search and filter implementation from u1-client to get the list always up to date (LP: #1056189).

Description of the change

This branch requires this u1-client branch:
https://code.launchpad.net/~diegosarmentero/ubuntuone-client/search-filter/+merge/130862

To work as expected.

If you see the following lint issue:
== Python Lint Notices ==

ubuntuone/controlpanel/sd_client/__init__.py:
    235: [E1101, SyncDaemonClient.search_files] Instance of 'SyncDaemonTool' has no 'search_files' member

You will need to add the u1-client branch mentioned to the path when running the tests.

To post a comment you must log in.
Revision history for this message
Roberto Alsina (ralsina) :
review: Approve
Revision history for this message
Mike McCracken (mikemc) wrote :

works for me on darwin with the search-filter branch mentioned above and the ~diegosarmentero/ubuntuone-client/fix-tests-jenkins branch.

review: Approve
Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :
Download full text (163.9 KiB)

The attempt to merge lp:~diegosarmentero/ubuntuone-control-panel/search-shared-files into lp:ubuntuone-control-panel failed. Below is the output from the failed tests.

*** Running DBus test suite ***
ubuntuone.controlpanel.dbustests.test_dbus_service
  BaseTestCase
    runTest ... [OK]
  DBusServiceMainTestCase
    test_dbus_service_cant_register ... Control panel backend already running.
                                   [OK]
    test_dbus_service_main ... [OK]
  DBusServiceTestCase
    test_cant_register_twice ... [SKIPPED]
    test_dbus_busname_created ... [OK]
    test_error_handler_default ... [OK]
    test_error_handler_with_exception ... [OK]
    test_error_handler_with_failure ... [OK]
    test_error_handler_with_non_string_dict ... [OK]
    test_error_handler_with_string_dict ... [OK]
    test_register_service ... [OK]
  FileSyncTestCase
    test_file_sync_status_changed ... [OK]
    test_file_sync_status_disabled ... [OK]
    test_file_sync_status_disconnected ... [OK]
    test_file_sync_status_error ... [OK]
    test_file_sync_status_idle ... [OK]
    test_file_sync_status_starting ... [OK]
    test_file_sync_status_stopped ... [OK]
    test_file_sync_status_syncing ... [OK]
    test_file_sync_status_unknown ... [OK]
    test_status_changed_handler ... [OK]
    test_status_changed_handler_after_status_requested ... [OK]
    test_status_changed_handler_after_status_requested_twice ... [OK]
  OperationsAuthErrorTestCase
    test_account_info_returned ... [OK]
    test_change_device_settings ... [OK]
    test_change_replication_settings ... [OK]
    test_change_volume_settings ... [OK]
    test_connect_files ... [OK]
    test_devices_info_returned ... [OK]
    test_disable_files ... [OK]
    test_disconnect_files ... [OK]
    test_enable_files ... [OK]
    test_remove_device ... [OK]
    test_replications_info ... [OK]
    test_restart_files ... [O...

Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :
Download full text (163.9 KiB)

The attempt to merge lp:~diegosarmentero/ubuntuone-control-panel/search-shared-files into lp:ubuntuone-control-panel failed. Below is the output from the failed tests.

*** Running DBus test suite ***
ubuntuone.controlpanel.dbustests.test_dbus_service
  BaseTestCase
    runTest ... [OK]
  DBusServiceMainTestCase
    test_dbus_service_cant_register ... Control panel backend already running.
                                   [OK]
    test_dbus_service_main ... [OK]
  DBusServiceTestCase
    test_cant_register_twice ... [SKIPPED]
    test_dbus_busname_created ... [OK]
    test_error_handler_default ... [OK]
    test_error_handler_with_exception ... [OK]
    test_error_handler_with_failure ... [OK]
    test_error_handler_with_non_string_dict ... [OK]
    test_error_handler_with_string_dict ... [OK]
    test_register_service ... [OK]
  FileSyncTestCase
    test_file_sync_status_changed ... [OK]
    test_file_sync_status_disabled ... [OK]
    test_file_sync_status_disconnected ... [OK]
    test_file_sync_status_error ... [OK]
    test_file_sync_status_idle ... [OK]
    test_file_sync_status_starting ... [OK]
    test_file_sync_status_stopped ... [OK]
    test_file_sync_status_syncing ... [OK]
    test_file_sync_status_unknown ... [OK]
    test_status_changed_handler ... [OK]
    test_status_changed_handler_after_status_requested ... [OK]
    test_status_changed_handler_after_status_requested_twice ... [OK]
  OperationsAuthErrorTestCase
    test_account_info_returned ... [OK]
    test_change_device_settings ... [OK]
    test_change_replication_settings ... [OK]
    test_change_volume_settings ... [OK]
    test_connect_files ... [OK]
    test_devices_info_returned ... [OK]
    test_disable_files ... [OK]
    test_disconnect_files ... [OK]
    test_enable_files ... [OK]
    test_remove_device ... [OK]
    test_replications_info ... [OK]
    test_restart_files ... [O...

374. By Diego Sarmentero

fixing pep8 issues

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntuone/controlpanel/backend.py'
2--- ubuntuone/controlpanel/backend.py 2012-10-26 15:55:18 +0000
3+++ ubuntuone/controlpanel/backend.py 2012-10-29 14:02:23 +0000
4@@ -883,6 +883,13 @@
5 returnValue(result)
6
7 @log_call(logger.info)
8+ @inlineCallbacks
9+ def search_files(self, pattern):
10+ """Search for this pattern in the name of u1 files."""
11+ result = yield self.sd_client.search_files(pattern)
12+ returnValue(result)
13+
14+ @log_call(logger.info)
15 def shutdown(self):
16 """Stop this service."""
17 # do any other needed cleanup
18
19=== modified file 'ubuntuone/controlpanel/gui/qt/share_links_search.py'
20--- ubuntuone/controlpanel/gui/qt/share_links_search.py 2012-10-16 14:32:44 +0000
21+++ ubuntuone/controlpanel/gui/qt/share_links_search.py 2012-10-29 14:02:23 +0000
22@@ -28,6 +28,8 @@
23
24 logger = setup_logging('qt.share_links_search')
25
26+HOME_DIR = ''
27+
28
29 def get_system_icon_for_filename(file_path):
30 """Return the icon used for the system to represent this file."""
31@@ -37,7 +39,7 @@
32 return icon
33
34
35-# pylint: disable=C0103
36+# pylint: disable=C0103,W0603
37
38 class SearchBox(QtGui.QLineEdit, cache.Cache):
39 """Search widget for the synced files."""
40@@ -48,9 +50,7 @@
41 super(SearchBox, self).__init__(parent)
42 # The search box should be disabled until
43 # the file list is obtained
44- self.setEnabled(False)
45 self.popup = FilesPopup()
46- self.home_dir = ''
47 self.temp_u1_files = []
48 self.items_per_page = 0
49 self.items_step = 20
50@@ -72,7 +72,7 @@
51 self._scroll_fetch_more)
52 self.textChanged.connect(self.filter)
53
54- self._get_volumes_info()
55+ self._get_home_path()
56
57 def _scroll_fetch_more(self, value):
58 """Fetch more items into the list on scroll."""
59@@ -81,56 +81,27 @@
60 self.popup.fetch_more(filenames)
61
62 @inlineCallbacks
63- def _get_volumes_info(self):
64+ def _get_home_path(self):
65 """Get the volumes info."""
66- self.home_dir = yield self.backend.get_home_dir()
67- logger.info('Starting file list collection')
68- self._thread_explore = ThreadExploreFolder(self.home_dir)
69- info = yield self.backend.volumes_info()
70- self._process_volumes_info(info)
71-
72- def _process_volumes_info(self, info):
73- """Get the volumes paths and process them."""
74- folders = []
75- for _, _, data in info:
76- for d in data:
77- if d['type'] != 'SHARE':
78- folder = d.get('path', d.get('realpath'))
79- folders.append(folder)
80- self.get_folders_files(folders)
81-
82- def get_folders_files(self, folders):
83- """Get the list of files in each folder and index them."""
84- self._thread_explore.set_folders(folders)
85- self._thread_explore.folderDataObtained.connect(
86- self._folder_content_obtained)
87- self._thread_explore.start()
88-
89- def _folder_content_obtained(self):
90- """Receive the content of the folders from the thread."""
91- files = self._get_filtered_list(self._thread_explore.u1_files)
92- logger.info('Finished file list collection, found %d files.',
93- len(self._thread_explore.u1_files))
94- self.setEnabled(True)
95- self.popup.load_items(files)
96- text = self.text()
97- self.filter(text)
98-
99+ global HOME_DIR
100+ HOME_DIR = yield self.backend.get_home_dir()
101+
102+ @inlineCallbacks
103 def filter(self, text):
104 """Filter the content of the popup with the text entered."""
105 text = unicode(text)
106 self.items_per_page = 0
107 if text and (self.prefix == '' or self.prefix != text[:-1]):
108 self.prefix = text
109- self.temp_u1_files = self._thread_explore.u1_files
110- self._show_filter()
111+ self.temp_u1_files = yield self.backend.search_files(self.prefix)
112+ self._load_items()
113 elif text != '':
114 self.prefix = text
115- self._show_filter()
116+ self._load_items()
117 else:
118 self.popup.hide()
119
120- def _show_filter(self):
121+ def _load_items(self):
122 """Load the items in the popup and display it."""
123 if not self.popup.isVisible():
124 self.popup.setFixedWidth(self.width())
125@@ -210,8 +181,8 @@
126 """Move the popup when the windows is moved."""
127 super(SearchBox, self).moveEvent(event)
128 if self.popup.isVisible():
129- point = self.mapToGlobal(self.line_search.pos())
130- self.popup.move(point.x(), point.y() + self.line_search.height())
131+ point = self.mapToGlobal(self.pos())
132+ self.popup.move(point.x(), point.y() + self.height())
133
134
135 class FileItem(QtGui.QLabel):
136@@ -224,17 +195,29 @@
137 self.text_style = (u"<span style='color: {2};'>{0}</span><br>"
138 "<span style='font-size: 13px; color: {3};'>({1})</span>")
139 self.setText(self.text_style.format(
140- self.name, self.file_path, '#333333', 'grey'))
141+ self.name, self.reduced_path(self.file_path),
142+ '#333333', 'grey'))
143+
144+ def reduced_path(self, file_path):
145+ """Replace the home part of the path with ~."""
146+ if file_path.startswith(HOME_DIR):
147+ reduce_path = file_path[len(HOME_DIR):]
148+ if reduce_path.startswith(os.path.sep):
149+ reduce_path = reduce_path[1:]
150+ file_path = os.path.join('~', reduce_path)
151+ return file_path
152
153 def set_selected(self):
154 """Set a style for the text when the item is selected."""
155 self.setText(self.text_style.format(
156- self.name, self.file_path, 'white', 'white'))
157+ self.name, self.reduced_path(self.file_path),
158+ 'white', 'white'))
159
160 def set_not_selected(self):
161 """Set a style for the text when the item is not selected."""
162 self.setText(self.text_style.format(
163- self.name, self.file_path, '#333333', 'grey'))
164+ self.name, self.reduced_path(self.file_path),
165+ '#333333', 'grey'))
166
167
168 class FilesPopup(QtGui.QFrame):
169@@ -296,47 +279,3 @@
170 """Notify when the popup is hidden."""
171 super(FilesPopup, self).hideEvent(event)
172 self.popupHidden.emit()
173-
174-
175-class ThreadExploreFolder(QtCore.QThread):
176- """Retrieve the data of the folders asynchronously."""
177-
178- folderDataObtained = QtCore.pyqtSignal()
179-
180- def __init__(self, home_dir=''):
181- super(ThreadExploreFolder, self).__init__()
182- self.home_dir = home_dir
183- self.u1_files = []
184- self.folders = []
185-
186- def set_folders(self, folders):
187- """Set the folders to be explored."""
188- self.folders = folders
189-
190- def run(self):
191- """Execute the thread to obtain the folders data."""
192- folders_data = []
193- for folder in self.folders:
194- folders_data += self.get_folder_info(folder)
195- temp_files = []
196- for file_ in folders_data:
197- if file_.startswith(self.home_dir):
198- new_path = file_[len(self.home_dir):]
199- if new_path.startswith(os.path.sep):
200- new_path = new_path[1:]
201- path = os.path.join('~', new_path)
202- temp_files.append(path)
203- else:
204- temp_files.append(file_)
205- folders_data = temp_files
206- folders_data.sort()
207- self.u1_files = folders_data
208- self.folderDataObtained.emit()
209-
210- def get_folder_info(self, folder):
211- """Return the list of files in the proper folder."""
212- files_list = []
213- if os.path.exists(folder):
214- for root, _, files in os.walk(folder):
215- files_list.extend([os.path.join(root, f) for f in files])
216- return files_list
217
218=== modified file 'ubuntuone/controlpanel/gui/qt/tests/__init__.py'
219--- ubuntuone/controlpanel/gui/qt/tests/__init__.py 2012-10-04 21:12:56 +0000
220+++ ubuntuone/controlpanel/gui/qt/tests/__init__.py 2012-10-29 14:02:23 +0000
221@@ -146,6 +146,7 @@
222 'replications_info',
223 'restart_files',
224 'restore_file_sync_settings',
225+ 'search_files',
226 'set_public_access_changed_handler',
227 'set_public_access_change_error_handler',
228 'set_public_files_list_handler',
229
230=== modified file 'ubuntuone/controlpanel/gui/qt/tests/test_gui.py'
231--- ubuntuone/controlpanel/gui/qt/tests/test_gui.py 2012-10-16 14:19:39 +0000
232+++ ubuntuone/controlpanel/gui/qt/tests/test_gui.py 2012-10-29 14:02:23 +0000
233@@ -19,7 +19,6 @@
234 from twisted.internet import defer
235
236 from ubuntuone.controlpanel.gui.qt import gui
237-from ubuntuone.controlpanel.gui.qt import share_links_search
238 from ubuntuone.controlpanel.gui.qt.tests import BaseTestCase, FakedDialog
239
240
241@@ -44,8 +43,6 @@
242 @defer.inlineCallbacks
243 def setUp(self):
244 """Set the different tests."""
245- self.patch(share_links_search.SearchBox, "_get_volumes_info",
246- lambda *args, **kwargs: None)
247 yield super(MainWindowTestCase, self).setUp()
248
249 def test_close_event_calls_custom_close_callback(self):
250
251=== modified file 'ubuntuone/controlpanel/gui/qt/tests/test_share_links.py'
252--- ubuntuone/controlpanel/gui/qt/tests/test_share_links.py 2012-10-16 14:32:44 +0000
253+++ ubuntuone/controlpanel/gui/qt/tests/test_share_links.py 2012-10-29 14:02:23 +0000
254@@ -44,8 +44,6 @@
255
256 @defer.inlineCallbacks
257 def setUp(self):
258- self.patch(gui.share_links_ui.SearchBox, "_get_volumes_info",
259- lambda *args, **kwargs: None)
260 yield super(ShareLinksTestCase, self).setUp()
261
262 def test_setup(self):
263
264=== modified file 'ubuntuone/controlpanel/gui/qt/tests/test_share_links_search.py'
265--- ubuntuone/controlpanel/gui/qt/tests/test_share_links_search.py 2012-10-16 14:32:44 +0000
266+++ ubuntuone/controlpanel/gui/qt/tests/test_share_links_search.py 2012-10-29 14:02:23 +0000
267@@ -18,7 +18,7 @@
268
269 import os
270
271-from dirspec import utils
272+#from dirspec import utils
273 from twisted.internet import defer
274
275 from ubuntuone.controlpanel.gui.tests import USER_HOME
276@@ -36,63 +36,39 @@
277
278 @defer.inlineCallbacks
279 def setUp(self):
280- self.patch(gui.ThreadExploreFolder, "start",
281- lambda *args, **kwargs: self.fake_start())
282- self.patch(gui.SearchBox, "_get_volumes_info",
283- lambda *args, **kwargs: None)
284 yield super(SearchBoxTestCase, self).setUp()
285-
286- self.ui.home_dir = yield self.ui.backend.get_home_dir()
287- self.ui._thread_explore = gui.ThreadExploreFolder(self.ui.home_dir)
288- self.patch(utils, "user_home", USER_HOME)
289- self.patch(self.ui._thread_explore, "get_folder_info",
290- self.fake_get_folder_info)
291- self.folder_info = {
292- 'folder1': [
293- os.path.join(USER_HOME, 'ubuntu', 'file1'),
294- os.path.join(USER_HOME, 'ubuntu', 'file2'),
295- os.path.join(USER_HOME, 'one', 'file3'),
296- ],
297- 'folder2': [
298- os.path.join(USER_HOME, 'test', 'asd'),
299- os.path.join('other_path', 'test', 'qwe'),
300- os.path.join(USER_HOME, 'blabla', 'iop'),
301- ]
302- }
303+ self.patch(self.ui.backend, "search_files", self.fake_search_files)
304+ self.files = []
305 self._slot_item = None
306
307- def fake_start(self):
308- """Fake thread start."""
309- self.ui._thread_explore.run()
310+ def fake_search_files(self, pattern):
311+ """Fake search_files from the backend."""
312+ self.files = [os.path.join(USER_HOME, 'blabla', 'iop'),
313+ os.path.join(USER_HOME, 'one', 'file3'),
314+ os.path.join(USER_HOME, 'test', 'asd'),
315+ os.path.join(USER_HOME, 'ubuntu', 'file1'),
316+ os.path.join(USER_HOME, 'ubuntu', 'file2'),
317+ os.path.join('other_path', 'test', 'qwe')]
318+ return sorted(self.files)
319
320 def fake_slot(self, item):
321 """Fake function to be called when itemSelected is emitted."""
322 self._slot_item = item
323
324- def fake_get_folder_info(self, folder):
325- """Fake get_folder_info."""
326- return self.folder_info.get(folder, [])
327-
328 def test_initialization(self):
329 """Check that the widget is build properly"""
330- self.assertEqual(self.ui.home_dir, USER_HOME)
331- self.assertEqual(self.ui._thread_explore.u1_files, [])
332+ self.assertEqual(gui.HOME_DIR, USER_HOME)
333 self.assertEqual(self.ui.temp_u1_files, [])
334 self.assertEqual(self.ui.items_per_page, 0)
335 self.assertEqual(self.ui.items_step, 20)
336 self.assertEqual(self.ui.prefix, '')
337- self.assertFalse(self.ui.isEnabled())
338-
339- def test_folder_content_obtained_enables(self):
340- """Check that _folder_content_obtained enables the widget."""
341- self.ui._folder_content_obtained()
342 self.assertTrue(self.ui.isEnabled())
343
344 def test_key_down_pressed(self):
345 """Check the proper actions are executed on key down pressed."""
346- data1 = [{'path': 'folder1', 'type': 'ROOT'}]
347- data2 = [{'realpath': 'folder2', 'type': 'UDF'}]
348- self.ui._process_volumes_info([(0, 0, data1), (0, 0, data2)])
349+ self.ui.popup.setVisible(True)
350+ self.ui.temp_u1_files = self.ui.backend.search_files('')
351+ self.ui._load_items()
352 self.ui.popup.list_widget.setCurrentRow(1)
353 current = self.ui.popup.list_widget.currentRow()
354 self.ui._key_down_pressed(current)
355@@ -107,12 +83,10 @@
356 data.append(True)
357
358 self.patch(self.ui.popup, "fetch_more", fake_fetch_more)
359- data1 = [{'path': 'folder1', 'type': 'ROOT'}]
360- data2 = [{'realpath': 'folder2', 'type': 'UDF'}]
361- self.ui._process_volumes_info([(0, 0, data1), (0, 0, data2),
362- (0, 0, data1), (0, 0, data2), (0, 0, data1), (0, 0, data2),
363- (0, 0, data1), (0, 0, data2), (0, 0, data1), (0, 0, data2),
364- (0, 0, data1), (0, 0, data2), (0, 0, data1), (0, 0, data2)])
365+ self.ui.popup.setVisible(True)
366+ self.ui.temp_u1_files = self.ui.backend.search_files('')
367+ self.ui.temp_u1_files = self.ui.temp_u1_files * 4
368+ self.ui._load_items()
369 self.assertEqual(self.ui.popup.list_widget.count(), 20)
370 self.ui.popup.list_widget.setCurrentRow(
371 self.ui.popup.list_widget.count() - 5)
372@@ -122,9 +96,9 @@
373
374 def test_key_up_pressed(self):
375 """Check the proper actions are executed on key up pressed."""
376- data1 = [{'path': 'folder1', 'type': 'ROOT'}]
377- data2 = [{'realpath': 'folder2', 'type': 'UDF'}]
378- self.ui._process_volumes_info([(0, 0, data1), (0, 0, data2)])
379+ self.ui.popup.setVisible(True)
380+ self.ui.temp_u1_files = self.ui.backend.search_files('')
381+ self.ui._load_items()
382 self.ui.popup.list_widget.setCurrentRow(1)
383 current = self.ui.popup.list_widget.currentRow()
384 self.ui._key_up_pressed(current)
385@@ -132,9 +106,9 @@
386
387 def test_key_up_pressed_stay_in_0(self):
388 """Check the proper actions are executed on key up pressed."""
389- data1 = [{'path': 'folder1', 'type': 'ROOT'}]
390- data2 = [{'realpath': 'folder2', 'type': 'UDF'}]
391- self.ui._process_volumes_info([(0, 0, data1), (0, 0, data2)])
392+ self.ui.popup.setVisible(True)
393+ self.ui.temp_u1_files = self.ui.backend.search_files('')
394+ self.ui._load_items()
395 self.ui.popup.list_widget.setCurrentRow(0)
396 current = self.ui.popup.list_widget.currentRow()
397 self.assertEqual(self.ui.popup.list_widget.currentRow(), 0)
398@@ -143,33 +117,33 @@
399
400 def test_key_return_pressed(self):
401 """Check the proper actions are executed on key return pressed."""
402- data1 = [{'path': 'folder1', 'type': 'ROOT'}]
403- data2 = [{'realpath': 'folder2', 'type': 'UDF'}]
404- self.ui._process_volumes_info([(0, 0, data1), (0, 0, data2)])
405+ self.ui.popup.setVisible(True)
406+ self.ui.temp_u1_files = self.ui.backend.search_files('')
407+ self.ui._load_items()
408 self.ui.popup.list_widget.setCurrentRow(1)
409 current = self.ui.popup.list_widget.currentRow()
410 self.ui.itemSelected.connect(self.fake_slot)
411 self.ui._key_return_pressed(current)
412 expected = unicode(self._slot_item).replace('~', USER_HOME)
413- self.assertEqual(expected, self.folder_info['folder2'][2])
414+ self.assertEqual(expected, self.files[1])
415
416 def test_mouse_click_pressed(self):
417 """Check the proper actions are executed when click is pressed."""
418- data1 = [{'path': 'folder1', 'type': 'ROOT'}]
419- data2 = [{'realpath': 'folder2', 'type': 'UDF'}]
420- self.ui._process_volumes_info([(0, 0, data1), (0, 0, data2)])
421+ self.ui.temp_u1_files = self.ui.backend.search_files('')
422+ self.ui.popup.setVisible(True)
423+ self.ui._load_items()
424 self.ui.popup.list_widget.setCurrentRow(1)
425 current = self.ui.popup.list_widget.currentItem()
426 self.ui.itemSelected.connect(self.fake_slot)
427 self.ui.popup.list_widget.itemPressed.emit(current)
428 expected = unicode(self._slot_item).replace('~', USER_HOME)
429- self.assertEqual(expected, self.folder_info['folder2'][2])
430+ self.assertEqual(expected, self.files[1])
431
432 def test_mouse_scroll(self):
433 """Check that fetch_more is called when we reach the end of scroll."""
434- data1 = [{'path': 'folder1', 'type': 'ROOT'}]
435- data2 = [{'realpath': 'folder2', 'type': 'UDF'}]
436- self.ui._process_volumes_info([(0, 0, data1), (0, 0, data2)])
437+ self.ui.temp_u1_files = self.ui.backend.search_files('')
438+ self.ui.popup.setVisible(True)
439+ self.ui._load_items()
440 self.patch(self.ui.popup, "fetch_more", self._set_called)
441 self.ui._scroll_fetch_more(
442 self.ui.popup.list_widget.verticalScrollBar().maximum())
443@@ -185,13 +159,13 @@
444 data.append(text)
445
446 self.patch(self.ui, "setText", fake_set_text)
447- data1 = [{'path': 'folder1', 'type': 'ROOT'}]
448- data2 = [{'realpath': 'folder2', 'type': 'UDF'}]
449- self.ui._process_volumes_info([(0, 0, data1), (0, 0, data2)])
450- self.ui.popup.list_widget.setCurrentRow(1)
451+ self.ui.popup.setVisible(True)
452+ self.ui.temp_u1_files = self.ui.backend.search_files('')
453+ self.ui._load_items()
454+ self.ui.popup.list_widget.setCurrentRow(2)
455
456 self.ui._key_space_pressed()
457- expected = ['iop']
458+ expected = [os.path.basename(self.files[2])]
459 self.assertEqual(expected, data)
460
461 def test_key_space_pressed_without_selection(self):
462@@ -201,64 +175,50 @@
463
464 def test_process_volumes_info(self):
465 """Check that _process_volumes_info obtain the proper info."""
466- data1 = [{'path': 'folder1', 'type': 'ROOT'}]
467- data2 = [{'realpath': 'folder2', 'type': 'UDF'}]
468- self.ui._process_volumes_info([(0, 0, data1), (0, 0, data2)])
469- expected = [
470- os.path.join('other_path', 'test', 'qwe'),
471- os.path.join('~', 'blabla', 'iop'),
472- os.path.join('~', 'one', 'file3'),
473- os.path.join('~', 'test', 'asd'),
474- os.path.join('~', 'ubuntu', 'file1'),
475- os.path.join('~', 'ubuntu', 'file2')]
476- self.assertEqual(self.ui._thread_explore.u1_files, expected)
477+ self.ui.temp_u1_files = self.ui.backend.search_files('')
478+ self.ui.popup.setVisible(True)
479+ self.addCleanup(self.ui.popup.hide)
480+ self.ui._load_items()
481+ expected = self.files
482+ expected.sort()
483+ self.assertEqual(self.ui.temp_u1_files, expected)
484 self.assertEqual(self.ui.popup.list_widget.count(), 6)
485
486 def test_filter(self):
487 """Check the results of the filter."""
488 # This tests the behavior of:
489 # filter
490- # _show_filter
491+ # _load_items
492 # _get_filtered_list
493 self.patch(self.ui.popup, "isVisible", lambda: True)
494- data1 = [{'path': 'folder1', 'type': 'ROOT'}]
495- data2 = [{'realpath': 'folder2', 'type': 'UDF'}]
496- self.ui._process_volumes_info([(0, 0, data1), (0, 0, data2)])
497+ self.ui.popup.setVisible(True)
498+ self.ui.temp_u1_files = self.ui.backend.search_files('')
499+ self.ui._load_items()
500 self.ui.filter('p')
501- expected = [os.path.join('~', 'blabla', 'iop')]
502+ expected = [os.path.join(USER_HOME, 'blabla', 'iop')]
503 self.assertEqual(expected, self.ui.temp_u1_files)
504
505 self.ui.filter('i')
506 expected = [
507- os.path.join('~', 'blabla', 'iop'),
508- os.path.join('~', 'one', 'file3'),
509- os.path.join('~', 'ubuntu', 'file1'),
510- os.path.join('~', 'ubuntu', 'file2')]
511+ os.path.join(USER_HOME, 'blabla', 'iop'),
512+ os.path.join(USER_HOME, 'one', 'file3'),
513+ os.path.join(USER_HOME, 'ubuntu', 'file1'),
514+ os.path.join(USER_HOME, 'ubuntu', 'file2')]
515 self.assertEqual(expected, self.ui.temp_u1_files)
516
517 def test_set_selected_item(self):
518 """Check the notification of the selected item."""
519 self.ui.itemSelected.connect(self._set_called)
520 self.patch(self.ui.popup, "isVisible", lambda: True)
521- data1 = [{'path': 'folder1', 'type': 'ROOT'}]
522- data2 = [{'realpath': 'folder2', 'type': 'UDF'}]
523- self.ui._process_volumes_info([(0, 0, data1), (0, 0, data2)])
524+ self.ui.temp_u1_files = self.ui.backend.search_files('')
525+ self.ui._load_items()
526 self.ui.popup.list_widget.setCurrentRow(0)
527 item = self.ui.popup.list_widget.currentItem()
528 self.ui._set_selected_item(item)
529 self.assertEqual(self._called,
530- ((os.path.join(u'other_path', u'test', u'qwe'),), {}))
531+ ((os.path.join(USER_HOME, 'blabla', 'iop'),), {}))
532 self.assertEqual(self.ui.text(), '')
533
534- def test_ignore_shared_folders(self):
535- """Check that the folders shared with me are ignored."""
536- data = []
537- self.patch(self.ui, "get_folders_files", data.append)
538- data1 = [{'path': 'folder1', 'type': 'ROOT'}]
539- data2 = [{'realpath': 'folder2', 'type': 'SHARE'}]
540- self.ui._process_volumes_info([(0, 0, data1), (0, 0, data2)])
541- self.assertEqual(data, [['folder1']])
542-
543
544 class FileItemTestCase(BaseTestCase):
545 """Test the File Item."""
546@@ -267,6 +227,11 @@
547 file_path = '/home/tester/ubuntu/file1.txt'
548 kwargs = {'file_path': file_path}
549
550+ @defer.inlineCallbacks
551+ def setUp(self):
552+ yield super(FileItemTestCase, self).setUp()
553+ gui.HOME_DIR = '/path/'
554+
555 def test_default(self):
556 """Check the default style of the item"""
557 name = os.path.basename(self.file_path)
558@@ -290,6 +255,13 @@
559 '#333333', 'grey')
560 self.assertEqual(self.ui.text(), style)
561
562+ def test_reduce_path(self):
563+ """Check the default style of the item"""
564+ gui.HOME_DIR = USER_HOME
565+ result = self.ui.reduced_path(self.file_path)
566+ expected = os.path.join('~', 'ubuntu', 'file1.txt')
567+ self.assertEqual(expected, result)
568+
569
570 class FilesPopupTestCase(BaseTestCase):
571
572
573=== modified file 'ubuntuone/controlpanel/sd_client/__init__.py'
574--- ubuntuone/controlpanel/sd_client/__init__.py 2012-08-24 20:44:03 +0000
575+++ ubuntuone/controlpanel/sd_client/__init__.py 2012-10-29 14:02:23 +0000
576@@ -229,3 +229,7 @@
577 def set_public_access_change_error_handler(self, handler):
578 """Set the status handler function."""
579 return self.proxy.connect_signal('PublicAccessChangeError', handler)
580+
581+ def search_files(self, pattern):
582+ """Search for this pattern in the name of u1 files."""
583+ return self.proxy.search_files(pattern)
584
585=== modified file 'ubuntuone/controlpanel/tests/test_backend.py'
586--- ubuntuone/controlpanel/tests/test_backend.py 2012-10-23 19:26:30 +0000
587+++ ubuntuone/controlpanel/tests/test_backend.py 2012-10-29 14:02:23 +0000
588@@ -170,6 +170,7 @@
589 self.folders = []
590 self.volumes_refreshed = False
591 self.menu_data = {'recent-transfers': (), 'uploading': ()}
592+ self.files_search = ['/home/u1/path/my_file', '/home/u1/path/test']
593 self.publicfiles = [
594 {'path': '/home/file1', 'public_url': 'http:ubuntuone.com/asd123'},
595 {'path': '/home/file2', 'public_url': 'http:ubuntuone.com/qwe456'},
596@@ -340,6 +341,10 @@
597 """Return the sync menu data."""
598 return self.menu_data
599
600+ def search_files(self, pattern):
601+ """Return the search files results."""
602+ return [file_ for file_ in self.files_search if pattern in file_]
603+
604 def get_public_files(self):
605 """Trigger the action to get the public files."""
606 if self.public_files_list_handler is not None:
607@@ -1808,6 +1813,16 @@
608 self.assertEqual(result, expected)
609
610 @inlineCallbacks
611+ def test_search_files(self):
612+ """Check that we get the right data to create the menu."""
613+ result = yield self.be.search_files('file')
614+ expected = ['/home/u1/path/my_file']
615+ self.assertEqual(result, expected)
616+ result = yield self.be.search_files('test')
617+ expected = ['/home/u1/path/test']
618+ self.assertEqual(result, expected)
619+
620+ @inlineCallbacks
621 def test_get_public_files(self):
622 """Check that we get list of public files."""
623 data = []

Subscribers

People subscribed via source and target branches