def test_given_no_custom_operator_then_expected_result_returned(): result = False content = get_content() anonymizers_config = AppEntitiesConvertor.operators_config_from_json( content.get("anonymizers")) assert AppEntitiesConvertor.check_custom_operator( anonymizers_config) == result
def test_given_custom_operator_then_expected_result_returned(): result = True anonymizers = { "DEFAULT": { "type": "replace", "new_value": "ANONYMIZED" }, "PHONE_NUMBER": { "type": "custom", "lambda": "lambda x: x[::-1]" } } anonymizers_config = AppEntitiesConvertor.operators_config_from_json( anonymizers) assert AppEntitiesConvertor.check_custom_operator( anonymizers_config) == result
def anonymize() -> Response: content = request.get_json() if not content: raise BadRequest("Invalid request json") anonymizers_config = AppEntitiesConvertor.operators_config_from_json( content.get("anonymizers")) if AppEntitiesConvertor.check_custom_operator(anonymizers_config): raise BadRequest("Custom type anonymizer is not supported") analyzer_results = AppEntitiesConvertor.analyzer_results_from_json( content.get("analyzer_results")) anoymizer_result = self.anonymizer.anonymize( text=content.get("text"), analyzer_results=analyzer_results, operators=anonymizers_config, ) return Response(anoymizer_result.to_json(), mimetype="application/json")