Beispiel #1
0
    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_new_beneficiary_application_details(123, "closed"),
            make_new_beneficiary_application_details(456, "closed"),
            make_new_beneficiary_application_details(789, "closed"),
        ]

        has_already_been_imported = Mock(return_value=False)
        has_already_been_created = Mock(return_value=False)

        # when
        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_tag_user_had_completed_id_check():
    # given
    recieved_beneficiary = UserFactory(hasCompletedIdCheck=False)
    already_beneficiary = BeneficiaryGrant18Factory(hasCompletedIdCheck=True)
    initiated_beneficiary = UserFactory(hasCompletedIdCheck=False)

    get_all_application_ids = Mock(return_value=[123, 456, 789])

    get_details = Mock()
    get_details.side_effect = [
        make_new_beneficiary_application_details(123, "received"),
        make_new_beneficiary_application_details(456, "received"),
        make_new_beneficiary_application_details(789, "initiated"),
    ]

    already_existing_user = Mock()
    already_existing_user.side_effect = [recieved_beneficiary, already_beneficiary, initiated_beneficiary]

    # when
    remote_tag_has_completed.run(
        ONE_WEEK_AGO,
        procedure_id=6712558,
        get_all_applications_ids=get_all_application_ids,
        get_details=get_details,
        already_existing_user=already_existing_user,
    )

    assert User.query.filter(User.hasCompletedIdCheck.is_(True)).count() == 3
Beispiel #3
0
    def test_should_retrieve_applications_from_new_procedure_id(
            self, process_beneficiary_application):
        # given
        get_all_application_ids = Mock(return_value=[123, 456, 789])
        find_applications_ids_to_retry = Mock(return_value=[])

        get_details = Mock()
        get_details.side_effect = [
            make_new_beneficiary_application_details(123, "closed"),
            make_new_beneficiary_application_details(456, "closed"),
            make_new_beneficiary_application_details(789, "closed"),
        ]

        has_already_been_imported = Mock(return_value=False)
        has_already_been_created = Mock(return_value=False)

        # when
        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 get_all_application_ids.call_count == 1
        get_all_application_ids.assert_called_with(6712558, ANY, ANY)
Beispiel #4
0
    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_new_beneficiary_application_details(
                123, "closed"))
        user = User()
        user.email = "*****@*****.**"
        has_already_been_imported = Mock(return_value=True)
        has_already_been_created = Mock(return_value=False)

        # when
        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()
Beispiel #5
0
    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_new_beneficiary_application_details(
                123, "closed"))
        user = User()
        user.email = "*****@*****.**"
        has_already_been_imported = Mock(return_value=False)
        has_already_been_created = Mock(return_value=True)

        # when
        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()
Beispiel #6
0
    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_new_beneficiary_application_details(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
        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 6712558"
    def test_handles_activity_even_if_activity_is_not_filled(self):
        # given
        application_detail = make_new_beneficiary_application_details(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_new_beneficiary_application_details(1, "closed", civility="M.")

        # when
        information = parse_beneficiary_information(application_detail)

        # then
        assert information["civility"] == "M."
    def test_handles_activity_parsing(self):
        # given
        application_detail = make_new_beneficiary_application_details(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_new_beneficiary_application_details(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_new_beneficiary_application_details(1, "closed", postal_code="  93130  ")

        # when
        information = parse_beneficiary_information(application_detail)

        # then
        assert information["postal_code"] == "93130"
    def test_handles_lowercased_mixed_digits_and_letter_department_code(self):
        # given
        application_detail = make_new_beneficiary_application_details(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_new_beneficiary_application_details(1, "closed", department_code="973 - Guyane")

        # when
        information = parse_beneficiary_information(application_detail)

        # then
        assert information["department"] == "973"
    def test_handles_department_code_with_another_label(self):
        # given
        application_detail = make_new_beneficiary_application_details(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"
Beispiel #15
0
    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_new_beneficiary_application_details(123, "closed")
        ])
        has_already_been_imported = Mock(return_value=False)
        has_already_been_created = Mock(return_value=False)

        # when
        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": "John",
                "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,
        )