~ubuntuone-control-tower/ubuntuone-control-panel/trunk

« back to all changes in this revision

Viewing changes to ubuntuone/controlpanel/integrationtests/test_dbus_service.py

  • Committer: Tarmac
  • Author(s): Natalia B. Bidart
  • Date: 2011-04-13 21:33:31 UTC
  • mfrom: (135.1.3 dont-start-syncdaemon)
  • Revision ID: tarmac-20110413213331-8i8d54cl8bkp5ld4
- Fixed (LP: #744731) with:
- Avoid creating a control-panel-backend in the OverviewPanel.
- Avoid FileSyncService and FileSyncStatus to start syncdaemon until load() is called.
- Make the dbus layer for the control panel backend not set the FileStatusChanged signal until is actually needed

Show diffs side-by-side

added added

removed removed

Lines of Context:
122
122
        dbus_service.MSG_KEY: 'test me please',
123
123
        dbus_service.STATUS_KEY: dbus_service.FILE_SYNC_IDLE,
124
124
    }
125
 
    status_changed_handler = None
126
125
    shutdown_func = None
127
126
 
128
127
    def __init__(self, shutdown_func=None):
129
128
        MockBackend.shutdown_func = shutdown_func
 
129
        self._status_changed_handler = []
130
130
 
131
131
    def _process(self, result):
132
132
        """Process the request with the given result."""
135
135
            return defer.fail(self.exception(result))
136
136
        return defer.succeed(result)
137
137
 
 
138
    def _set_status_changed_handler(self, handler):
 
139
        """Set 'handler' to be called when file sync status changes."""
 
140
        if handler is not None:
 
141
            self._status_changed_handler.append(handler)
 
142
        else:
 
143
            self._status_changed_handler = []
 
144
 
 
145
    def _get_status_changed_handler(self):
 
146
        """Return the handler to be called when file sync status changes."""
 
147
        if len(self._status_changed_handler) > 0:
 
148
            result = self._status_changed_handler[-1]
 
149
        else:
 
150
            result = None
 
151
        return result
 
152
 
 
153
    status_changed_handler = property(_get_status_changed_handler,
 
154
                                      _set_status_changed_handler)
 
155
 
138
156
    def account_info(self):
139
157
        """Get the user account info."""
140
158
        return self._process(SAMPLE_ACCOUNT_INFO)
737
755
    def test_status_changed_handler(self):
738
756
        """The status changed handler is properly set."""
739
757
        be = MockBackend()
 
758
        dbus_service.ControlPanelBackend(backend=be)
 
759
 
 
760
        self.assertEqual(be.status_changed_handler, None)
 
761
 
 
762
    def test_status_changed_handler_after_status_requested(self):
 
763
        """The status changed handler is properly set."""
 
764
        be = MockBackend()
740
765
        cpbe = dbus_service.ControlPanelBackend(backend=be)
 
766
        cpbe.file_sync_status()
741
767
 
742
768
        self.assertEqual(be.status_changed_handler, cpbe.process_status)
743
769
 
 
770
    def test_status_changed_handler_after_status_requested_twice(self):
 
771
        """The status changed handler is properly set."""
 
772
        be = MockBackend()
 
773
        cpbe = dbus_service.ControlPanelBackend(backend=be)
 
774
        cpbe.file_sync_status()
 
775
        cpbe.file_sync_status()
 
776
 
 
777
        # pylint: disable=W0212
 
778
        self.assertEqual(be._status_changed_handler, [cpbe.process_status])
 
779
 
744
780
 
745
781
class ShutdownTestCase(BaseTestCase):
746
782
    """Test for the DBus service shurdown."""