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_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_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_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_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"
    def test_personal_information_of_beneficiary_are_parsed_from_application_detail(self):
        # when
        information = parse_beneficiary_information(APPLICATION_DETAIL_STANDARD_RESPONSE)

        # then
        assert information["last_name"] == "Doe"
        assert information["first_name"] == "John"
        assert information["birth_date"] == datetime(2000, 5, 1)
        assert information["civility"] == "M."
        assert information["email"] == "*****@*****.**"
        assert information["phone"] == "0123456789"
        assert information["postal_code"] == "93130"
        assert information["application_id"] == 123