def test_given_empty_analyzer_results_then_list_created_successfully(): analyzer_results = AppEntitiesConvertor.analyzer_results_from_json([]) assert len(analyzer_results) == len([]) for result_a in analyzer_results: same_result_in_content = __find_element([], result_a.entity_type) assert same_result_in_content assert result_a.score == same_result_in_content.get("score") assert result_a.start == same_result_in_content.get("start") assert result_a.end == same_result_in_content.get("end")
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")
def test_given_invalid_json_for_analyzer_result_then_we_fail( request_json, result_text): with pytest.raises(InvalidParamException) as e: AppEntitiesConvertor.analyzer_results_from_json(request_json) assert result_text == e.value.err_msg
def test_given_anonymize_called_with_multiple_scenarios_then_expected_results_returned( analyzer_json, result): analyzer_results = AppEntitiesConvertor.analyzer_results_from_json( analyzer_json) assert analyzer_results == result