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
Example #2
0
def test_given_anonymizers_json_then_we_create_properties_properly(
        anonymizer_json, result
):
    anonymizers_config = AppEntitiesConvertor.operators_config_from_json(
        anonymizer_json.get("anonymizers")
    )
    assert anonymizers_config == result
def test_given_valid_json_then_anonymizers_config_list_created_successfully():
    content = get_content()
    anonymizers_config = AppEntitiesConvertor.operators_config_from_json(
        content.get("anonymizers"))
    assert len(anonymizers_config) == 2
    phone_number_anonymizer = anonymizers_config.get("PHONE_NUMBER")
    assert phone_number_anonymizer.params == {
        "masking_char": "*",
        "chars_to_mask": 4,
        "from_end": True,
    }
    assert phone_number_anonymizer.operator_name == "mask"
    default_anonymizer = anonymizers_config.get("DEFAULT")
    assert default_anonymizer.params == {"new_value": "ANONYMIZED"}
    assert default_anonymizer.operator_name == "replace"
Example #4
0
 def deanonymize() -> Response:
     content = request.get_json()
     if not content:
         raise BadRequest("Invalid request json")
     text = content.get("text")
     deanonymize_entities = AppEntitiesConvertor.deanonymize_entities_from_json(
         content)
     deanonymize_config = AppEntitiesConvertor.operators_config_from_json(
         content.get("deanonymizers"))
     deanonymized_response = self.deanonymize.deanonymize(
         text=text,
         entities=deanonymize_entities,
         operators=deanonymize_config)
     return Response(deanonymized_response.to_json(),
                     mimetype="application/json")
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
Example #6
0
        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"))
            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")