def test_convert_bytes_to_string(): # byte string will be decoded byte_string = b"\xcf\x84o\xcf\x81\xce\xbdo\xcf\x82" decoded_string = "τoρνoς" assert utils.convert_bytes_to_string(byte_string) == decoded_string # string remains string assert utils.convert_bytes_to_string(decoded_string) == decoded_string
def inspect_and_save_yaml_config_from_request(self, request_body: bytes, team: Text, project_id: Text) -> Text: """Inspect and save yaml config from `request_body`.""" config_yaml = rasa_core_utils.convert_bytes_to_string(request_body) stack_config = self.inspect_and_load_yaml_config(config_yaml) self.save_config(team, project_id, stack_config) return config_yaml
def add_jwt_key_to_result(results: Dict) -> Dict: """Add JWT public key to a dictionary of 'version' results `results`. Follows basic jwks format: https://auth0.com/docs/jwks """ results["keys"] = [{ "alg": constants.JWT_METHOD, "key": rasa_core_utils.convert_bytes_to_string(config.jwt_public_key), }] return results
async def update_domain(request: Request, user: Dict) -> HTTPResponse: rasa_x_utils.handle_deprecated_request_parameters( request, "store_templates", "store_responses") store_responses = utils.bool_arg(request, "store_responses", False) domain_yaml = rasa_core_utils.convert_bytes_to_string(request.body) try: updated_domain = DomainService(request[REQUEST_DB_SESSION_KEY] ).validate_and_store_domain_yaml( domain_yaml, store_responses=store_responses, username=user["username"]) except InvalidDomain as e: return rasa_x_utils.error(400, "InvalidDomainError", "Could not update domain.", e) return response.text(updated_domain)
async def add_bulk_stories(request: Request, user: Dict[Text, Any]) -> HTTPResponse: story_string = rasa_core_utils.convert_bytes_to_string(request.body) try: saved_stories = await _story_service(request).replace_stories( story_string, user["team"], username=user[USERNAME_KEY]) if saved_stories is not None: return response.json( saved_stories, headers={"X-Total-Count": len(saved_stories)}) except StoryParseError as e: logger.error(e.message) return rasa_x_utils.error( HTTPStatus.BAD_REQUEST, "StoryParseError", "Failed to parse stories.", details=e.message, )
async def modify_story(request: Request, story_id: Text, user: Dict[Text, Any]) -> HTTPResponse: story_string = rasa_core_utils.convert_bytes_to_string(request.body) try: updated_story = await _story_service(request).update_story( story_id, story_string, user) if not updated_story: return response.text("Story could not be found", HTTPStatus.NOT_FOUND) else: return response.json(updated_story) except StoryParseError as e: logger.error(e.message) return rasa_x_utils.error( HTTPStatus.BAD_REQUEST, "StoryParseError", "Failed to modify story.", details=e.message, )
async def add_tests(request: Request, user: Dict[Text, Text]) -> HTTPResponse: end_to_end_test_story = rasa_core_utils.convert_bytes_to_string( request.body) saved_test_stories: List[Text] = TestService.save_tests( end_to_end_test_story) if saved_test_stories and utils.is_git_available(): from rasax.community.services.integrated_version_control.git_service import ( GitService, ) GitService( request[REQUEST_DB_SESSION_KEY]).track_training_data_dumping( user[USERNAME_KEY], time.time()) if saved_test_stories: telemetry.track_e2e_test_created(request.headers.get("Referer")) return response.json(saved_test_stories, HTTPStatus.CREATED) return rasa_x_utils.error( HTTPStatus.BAD_REQUEST, "TestsSaveError", "Failed to save tests.", )