Exemplo n.º 1
0
 def test_add_device_context(self):
     """
     Ensure that adding a device context works
     """
     manager = SessionManager([], self.storage)
     manager.add_device_context(self.context)
     self.assertIn(self.context, manager.device_context_list)
Exemplo n.º 2
0
 def test_default_device_context__no_contexts(self):
     """
     Verify that accessing SessionManager.default_device_context returns
     None when the manager doesn't have any device context objects yet
     """
     manager = SessionManager([], self.storage)
     self.assertIsNone(manager.default_device_context, None)
Exemplo n.º 3
0
 def setUp(self):
     self.storage = mock.Mock(name="storage", spec=SessionStorage)
     self.state = mock.Mock(name="state", spec=SessionState)
     self.context = mock.Mock(name="context", spec=SessionDeviceContext)
     self.context2 = mock.Mock(name='context2',
                               spec_set=SessionDeviceContext)
     self.context_list = [self.context]  # NOTE: just the first context
     self.manager = SessionManager(self.context_list, self.storage)
Exemplo n.º 4
0
 def test_on_device_context_removed(self):
     """
     Ensure that removing a device context sends the appropriate signal
     """
     manager = SessionManager([self.context], self.storage)
     self.watchSignal(manager.on_device_context_removed)
     manager.remove_device_context(self.context)
     self.assertSignalFired(manager.on_device_context_removed, self.context)
Exemplo n.º 5
0
 def test_add_device_context__twice(self):
     """
     Ensure that you cannot add the same device context twice
     """
     manager = SessionManager([], self.storage)
     manager.add_device_context(self.context)
     with self.assertRaises(ValueError):
         manager.add_device_context(self.context)
Exemplo n.º 6
0
 def test_storage(self):
     """
     verify that accessing SessionManager.storage works okay
     """
     storage = mock.Mock(name="storage", spec=SessionStorage)
     state = mock.Mock(name="state", spec=SessionState)
     manager = SessionManager(state, storage)
     self.assertIs(manager.storage, storage)
Exemplo n.º 7
0
 def test_add_device_context__add_another(self):
     """
     Ensure that adding a second context also works
     """
     manager = SessionManager([], self.storage)
     manager.add_device_context(self.context)
     manager.add_device_context(self.context2)
     self.assertIn(self.context, manager.device_context_list)
     self.assertIn(self.context2, manager.device_context_list)
Exemplo n.º 8
0
 def test_add_local_device_context(self):
     """
     Ensure that using add_local_device_context() adds a context with
     a special 'local' device and fires the appropriate signal
     """
     manager = SessionManager([], self.storage)
     self.watchSignal(manager.on_device_context_added)
     cls_name = "plainbox.impl.session.manager.SessionDeviceContext"
     with mock.patch(cls_name) as sdc:
         manager.add_local_device_context()
         self.assertSignalFired(manager.on_device_context_added, sdc())
         self.assertIn(sdc(), manager.device_context_list)
Exemplo n.º 9
0
 def test_checkpoint(self):
     """
     verify that SessionManager.checkpoint() creates an image of the
     suspended session and writes it using the storage system.
     """
     storage = mock.Mock(name="storage", spec=SessionStorage)
     state = mock.Mock(name="state", spec=SessionState)
     manager = SessionManager(state, storage)
     # Mock the suspend helper, we don't want to suspend our mock objects
     helper_name = "plainbox.impl.session.manager.SessionSuspendHelper"
     with mock.patch(helper_name, spec=SessionSuspendHelper) as helper_cls:
         # Call the tested method
         manager.checkpoint()
         # Ensure that a fresh instance of the suspend helper was used to
         # call the suspend() method and that the session state parameter
         # was passed to it.
         helper_cls().suspend.assert_called_with(state)
     # Ensure that save_checkpoint() was called on the storage object with
     # the return value of what the suspend helper produced.
     storage.save_checkpoint.assert_called_with(helper_cls().suspend(state))