def test_an_import_status_is_saved_if_beneficiary_is_a_duplicate( self, mock_get_beneficiary_duplicates, app): # given information = { "department": "93", "last_name": "Doe", "first_name": "Jane", "birth_date": datetime(2000, 5, 1), "email": "*****@*****.**", "phone": "0612345678", "postal_code": "93130", "application_id": 123, "civility": "Mme", "activity": "Étudiant", } mock_get_beneficiary_duplicates.return_value = [ create_user(idx=11), create_user(idx=22) ] # when remote_import.process_beneficiary_application(information, error_messages=[], new_beneficiaries=[], retry_ids=[], procedure_id=123456) # then beneficiary_import = BeneficiaryImport.query.first() assert beneficiary_import.currentStatus == ImportStatus.DUPLICATE assert beneficiary_import.applicationId == 123 assert beneficiary_import.detail == "Utilisateur en doublon : 11, 22"
def test_beneficiary_is_created_if_duplicates_are_found_but_id_is_in_retry_list( self, send_activation_email, app): # given information = { "department": "93", "last_name": "Doe", "first_name": "Jane", "birth_date": datetime(2000, 5, 1), "email": "*****@*****.**", "phone": "0612345678", "postal_code": "93130", "application_id": 123, "civility": "Mme", "activity": "Étudiant", } existing_user = create_user(date_of_birth=datetime(2000, 5, 1), first_name="Jane", last_name="Doe") repository.save(existing_user) retry_ids = [123] # when remote_import.process_beneficiary_application(information, error_messages=[], new_beneficiaries=[], retry_ids=retry_ids, procedure_id=123456) # then send_activation_email.assert_called() beneficiary_import = BeneficiaryImport.query.filter_by( applicationId=123).first() assert beneficiary_import.currentStatus == ImportStatus.CREATED
def test_account_activation_email_is_sent( self, send_activation_email, mock_repository, create_beneficiary_from_application, app): # given information = { "department": "93", "last_name": "Doe", "first_name": "Jane", "birth_date": datetime(2000, 5, 1), "email": "*****@*****.**", "phone": "0612345678", "postal_code": "93130", "application_id": 123, "civility": "Mme", "activity": "Étudiant", } create_beneficiary_from_application.return_value = create_user() # when remote_import.process_beneficiary_application(information, error_messages=[], new_beneficiaries=[], retry_ids=[], procedure_id=123456) # then send_activation_email.assert_called()
def test_an_import_status_is_saved_if_beneficiary_is_created(self, app): # given app.mailjet_client = Mock(spec=Client) app.mailjet_client.send = Mock() information = { "department": "93", "last_name": "Doe", "first_name": "Jane", "birth_date": datetime(2000, 5, 1), "email": "*****@*****.**", "phone": "0612345678", "postal_code": "93130", "application_id": 123, "civility": "Mme", "activity": "Étudiant", } # when remote_import.process_beneficiary_application(information, error_messages=[], new_beneficiaries=[], retry_ids=[], procedure_id=123456) # then beneficiary_import = BeneficiaryImport.query.first() assert beneficiary_import.beneficiary.email == "*****@*****.**" assert beneficiary_import.currentStatus == ImportStatus.CREATED assert beneficiary_import.applicationId == 123
def test_new_beneficiaries_are_recorded_with_deposit(self, app): # given app.mailjet_client = Mock(spec=Client) app.mailjet_client.send = Mock() information = { "department": "93", "last_name": "Doe", "first_name": "Jane", "birth_date": datetime(2000, 5, 1), "email": "*****@*****.**", "phone": "0612345678", "postal_code": "93130", "application_id": 123, "civility": "Mme", "activity": "Étudiant", } # when remote_import.process_beneficiary_application(information, error_messages=[], new_beneficiaries=[], retry_ids=[], procedure_id=123456) # then first = User.query.first() assert first.email == "*****@*****.**" assert first.wallet_balance == 500 assert first.civility == "Mme" assert first.activity == "Étudiant"
def test_error_is_collected_if_beneficiary_could_not_be_saved( self, send_activation_email, mock_repository, create_beneficiary_from_application, app ): # given information = { "department": "93", "last_name": "Doe", "first_name": "Jane", "birth_date": datetime(2000, 5, 1), "email": "*****@*****.**", "phone": "0612345678", "postal_code": "93130", "application_id": 123, "civility": "Mme", "activity": "Étudiant", } create_beneficiary_from_application.side_effect = [User()] mock_repository.save.side_effect = [ApiErrors({"postalCode": ["baaaaad value"]})] new_beneficiaries = [] error_messages = [] # when remote_import.process_beneficiary_application( information, error_messages, new_beneficiaries, retry_ids=[], procedure_id=123456 ) # then send_activation_email.assert_not_called() assert error_messages == ['{\n "postalCode": [\n "baaaaad value"\n ]\n}'] assert not new_beneficiaries