Merge lp:~nataliabidart/ubuntuone-control-panel/share-backend into lp:ubuntuone-control-panel

Proposed by Natalia Bidart
Status: Merged
Approved by: Natalia Bidart
Approved revision: 215
Merged at revision: 212
Proposed branch: lp:~nataliabidart/ubuntuone-control-panel/share-backend
Merge into: lp:ubuntuone-control-panel
Diff against target: 524 lines (+144/-81)
18 files modified
ubuntuone/controlpanel/__init__.py (+1/-2)
ubuntuone/controlpanel/backend.py (+2/-0)
ubuntuone/controlpanel/cache.py (+45/-0)
ubuntuone/controlpanel/gui/gtk/tests/__init__.py (+3/-3)
ubuntuone/controlpanel/gui/qt/addfolder.py (+5/-7)
ubuntuone/controlpanel/gui/qt/device.py (+4/-4)
ubuntuone/controlpanel/gui/qt/devices.py (+1/-2)
ubuntuone/controlpanel/gui/qt/filesyncstatus.py (+4/-7)
ubuntuone/controlpanel/gui/qt/gotoweb.py (+2/-4)
ubuntuone/controlpanel/gui/qt/gui.py (+1/-1)
ubuntuone/controlpanel/gui/qt/loadingoverlay.py (+1/-1)
ubuntuone/controlpanel/gui/qt/tests/__init__.py (+18/-25)
ubuntuone/controlpanel/gui/qt/tests/test_controlpanel.py (+1/-0)
ubuntuone/controlpanel/gui/qt/tests/test_device.py (+1/-7)
ubuntuone/controlpanel/gui/qt/tests/test_gotoweb.py (+0/-4)
ubuntuone/controlpanel/gui/qt/tests/test_ubuntuonebin.py (+0/-5)
ubuntuone/controlpanel/gui/qt/ubuntuonebin.py (+4/-9)
ubuntuone/controlpanel/tests/test_cache.py (+51/-0)
To merge this branch: bzr merge lp:~nataliabidart/ubuntuone-control-panel/share-backend
Reviewer Review Type Date Requested Status
Diego Sarmentero (community) Approve
Roberto Alsina (community) Approve
Review via email: mp+73862@code.launchpad.net

Commit message

- Share the same backend instance among all widgets (LP: #834766).
- No more edge when hitting the REST api.

Description of the change

Run the controlpanel with:

nessita@dali:~/canonical/u1/controlpanel/share-backend$ ./setup.py clean build; DEBUG=True PYTHONPATH=. ./bin/ubuntuone-control-panel-qt > a.out 2>&1

and confirm that the log line:

2011-09-02 15:00:52,491 - ubuntuone.controlpanel.backend - INFO - ControlBackend: instance started.

appears only once, no matter how many devices you have, no matter how many times you visit a tab.

To post a comment you must log in.
215. By Natalia Bidart

Typos.

Revision history for this message
Roberto Alsina (ralsina) wrote :

+1 good job!

review: Approve
Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntuone/controlpanel/__init__.py'
2--- ubuntuone/controlpanel/__init__.py 2011-08-26 17:16:16 +0000
3+++ ubuntuone/controlpanel/__init__.py 2011-09-02 18:12:25 +0000
4@@ -29,6 +29,5 @@
5 DBUS_PREFERENCES_PATH = "/preferences"
6 DBUS_PREFERENCES_IFACE = "com.ubuntuone.controlpanel.Preferences"
7
8-# XXX: use edge only when testing new stuff
9-WEBSERVICE_BASE_URL = u"https://edge.one.ubuntu.com/api/"
10+WEBSERVICE_BASE_URL = u"https://one.ubuntu.com/api/"
11 TRANSLATION_DOMAIN = 'ubuntuone-control-panel'
12
13=== modified file 'ubuntuone/controlpanel/backend.py'
14--- ubuntuone/controlpanel/backend.py 2011-08-31 16:20:08 +0000
15+++ ubuntuone/controlpanel/backend.py 2011-09-02 18:12:25 +0000
16@@ -138,6 +138,8 @@
17 self.sd_client = sd_client.SyncDaemonClient()
18 self.wc = web_client_factory(self.get_credentials)
19
20+ logger.info('ControlBackend: instance started.')
21+
22 def _process_file_sync_status(self, status):
23 """Process raw file sync status into custom format.
24
25
26=== added file 'ubuntuone/controlpanel/cache.py'
27--- ubuntuone/controlpanel/cache.py 1970-01-01 00:00:00 +0000
28+++ ubuntuone/controlpanel/cache.py 2011-09-02 18:12:25 +0000
29@@ -0,0 +1,45 @@
30+# -*- coding: utf-8 -*-
31+
32+# Authors: Natalia B Bidart <natalia.bidart@canonical.com>
33+#
34+# Copyright 2011 Canonical Ltd.
35+#
36+# This program is free software: you can redistribute it and/or modify it
37+# under the terms of the GNU General Public License version 3, as published
38+# by the Free Software Foundation.
39+#
40+# This program is distributed in the hope that it will be useful, but
41+# WITHOUT ANY WARRANTY; without even the implied warranties of
42+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
43+# PURPOSE. See the GNU General Public License for more details.
44+#
45+# You should have received a copy of the GNU General Public License along
46+# with this program. If not, see <http://www.gnu.org/licenses/>.
47+
48+"""The base object that holds a backend instance."""
49+
50+from ubuntuone.controlpanel import backend
51+
52+
53+class Cache(object):
54+ """The base object that caches stuff."""
55+
56+ logger = None
57+ _shared_objects = {}
58+
59+ def __init__(self, *args, **kwargs):
60+ """Initialize the object using 'backend' as backend."""
61+ super(Cache, self).__init__()
62+ if self.logger is not None:
63+ self.logger.debug('%s: started.', self.__class__.__name__)
64+
65+ @property
66+ def backend(self):
67+ """A cached ControlBackend instance."""
68+ if not self._shared_objects:
69+ self._shared_objects['backend'] = backend.ControlBackend()
70+ return self._shared_objects['backend']
71+
72+ def clear(self):
73+ """Clear all cached objects."""
74+ self._shared_objects = {}
75
76=== modified file 'ubuntuone/controlpanel/gui/gtk/tests/__init__.py'
77--- ubuntuone/controlpanel/gui/gtk/tests/__init__.py 2011-08-18 15:50:38 +0000
78+++ ubuntuone/controlpanel/gui/gtk/tests/__init__.py 2011-09-02 18:12:25 +0000
79@@ -109,8 +109,8 @@
80 ]
81
82
83-class FakeControlPanelBackend(FakedDBusBackend):
84- """Fake a Control Panel Service, act as a dbus.Interface."""
85+class FakedGUIBackend(FakedDBusBackend):
86+ """Fake a Control Panel GUI Service, act as a dbus.Interface."""
87
88 bus_name = gui.DBUS_BUS_NAME_GUI
89 object_path = gui.DBUS_PATH_GUI
90@@ -135,7 +135,7 @@
91 return FakedControlPanelBackend(obj, dbus_interface,
92 *args, **kwargs)
93 if dbus_interface == gui.DBUS_IFACE_GUI:
94- return FakeControlPanelBackend(
95+ return FakedGUIBackend(
96 obj, dbus_interface, *args, **kwargs)
97
98
99
100=== modified file 'ubuntuone/controlpanel/gui/qt/addfolder.py'
101--- ubuntuone/controlpanel/gui/qt/addfolder.py 2011-08-27 01:05:52 +0000
102+++ ubuntuone/controlpanel/gui/qt/addfolder.py 2011-09-02 18:12:25 +0000
103@@ -25,11 +25,9 @@
104 from PyQt4 import QtGui, QtCore
105 from twisted.internet import defer
106
107-from ubuntuone.controlpanel import backend
108+from ubuntuone.controlpanel import cache
109 from ubuntuone.controlpanel.logger import setup_logging
110-from ubuntuone.controlpanel.gui import (
111- FOLDER_INVALID_PATH,
112-)
113+from ubuntuone.controlpanel.gui import FOLDER_INVALID_PATH
114
115
116 logger = setup_logging('qt.addfolder')
117@@ -37,9 +35,11 @@
118 CLOSE = QtGui.QMessageBox.Close
119
120
121-class AddFolderButton(QtGui.QPushButton):
122+class AddFolderButton(cache.Cache, QtGui.QPushButton):
123 """The AddFolderButton widget"""
124
125+ logger = logger
126+
127 folderCreated = QtCore.pyqtSignal(unicode)
128 folderCreationCanceled = QtCore.pyqtSignal()
129
130@@ -47,9 +47,7 @@
131 """Initialize the UI of the widget."""
132 super(AddFolderButton, self).__init__(*args, **kwargs)
133 self.cloud_folders = []
134- self.backend = backend.ControlBackend()
135 self.clicked.connect(self.on_clicked)
136- logger.debug('%s: started.', self.__class__.__name__)
137
138 @QtCore.pyqtSlot()
139 @defer.inlineCallbacks
140
141=== modified file 'ubuntuone/controlpanel/gui/qt/device.py'
142--- ubuntuone/controlpanel/gui/qt/device.py 2011-08-19 15:35:38 +0000
143+++ ubuntuone/controlpanel/gui/qt/device.py 2011-09-02 18:12:25 +0000
144@@ -25,6 +25,7 @@
145 DEVICE_TYPE_COMPUTER,
146 DEVICE_TYPE_PHONE,
147 )
148+from ubuntuone.controlpanel import cache
149 from ubuntuone.controlpanel.gui import DEVICE_CONFIRM_REMOVE
150 from ubuntuone.controlpanel.gui.qt import icon_from_name, pixmap_from_name
151 from ubuntuone.controlpanel.gui.qt.ui import device_ui
152@@ -49,19 +50,18 @@
153 return icon_name
154
155
156-class DeviceWidget(QtGui.QWidget):
157+class DeviceWidget(cache.Cache, QtGui.QWidget):
158 """The widget for each device in the control panel."""
159
160 removed = QtCore.pyqtSignal()
161 removeCanceled = QtCore.pyqtSignal()
162
163- def __init__(self, backend, device_id, **kwargs):
164+ def __init__(self, device_id, *args, **kwargs):
165 """Initialize the UI of the widget."""
166- QtGui.QWidget.__init__(self, **kwargs)
167+ super(DeviceWidget, self).__init__(*args, **kwargs)
168 self.ui = device_ui.Ui_Form()
169 self.ui.setupUi(self)
170 self.id = device_id
171- self.backend = backend
172
173 def update_device_info(self, device_info):
174 """Update the device info."""
175
176=== modified file 'ubuntuone/controlpanel/gui/qt/devices.py'
177--- ubuntuone/controlpanel/gui/qt/devices.py 2011-08-31 17:18:56 +0000
178+++ ubuntuone/controlpanel/gui/qt/devices.py 2011-09-02 18:12:25 +0000
179@@ -90,8 +90,7 @@
180
181 def update_local_device(self, device_info):
182 """Update the info for the local device."""
183- device_widget = device.DeviceWidget(backend=self.backend,
184- device_id=device_info['device_id'])
185+ device_widget = device.DeviceWidget(device_id=device_info['device_id'])
186 device_widget.update_device_info(device_info)
187 device_widget.removed.connect(self.on_local_device_removed)
188
189
190=== modified file 'ubuntuone/controlpanel/gui/qt/filesyncstatus.py'
191--- ubuntuone/controlpanel/gui/qt/filesyncstatus.py 2011-08-31 17:18:56 +0000
192+++ ubuntuone/controlpanel/gui/qt/filesyncstatus.py 2011-09-02 18:12:25 +0000
193@@ -21,7 +21,7 @@
194 from PyQt4 import QtGui, QtCore
195 from twisted.internet import defer
196
197-from ubuntuone.controlpanel import backend
198+from ubuntuone.controlpanel import backend, cache
199 from ubuntuone.controlpanel.logger import setup_logging, log_call
200 from ubuntuone.controlpanel.gui import (
201 ERROR_COLOR,
202@@ -108,19 +108,16 @@
203 return icon_name
204
205
206-class FileSyncStatus(QtGui.QWidget):
207+class FileSyncStatus(cache.Cache, QtGui.QWidget):
208 """The FileSyncStatus widget"""
209
210- def __init__(self, parent=None):
211+ def __init__(self, *args, **kwargs):
212 """Initialize the UI of the widget."""
213- QtGui.QWidget.__init__(self, parent)
214+ super(FileSyncStatus, self).__init__(*args, **kwargs)
215 self.ui = filesyncstatus_ui.Ui_Form()
216 self.ui.setupUi(self)
217
218 self._backend_method = None
219- self.backend = backend.ControlBackend()
220-
221- logger.debug('%s: started.', self.__class__.__name__)
222
223 # Invalid name "showEvent"
224 # pylint: disable=C0103
225
226=== modified file 'ubuntuone/controlpanel/gui/qt/gotoweb.py'
227--- ubuntuone/controlpanel/gui/qt/gotoweb.py 2011-08-31 18:33:43 +0000
228+++ ubuntuone/controlpanel/gui/qt/gotoweb.py 2011-09-02 18:12:25 +0000
229@@ -22,11 +22,11 @@
230
231 from twisted.internet import defer
232
233-from ubuntuone.controlpanel import backend
234+from ubuntuone.controlpanel import cache
235 from ubuntuone.controlpanel.gui import qt, sign_url, UBUNTUONE_LINK
236
237
238-class GoToWebButton(QtGui.QPushButton):
239+class GoToWebButton(cache.Cache, QtGui.QPushButton):
240 """The GoToWebButton widget"""
241
242 def __init__(self, *args, **kwargs):
243@@ -38,8 +38,6 @@
244 self.clicked.connect(self.on_clicked)
245 self.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
246
247- self.backend = backend.ControlBackend()
248-
249 @defer.inlineCallbacks
250 @QtCore.pyqtSlot()
251 def on_clicked(self):
252
253=== modified file 'ubuntuone/controlpanel/gui/qt/gui.py'
254--- ubuntuone/controlpanel/gui/qt/gui.py 2011-08-31 17:18:56 +0000
255+++ ubuntuone/controlpanel/gui/qt/gui.py 2011-09-02 18:12:25 +0000
256@@ -33,7 +33,7 @@
257
258 def __init__(self, close_callback=None):
259 """Initialize this instance with the UI layout."""
260- QtGui.QMainWindow.__init__(self)
261+ super(MainWindow, self).__init__()
262 self.ui = mainwindow_ui.Ui_MainWindow()
263 self.ui.setupUi(self)
264 self.close_callback = close_callback
265
266=== modified file 'ubuntuone/controlpanel/gui/qt/loadingoverlay.py'
267--- ubuntuone/controlpanel/gui/qt/loadingoverlay.py 2011-08-31 17:18:56 +0000
268+++ ubuntuone/controlpanel/gui/qt/loadingoverlay.py 2011-09-02 18:12:25 +0000
269@@ -36,7 +36,7 @@
270 """
271
272 def __init__(self, parent=None):
273- QtGui.QFrame.__init__(self, parent)
274+ super(LoadingOverlay, self).__init__(parent=parent)
275 self.ui = loadingoverlay_ui.Ui_Form()
276 self.ui.setupUi(self)
277
278
279=== modified file 'ubuntuone/controlpanel/gui/qt/tests/__init__.py'
280--- ubuntuone/controlpanel/gui/qt/tests/__init__.py 2011-09-01 17:11:16 +0000
281+++ ubuntuone/controlpanel/gui/qt/tests/__init__.py 2011-09-02 18:12:25 +0000
282@@ -25,7 +25,7 @@
283 from PyQt4 import QtCore
284 from ubuntuone.devtools.handlers import MementoHandler
285
286-from ubuntuone.controlpanel import backend
287+from ubuntuone.controlpanel import backend, cache
288 from ubuntuone.controlpanel.tests import TestCase, EXPECTED_ACCOUNT_INFO, TOKEN
289 from ubuntuone.controlpanel.gui import qt, UBUNTUONE_FROM_OAUTH
290 from ubuntuone.controlpanel.gui.tests import FakedObject, USER_HOME
291@@ -80,21 +80,6 @@
292 return folder
293
294
295-def skip_if_abstract_class(test):
296- """Decorator to skip a test if is an abstract class."""
297-
298- def inner(instance):
299- """Skip a test if is an abstract class."""
300- abstract = instance.class_ui is None
301- result = None
302- if not abstract:
303- result = test(instance)
304-
305- return result
306-
307- return inner
308-
309-
310 class FakeUi(FakedObject):
311 """A fake Ui object."""
312
313@@ -179,18 +164,21 @@
314 class_ui = None
315 kwargs = {}
316
317- @skip_if_abstract_class
318 def setUp(self):
319+ cache.Cache._shared_objects = {}
320 super(BaseTestCase, self).setUp()
321 self.patch(backend, 'ControlBackend', FakedControlPanelBackend)
322- # self.class_ui is not callable
323- # pylint: disable=E1102
324- self.ui = self.class_ui(**self.kwargs)
325- self.addCleanup(self.ui.destroy)
326-
327- if hasattr(self.ui, 'backend'):
328- # clean backend calls
329- self.ui.backend._called.clear()
330+
331+ self.ui = None
332+ if self.class_ui is not None:
333+ # self.class_ui is not callable
334+ # pylint: disable=E1102
335+ self.ui = self.class_ui(**self.kwargs)
336+ # pylint: enable=E1102
337+ self.addCleanup(self.ui.destroy)
338+
339+ if getattr(self.ui, 'backend', None) is not None:
340+ self.addCleanup(self.ui.backend._called.clear)
341
342 if getattr(self.ui, 'logger', None) is not None:
343 self.memento = MementoHandler()
344@@ -248,3 +236,8 @@
345 expected_setup_ui = expected_setup_ui(self.ui)
346 self.assertEqual(self.ui.ui._called,
347 {'setupUi': ((expected_setup_ui,), {})})
348+
349+ def test_backend_is_correct(self):
350+ """The backend instance is correct."""
351+ if getattr(self.ui, 'backend', None) is not None:
352+ self.assertIsInstance(self.ui.backend, FakedControlPanelBackend)
353
354=== modified file 'ubuntuone/controlpanel/gui/qt/tests/test_controlpanel.py'
355--- ubuntuone/controlpanel/gui/qt/tests/test_controlpanel.py 2011-09-01 17:11:16 +0000
356+++ ubuntuone/controlpanel/gui/qt/tests/test_controlpanel.py 2011-09-02 18:12:25 +0000
357@@ -41,6 +41,7 @@
358 @defer.inlineCallbacks
359 def setUp(self):
360 yield super(ControlPanelTestCase, self).setUp()
361+ self.patch(self.ui.ui.folders_tab, 'process_info', lambda info: None)
362 self.ui.backend.next_result = SAMPLE_ACCOUNT_INFO
363
364 @defer.inlineCallbacks
365
366=== modified file 'ubuntuone/controlpanel/gui/qt/tests/test_device.py'
367--- ubuntuone/controlpanel/gui/qt/tests/test_device.py 2011-07-21 13:21:00 +0000
368+++ ubuntuone/controlpanel/gui/qt/tests/test_device.py 2011-09-02 18:12:25 +0000
369@@ -24,7 +24,6 @@
370 from ubuntuone.controlpanel.gui.qt.tests import (
371 BaseTestCase,
372 FakedConfirmDialog,
373- FakedControlPanelBackend,
374 SAMPLE_COMPUTER_INFO,
375 SAMPLE_PHONE_INFO,
376 )
377@@ -40,18 +39,13 @@
378 innerclass_ui = gui.device_ui
379 innerclass_name = "Ui_Form"
380 class_ui = gui.DeviceWidget
381- backend = FakedControlPanelBackend()
382 device_id = 'zaraza'
383- kwargs = {'backend': backend, 'device_id': device_id}
384+ kwargs = {'device_id': device_id}
385
386 def test_has_id(self):
387 """The device as an id, None by default."""
388 self.assertEqual(self.ui.id, self.device_id)
389
390- def test_has_backend(self):
391- """The device as a backend, None by default."""
392- self.assertIs(self.ui.backend, self.backend)
393-
394 def test_update_device_info(self):
395 """The widget is updated with the info."""
396 info = SAMPLE_COMPUTER_INFO
397
398=== modified file 'ubuntuone/controlpanel/gui/qt/tests/test_gotoweb.py'
399--- ubuntuone/controlpanel/gui/qt/tests/test_gotoweb.py 2011-08-31 18:33:43 +0000
400+++ ubuntuone/controlpanel/gui/qt/tests/test_gotoweb.py 2011-09-02 18:12:25 +0000
401@@ -51,10 +51,6 @@
402 self.assertEqual(self.ui.cursor().shape(),
403 gui.QtCore.Qt.PointingHandCursor)
404
405- def test_backend(self):
406- """Backend is created."""
407- self.assertIsInstance(self.ui.backend, gui.backend.ControlBackend)
408-
409 def test_open_uri_when_clicked(self):
410 """When clicking the button, the uri is opened."""
411 self.patch(qt, 'uri_hook', self._set_called)
412
413=== modified file 'ubuntuone/controlpanel/gui/qt/tests/test_ubuntuonebin.py'
414--- ubuntuone/controlpanel/gui/qt/tests/test_ubuntuonebin.py 2011-08-31 18:33:43 +0000
415+++ ubuntuone/controlpanel/gui/qt/tests/test_ubuntuonebin.py 2011-09-02 18:12:25 +0000
416@@ -32,11 +32,6 @@
417
418 class_ui = gui.UbuntuOneBin
419
420- def test_backend(self):
421- """Backend is created."""
422- self.assertIsInstance(self.ui.backend,
423- gui.backend.ControlBackend)
424-
425 def test_is_not_processing_after_creation(self):
426 """After creation, is not processing."""
427 self.assertFalse(self.ui.is_processing)
428
429=== modified file 'ubuntuone/controlpanel/gui/qt/ubuntuonebin.py'
430--- ubuntuone/controlpanel/gui/qt/ubuntuonebin.py 2011-08-31 17:18:56 +0000
431+++ ubuntuone/controlpanel/gui/qt/ubuntuonebin.py 2011-09-02 18:12:25 +0000
432@@ -20,19 +20,18 @@
433
434 from PyQt4 import QtGui
435
436-from ubuntuone.controlpanel import backend
437+from ubuntuone.controlpanel import cache
438 from ubuntuone.controlpanel.gui.qt.loadingoverlay import LoadingOverlay
439
440
441-class UbuntuOneBin(QtGui.QWidget):
442+class UbuntuOneBin(cache.Cache, QtGui.QWidget):
443 """The base widget for the Control Panel's tabs."""
444
445 ui_class = None
446- logger = None
447
448- def __init__(self, parent=None):
449+ def __init__(self, *args, **kwargs):
450 """Initialize the UI of the widget."""
451- QtGui.QWidget.__init__(self, parent)
452+ super(UbuntuOneBin, self).__init__(*args, **kwargs)
453 self.ui = None
454 if self.ui_class is not None:
455 # self.ui_class is not callable
456@@ -46,12 +45,8 @@
457 self._is_processing = None
458 self.is_processing = False
459
460- self.backend = backend.ControlBackend()
461 self._setup()
462
463- if self.logger is not None:
464- self.logger.debug('%s: started.', self.__class__.__name__)
465-
466 def _get_is_processing(self):
467 """Get the value of is_processing."""
468 return self._is_processing
469
470=== added file 'ubuntuone/controlpanel/tests/test_cache.py'
471--- ubuntuone/controlpanel/tests/test_cache.py 1970-01-01 00:00:00 +0000
472+++ ubuntuone/controlpanel/tests/test_cache.py 2011-09-02 18:12:25 +0000
473@@ -0,0 +1,51 @@
474+# -*- coding: utf-8 -*-
475+
476+# Authors: Natalia B. Bidart <nataliabidart@canonical.com>
477+#
478+# Copyright 2011 Canonical Ltd.
479+#
480+# This program is free software: you can redistribute it and/or modify it
481+# under the terms of the GNU General Public License version 3, as published
482+# by the Free Software Foundation.
483+#
484+# This program is distributed in the hope that it will be useful, but
485+# WITHOUT ANY WARRANTY; without even the implied warranties of
486+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
487+# PURPOSE. See the GNU General Public License for more details.
488+#
489+# You should have received a copy of the GNU General Public License along
490+# with this program. If not, see <http://www.gnu.org/licenses/>.
491+
492+"""Tests for the control panel cache."""
493+
494+from ubuntuone.controlpanel import backend, cache
495+from ubuntuone.controlpanel.tests import TestCase
496+
497+
498+class FakedBackend(object):
499+ """A faked backend."""
500+
501+
502+class CacheTestCase(TestCase):
503+ """Test suite for the Cache object."""
504+
505+ def setUp(self):
506+ super(CacheTestCase, self).setUp()
507+ self.patch(backend, 'ControlBackend', object)
508+ self.obj = cache.Cache()
509+ self.addCleanup(self.obj.clear)
510+
511+ def test_backend(self):
512+ """The backend instance is successfully created."""
513+ self.assertIsInstance(self.obj.backend, cache.backend.ControlBackend)
514+
515+ def test_backend_is_cached(self):
516+ """The backend instance is cached."""
517+ obj2 = cache.Cache()
518+ self.assertTrue(self.obj.backend is obj2.backend)
519+
520+ def test_clear(self):
521+ """The cached stuff are cleared."""
522+ old_backend = self.obj.backend
523+ self.obj.clear()
524+ self.assertFalse(self.obj.backend is old_backend)

Subscribers

People subscribed via source and target branches