def test_applications_to_retry_are_processed( self, process_beneficiary_application): # given get_all_application_ids = Mock(return_value=[123]) find_applications_ids_to_retry = Mock(return_value=[456, 789]) get_details = Mock() get_details.side_effect = [ make_old_application_detail(123, "closed"), make_old_application_detail(456, "closed"), make_old_application_detail(789, "closed"), ] has_already_been_imported = Mock(return_value=False) has_already_been_created = Mock(return_value=False) # when old_remote_import.run( ONE_WEEK_AGO, get_all_applications_ids=get_all_application_ids, get_applications_ids_to_retry=find_applications_ids_to_retry, get_details=get_details, already_imported=has_already_been_imported, already_existing_user=has_already_been_created, ) # then assert process_beneficiary_application.call_count == 3
def test_an_error_status_is_saved_when_an_application_is_not_parsable( self, mocked_parse_beneficiary_information, app): # given get_all_application_ids = Mock(return_value=[123]) find_applications_ids_to_retry = Mock(return_value=[]) get_details = Mock( side_effect=[make_old_application_detail(123, "closed")]) has_already_been_imported = Mock(return_value=False) has_already_been_created = Mock(return_value=False) mocked_parse_beneficiary_information.side_effect = [Exception()] # when old_remote_import.run( ONE_WEEK_AGO, get_all_applications_ids=get_all_application_ids, get_applications_ids_to_retry=find_applications_ids_to_retry, get_details=get_details, already_imported=has_already_been_imported, already_existing_user=has_already_been_created, ) # then beneficiary_import = BeneficiaryImport.query.first() assert beneficiary_import.currentStatus == ImportStatus.ERROR assert beneficiary_import.applicationId == 123 assert beneficiary_import.detail == "Le dossier 123 contient des erreurs et a été ignoré - Procedure 2567158"
def test_application_with_known_email_are_saved_as_rejected( self, process_beneficiary_application, app): # given get_all_application_ids = Mock(return_value=[123]) find_applications_ids_to_retry = Mock(return_value=[]) get_details = Mock( return_value=make_old_application_detail(123, "closed")) user = User() user.email = "*****@*****.**" has_already_been_imported = Mock(return_value=False) has_already_been_created = Mock(return_value=True) # when old_remote_import.run( ONE_WEEK_AGO, get_all_applications_ids=get_all_application_ids, get_applications_ids_to_retry=find_applications_ids_to_retry, get_details=get_details, already_imported=has_already_been_imported, already_existing_user=has_already_been_created, ) # then beneficiary_import = BeneficiaryImport.query.first() assert beneficiary_import.currentStatus == ImportStatus.REJECTED assert beneficiary_import.applicationId == 123 assert beneficiary_import.detail == "Compte existant avec cet email" process_beneficiary_application.assert_not_called()
def test_application_with_known_application_id_are_not_processed( self, process_beneficiary_application): # given get_all_application_ids = Mock(return_value=[123, 456]) find_applications_ids_to_retry = Mock(return_value=[]) get_details = Mock( return_value=make_old_application_detail(123, "closed")) user = User() user.email = "*****@*****.**" has_already_been_imported = Mock(return_value=True) has_already_been_created = Mock(return_value=False) # when old_remote_import.run( ONE_WEEK_AGO, get_all_applications_ids=get_all_application_ids, get_applications_ids_to_retry=find_applications_ids_to_retry, get_details=get_details, already_imported=has_already_been_imported, already_existing_user=has_already_been_created, ) # then process_beneficiary_application.assert_not_called()
def test_handles_activity_parsing(self): # given application_detail = make_old_application_detail(1, "closed") # when information = parse_beneficiary_information(application_detail) # then assert information["activity"] == "Étudiant"
def test_handles_postal_codes_containing_city_name(self): # given application_detail = make_old_application_detail( 1, "closed", postal_code="67 200 Strasbourg ") # when information = parse_beneficiary_information(application_detail) # then assert information["postal_code"] == "67200"
def test_handles_postal_codes_wrapped_with_spaces(self): # given application_detail = make_old_application_detail( 1, "closed", postal_code=" 67200 ") # when information = parse_beneficiary_information(application_detail) # then assert information["postal_code"] == "67200"
def test_handles_lowercased_mixed_digits_and_letter_department_code(self): # given application_detail = make_old_application_detail( 1, "closed", department_code="2a - Haute-Corse") # when information = parse_beneficiary_information(application_detail) # then assert information["department"] == "2a"
def test_handles_three_digits_department_code(self): # given application_detail = make_old_application_detail( 1, "closed", department_code="973 - Guyane") # when information = parse_beneficiary_information(application_detail) # then assert information["department"] == "973"
def test_handles_activity_even_if_activity_is_not_filled(self): # given application_detail = make_old_application_detail(1, "closed", activity=None) # when information = parse_beneficiary_information(application_detail) # then assert information["activity"] is None
def test_handles_civility_parsing(self): # given application_detail = make_old_application_detail(1, "closed", civility="M.") # when information = parse_beneficiary_information(application_detail) # then assert information["civility"] == "M."
def test_handles_department_code_with_another_label(self): # given application_detail = make_old_application_detail( 1, "closed", department_code="67 - Bas-Rhin") for field in application_detail["dossier"]["champs"]: label = field["type_de_champ"]["libelle"] if label == "Veuillez indiquer votre département": field["type_de_champ"][ "libelle"] = "Veuillez indiquer votre département de résidence" # when information = parse_beneficiary_information(application_detail) # then assert information["department"] == "67"
def test_beneficiary_is_created_with_procedure_id( self, process_beneficiary_application, app): # given get_all_application_ids = Mock(return_value=[123]) find_applications_ids_to_retry = Mock(return_value=[]) get_details = Mock( side_effect=[make_old_application_detail(123, "closed")]) has_already_been_imported = Mock(return_value=False) has_already_been_created = Mock(return_value=False) # when old_remote_import.run( ONE_WEEK_AGO, get_all_applications_ids=get_all_application_ids, get_applications_ids_to_retry=find_applications_ids_to_retry, get_details=get_details, already_imported=has_already_been_imported, already_existing_user=has_already_been_created, ) # then process_beneficiary_application.assert_called_with( information={ "last_name": "Doe", "first_name": "Jane", "civility": "Mme", "email": "*****@*****.**", "application_id": 123, "department": "67", "phone": "0123456789", "birth_date": datetime(2000, 5, 1, 0, 0), "activity": "Étudiant", "postal_code": "67200", }, error_messages=[], new_beneficiaries=[], retry_ids=[], procedure_id=2567158, )