def query_single_train_task(): """Query single train task""" plugin_name = request.args.get('plugin_name') train_id = get_train_id(request) processor = TrainTaskManager(DATA_MANAGER) tasks = processor.get_single_train_task(train_id=train_id, plugin_name=plugin_name) return jsonify(tasks)
def test_get_single_train_task_with_not_exists_train_id(self): """Test getting single train task with not exists train_id.""" train_task_manager = TrainTaskManager(self._mock_data_manager) for plugin_name in PluginNameEnum.list_members(): test_train_id = "not_exist_id" with pytest.raises(TrainJobNotExistError) as exc_info: _ = train_task_manager.get_single_train_task(plugin_name, test_train_id) assert exc_info.value.message == "Train job is not exist. " \ "Detail: Can not find the train job in data manager." assert exc_info.value.error_code == '50545005'
def test_get_single_train_task_with_not_exists_train_id(self, load_data): """Test getting single train task with not exists train_id.""" train_task_manager = TrainTaskManager(self._mock_data_manager) for plugin_name in PluginNameEnum.list_members(): test_train_id = "not_exist_id" with pytest.raises(ParamValueError) as exc_info: _ = train_task_manager.get_single_train_task( plugin_name, test_train_id) assert exc_info.type == ParamValueError assert exc_info.value.message == "Invalid parameter value. Can not find " \ "the train job in data manager." assert exc_info.value.error_code == '50540002'
def test_get_single_train_task_with_params(self): """Test getting single train task with params.""" train_task_manager = TrainTaskManager(self._mock_data_manager) for plugin_name in PluginNameEnum.list_members(): for test_train_id in self._train_id_list: result = train_task_manager.get_single_train_task(plugin_name, test_train_id) tags = result.get("train_jobs")[0].get("tags") # if it is a UUID if tags: assert test_train_id in self._plugins_id_map.get(plugin_name) else: assert test_train_id not in self._plugins_id_map.get(plugin_name)