Beispiel #1
0
 def testAccountsDaemonError(self, mock_lock, mock_logger, mock_watcher,
                             mock_utils):
     mock_logger_instance = mock.Mock()
     mock_logger.Logger.return_value = mock_logger_instance
     mocks = mock.Mock()
     mocks.attach_mock(mock_lock, 'lock')
     mocks.attach_mock(mock_logger, 'logger')
     mocks.attach_mock(mock_watcher, 'watcher')
     mocks.attach_mock(mock_utils, 'utils')
     mock_lock.LockFile.side_effect = IOError('Test Error')
     with mock.patch.object(accounts_daemon.AccountsDaemon,
                            'HandleAccounts'):
         accounts_daemon.AccountsDaemon()
         expected_calls = [
             mock.call.logger.Logger(name=mock.ANY,
                                     debug=False,
                                     facility=mock.ANY),
             mock.call.watcher.MetadataWatcher(logger=mock_logger_instance),
             mock.call.utils.AccountsUtils(logger=mock_logger_instance,
                                           groups=None,
                                           remove=False),
             mock.call.lock.LockFile(accounts_daemon.LOCKFILE),
             mock.call.logger.Logger().warning('Test Error'),
         ]
         self.assertEqual(mocks.mock_calls, expected_calls)
Beispiel #2
0
 def testAccountsDaemon(self, mock_lock, mock_logger, mock_watcher,
                        mock_utils):
     mock_logger_instance = mock.Mock()
     mock_logger.Logger.return_value = mock_logger_instance
     mocks = mock.Mock()
     mocks.attach_mock(mock_lock, 'lock')
     mocks.attach_mock(mock_logger, 'logger')
     mocks.attach_mock(mock_watcher, 'watcher')
     mocks.attach_mock(mock_utils, 'utils')
     with mock.patch.object(accounts_daemon.AccountsDaemon,
                            'HandleAccounts') as mock_handle:
         accounts_daemon.AccountsDaemon(groups='foo,bar',
                                        remove=True,
                                        debug=True)
         expected_calls = [
             mock.call.logger.Logger(name=mock.ANY,
                                     debug=True,
                                     facility=mock.ANY),
             mock.call.watcher.MetadataWatcher(logger=mock_logger_instance),
             mock.call.utils.AccountsUtils(logger=mock_logger_instance,
                                           groups='foo,bar',
                                           remove=True),
             mock.call.lock.LockFile(accounts_daemon.LOCKFILE),
             mock.call.lock.LockFile().__enter__(),
             mock.call.logger.Logger().info(mock.ANY),
             mock.call.watcher.MetadataWatcher().WatchMetadata(
                 mock_handle, recursive=True, timeout=mock.ANY),
             mock.call.lock.LockFile().__exit__(None, None, None),
         ]
         self.assertEqual(mocks.mock_calls, expected_calls)