def test_half_wait_get(self): result = {'r': None} def set_result(): result['r'] = [{}] log_manager = ExecuteLogManager() log_manager.get_current_execute_log_details = Mock(side_effect=lambda *a, **ka: result['r']) log_manager.is_running = Mock(return_value=True) time = TimeMock() time.call_on(115, set_result) with patch("monitorrent.rest.execute.time", time): execute_log_current = ExecuteLogCurrent(log_manager) self.api.add_route(self.test_route, execute_log_current) body = self.simulate_request(self.test_route, decode='utf-8') self.assertEqual(self.srmock.status, falcon.HTTP_OK) result = json.loads(body) self.assertEqual(result, {'is_running': True, 'logs': [{}]})
def test_execute_logs_failure(self): log_manager = ExecuteLogManager() log_manager.get_current_execute_log_details = Mock( side_effect=Exception) log_manager.is_running = Mock(return_value=True) execute_log_current = ExecuteLogCurrent(log_manager) time = TimeMock() with patch("monitorrent.rest.execute.time", time): self.api.add_route(self.test_route, execute_log_current) self.simulate_request(self.test_route, decode='utf-8') self.assertEqual(self.srmock.status, falcon.HTTP_INTERNAL_SERVER_ERROR)
def test_no_wait_get(self): log_manager = ExecuteLogManager() log_manager.get_current_execute_log_details = Mock(return_value=[{}]) log_manager.is_running = Mock(return_value=True) time = TimeMock() with patch("monitorrent.rest.execute.time", time): execute_log_current = ExecuteLogCurrent(log_manager) self.api.add_route(self.test_route, execute_log_current) body = self.simulate_request(self.test_route, decode='utf-8') self.assertEqual(self.srmock.status, falcon.HTTP_OK) result = json.loads(body) self.assertEqual(result, {'is_running': True, 'logs': [{}]})