def test_directories(self, *_): c = self.client self.assertIsInstance(c.get_datadir(), unicode) self.assertIsInstance(c.get_dir_manager(), Mock) c.task_server = TaskServer.__new__(TaskServer) c.task_server.client = self.client c.task_server.task_manager = TaskManager.__new__(TaskManager) c.task_server.task_manager.root_path = self.path c.task_server.task_computer = TaskComputer.__new__(TaskComputer) c.task_server.task_computer.dir_manager = DirManager(self.tempdir) c.task_server.task_computer.current_computations = [] c.resource_server = ResourceServer.__new__(ResourceServer) c.resource_server.dir_manager = c.task_server.task_computer.dir_manager self.assertIsInstance(c.get_dir_manager(), DirManager) res_dirs = c.get_res_dirs() self.assertIsInstance(res_dirs, dict) self.assertTrue(len(res_dirs) == 3) for key, value in res_dirs.iteritems(): self.assertIsInstance(key, unicode) self.assertIsInstance(value, unicode) self.assertTrue(self.path in value) res_dir_sizes = c.get_res_dirs_sizes() for key, value in res_dir_sizes.iteritems(): self.assertIsInstance(key, unicode) self.assertIsInstance(value, unicode) self.assertTrue(key in res_dirs)
def test_publish_events(self, send, log, *_): self.client = Client(datadir=self.path, transaction_system=False, connect_to_known_hosts=False, use_docker_machine_manager=False, use_monitor=False) c = self.client def get_balance(*_): d = Deferred() d.callback((1, 2, 3)) return d c.task_server = Mock() c.task_server.task_computer = TaskComputer.__new__(TaskComputer) c.task_server.task_computer.stats = dict() c.get_balance = get_balance c.get_task_count = lambda *_: 0 c.get_supported_task_count = lambda *_: 0 c.connection_status = lambda *_: 'test' c.config_desc.node_snapshot_interval = 1 c.config_desc.network_check_interval = 1 c._publish = Mock() past_time = time.time() - 10**10 future_time = time.time() + 10**10 c.last_nss_time = future_time c.last_net_check_time = future_time c.last_balance_time = future_time c.last_tasks_time = future_time c._Client__publish_events() assert not send.called assert not log.debug.called assert not c._publish.called c.last_nss_time = past_time c.last_net_check_time = past_time c.last_balance_time = past_time c.last_tasks_time = past_time c._Client__publish_events() assert not log.debug.called assert send.call_count == 2 assert c._publish.call_count == 3 def raise_exc(*_): raise Exception('Test exception') c.get_balance = raise_exc c._publish = Mock() send.call_count = 0 c.last_nss_time = past_time c.last_net_check_time = past_time c.last_balance_time = past_time c.last_tasks_time = past_time c._Client__publish_events() assert log.debug.called assert send.call_count == 2 assert c._publish.call_count == 2