def test_prepare_formdata_state_id_number(mock_i90):
    addr = baker.make_recipe("official.absentee_ballot_address")
    state = baker.make_recipe("election.state")
    ballot_request = baker.make_recipe(
        "absentee.ballot_request",
        region=addr.office.region,
        state=state,
    )

    # Default
    form_data = prepare_formdata(
        ballot_request,
        STATE_ID_NUMBER,
        IS_18_OR_OVER,
    )

    assert form_data["state_id_number"] == STATE_ID_NUMBER
    assert form_data.get("state_id_number_opt_1") == None
    assert form_data.get("state_id_number_opt_2") == None
    assert form_data.get("state_id_number_opt_3") == None

    # Option 1
    ballot_request.state_fields = {
        "state_id_number_opt_1": True,
    }
    form_data = prepare_formdata(
        ballot_request,
        STATE_ID_NUMBER,
        IS_18_OR_OVER,
    )

    assert form_data["state_id_number"] == STATE_ID_NUMBER
    assert form_data.get("state_id_number_opt_1") == STATE_ID_NUMBER
    assert form_data.get("state_id_number_opt_2") == None
    assert form_data.get("state_id_number_opt_3") == None

    # Option 2
    ballot_request.state_fields = {
        "state_id_number_opt_2": True,
    }
    form_data = prepare_formdata(
        ballot_request,
        STATE_ID_NUMBER,
        IS_18_OR_OVER,
    )

    assert form_data["state_id_number"] == STATE_ID_NUMBER
    assert form_data.get("state_id_number_opt_1") == None
    assert form_data.get("state_id_number_opt_2") == STATE_ID_NUMBER
    assert form_data.get("state_id_number_opt_3") == None
def test_prepare_formdata_auto_static(mocker, mock_i90):
    addr = baker.make_recipe("official.absentee_ballot_address")
    state = baker.make_recipe("election.state")
    ballot_request = baker.make_recipe(
        "absentee.ballot_request",
        region=addr.office.region,
        state=state,
    )

    mocker.patch.dict(
        STATE_DATA,
        {
            state.code: {
                "auto_fields": [{
                    "type": "static",
                    "slug": "foo",
                    "value": "bar"
                }]
            }
        },
    )

    form_data = prepare_formdata(
        ballot_request,
        STATE_ID_NUMBER,
        IS_18_OR_OVER,
    )
    assert form_data["foo"] == "bar"
def test_prepare_formdata_auto_todays_date(mocker, mock_i90):
    addr = baker.make_recipe("official.absentee_ballot_address")
    state = baker.make_recipe("election.state")
    ballot_request = baker.make_recipe(
        "absentee.ballot_request",
        region=addr.office.region,
        state=state,
        submit_date=datetime.date(2020, 5, 10),
    )

    mocker.patch.dict(
        STATE_DATA,
        {
            state.code: {
                "auto_fields": [{
                    "type": "todays_date",
                    "slug": "some_date"
                }]
            }
        },
    )

    form_data = prepare_formdata(
        ballot_request,
        STATE_ID_NUMBER,
        IS_18_OR_OVER,
    )
    assert form_data["some_date"] == "05/10/2020"
def test_prepare_formdata_auto_copy(mocker, mock_i90):
    addr = baker.make_recipe("official.absentee_ballot_address")
    state = baker.make_recipe("election.state")
    ballot_request = baker.make_recipe(
        "absentee.ballot_request",
        region=addr.office.region,
        state=state,
        date_of_birth=datetime.date(1992, 5, 10),
        state_fields={"state_field_foo": "state_field_foo_val"},
    )

    mocker.patch.dict(
        STATE_DATA,
        {
            state.code: {
                "auto_fields": [
                    # Copy a top-level field
                    {
                        "type": "copy",
                        "slug": "cp_dob",
                        "field": "date_of_birth"
                    },
                    # Copy a computed field
                    {
                        "type": "copy",
                        "slug": "cp_year",
                        "field": "year_of_birth"
                    },
                    # Copy a state field
                    {
                        "type": "copy",
                        "slug": "cp_state",
                        "field": "state_field_foo"
                    },
                ]
            }
        },
    )

    form_data = prepare_formdata(
        ballot_request,
        STATE_ID_NUMBER,
        IS_18_OR_OVER,
    )

    assert form_data["date_of_birth"] == "05/10/1992"
    assert form_data["cp_dob"] == "05/10/1992"

    assert form_data["year_of_birth"] == "1992"
    assert form_data["cp_year"] == "1992"

    assert form_data["state_field_foo"] == "state_field_foo_val"
    assert form_data["cp_state"] == "state_field_foo_val"
def test_prepare_formdata_just_phone(mock_i90):
    addr = baker.make_recipe("official.absentee_ballot_address", email=None)
    state = baker.make_recipe("election.state")
    ballot_request = baker.make_recipe("absentee.ballot_request",
                                       region=addr.office.region,
                                       state=state)

    add_state_info(state, "vbm_deadline_mail", "Some DEADLINE")
    add_state_info(state, "vbm_first_day_to_apply", "Some DATE")

    form_data = prepare_formdata(
        ballot_request,
        STATE_ID_NUMBER,
        IS_18_OR_OVER,
    )
    assert form_data["leo_contact_info"] == f"Phone: {addr.phone}"
def test_prepare_formdata_state_fields(mock_i90):
    addr = baker.make_recipe("official.absentee_ballot_address")
    state = baker.make_recipe("election.state")
    ballot_request = baker.make_recipe(
        "absentee.ballot_request",
        region=addr.office.region,
        state=state,
        state_fields={"test_custom_field": "some_value"},
    )

    form_data = prepare_formdata(
        ballot_request,
        STATE_ID_NUMBER,
        IS_18_OR_OVER,
    )

    assert form_data["test_custom_field"] == "some_value"
def test_prepare_formdata_no_deadline(mock_i90):
    addr = baker.make_recipe("official.absentee_ballot_address")
    state = baker.make_recipe("election.state")
    ballot_request = baker.make_recipe("absentee.ballot_request",
                                       region=addr.office.region,
                                       state=state)

    add_state_info(state, "vbm_first_day_to_apply", "Some DATE")

    form_data = prepare_formdata(
        ballot_request,
        STATE_ID_NUMBER,
        IS_18_OR_OVER,
    )

    assert form_data["vbm_deadline"] == "As soon as possible."
    assert form_data["vbm_first_day_to_apply"] == "Some DATE"
def test_prepare_formdata_state_fields_dont_overwrite(mock_i90):
    addr = baker.make_recipe("official.absentee_ballot_address")
    state = baker.make_recipe("election.state")
    ballot_request = baker.make_recipe(
        "absentee.ballot_request",
        region=addr.office.region,
        state=state,
    )
    # include a duplicate key in state_fields
    ballot_request.state_fields = {"us_citizen": "not valid"}

    form_data = prepare_formdata(
        ballot_request,
        STATE_ID_NUMBER,
        IS_18_OR_OVER,
    )

    assert form_data["us_citizen"] == True
def test_prepare_formdata_no_state_fields(mock_i90):
    addr = baker.make_recipe("official.absentee_ballot_address")
    state = baker.make_recipe("election.state")
    ballot_request = baker.make_recipe(
        "absentee.ballot_request",
        region=addr.office.region,
        state=state,
        state_fields=None,
    )
    add_state_info(state, "vbm_deadline_mail", "Some DEADLINE")

    form_data = prepare_formdata(
        ballot_request,
        STATE_ID_NUMBER,
        IS_18_OR_OVER,
    )

    assert form_data["vbm_deadline"] == "some deadline"
Beispiel #10
0
def test_prepare_formdata_no_first_day_to_apply(mock_i90):
    addr = baker.make_recipe("official.absentee_ballot_address")
    state = baker.make_recipe("election.state")
    ballot_request = baker.make_recipe("absentee.ballot_request",
                                       region=addr.office.region,
                                       state=state)

    add_state_info(state, "vbm_deadline_mail", "Some DEADLINE")

    form_data = prepare_formdata(
        ballot_request,
        STATE_ID_NUMBER,
        IS_18_OR_OVER,
    )

    assert form_data["vbm_deadline"] == "some deadline"
    assert (form_data["vbm_first_day_to_apply"] ==
            "At least 55 days before the election.")
Beispiel #11
0
def test_prepare_formdata_no_phone_or_email(mock_i90):
    addr = baker.make_recipe("official.absentee_ballot_address",
                             email=None,
                             phone=None)
    state = baker.make_recipe("election.state")
    ballot_request = baker.make_recipe("absentee.ballot_request",
                                       region=addr.office.region,
                                       state=state)

    add_state_info(state, "vbm_deadline_mail", "Some DEADLINE")
    add_state_info(state, "vbm_first_day_to_apply", "Some DATE")

    form_data = prepare_formdata(
        ballot_request,
        STATE_ID_NUMBER,
        IS_18_OR_OVER,
    )

    assert (form_data["leo_contact_info"] ==
            "https://www.voteamerica.com/local-election-offices/")
Beispiel #12
0
def test_prepare_formdata(mock_i90):
    addr = baker.make_recipe("official.absentee_ballot_address")
    state = baker.make_recipe("election.state")
    ballot_request = baker.make_recipe("absentee.ballot_request",
                                       region=addr.office.region,
                                       state=state)

    add_state_info(state, "vbm_deadline_mail", "Some DEADLINE")
    add_state_info(state, "vbm_first_day_to_apply", "Some DATE")

    form_data = prepare_formdata(
        ballot_request,
        STATE_ID_NUMBER,
        IS_18_OR_OVER,
    )
    assert form_data["mailto"] == ABSENTEE_BALLOT_MAILING_ADDRESS
    assert form_data["vbm_deadline"] == "some deadline"
    assert form_data["vbm_first_day_to_apply"] == "Some DATE"
    assert form_data[
        "leo_contact_info"] == f"Email: {addr.email}\nPhone: {addr.phone}"
Beispiel #13
0
def test_prepare_formdata_auto_conditional(mocker, mock_i90):
    addr = baker.make_recipe("official.absentee_ballot_address")
    state = baker.make_recipe("election.state")
    ballot_request = baker.make_recipe(
        "absentee.ballot_request",
        email="*****@*****.**",
        region=addr.office.region,
        state=state,
        date_of_birth=datetime.date(1992, 5, 10),
        state_fields={"state_field_foo": "state_field_foo_val"},
    )

    mocker.patch.dict(
        STATE_DATA,
        {
            state.code: {
                "auto_fields": [
                    # This one should activate
                    {
                        "type": "conditional",
                        "condition": {
                            "slug": "state_field_foo",
                            "value": "state_field_foo_val",
                        },
                        "fill": {
                            "slug": "filled_field",
                            "value": "filled_value"
                        },
                    },
                    # This one should activate
                    {
                        "type": "conditional",
                        "condition": {
                            "slug": "state_field_foo",
                            "value": "state_field_foo_val",
                        },
                        "fill": {
                            "slug": "filled_field_2",
                            "value_from": "email"
                        },
                    },
                    # This one should be ignored
                    {
                        "type": "conditional",
                        "condition": {
                            "slug": "state_field_foo",
                            "value": "state_field_bar_val",
                        },
                        "fill": {
                            "slug": "wrong_fill",
                            "value": "wrong_val"
                        },
                    },
                    # This one should also be ignored
                    {
                        "type": "conditional",
                        "condition": {
                            "slug": "state_field_other",
                            "value": "state_field_bar_val",
                        },
                        "fill": {
                            "slug": "wrong_fill_2",
                            "value_from": "email"
                        },
                    },
                ]
            }
        },
    )

    form_data = prepare_formdata(
        ballot_request,
        STATE_ID_NUMBER,
        IS_18_OR_OVER,
    )

    assert form_data["state_field_foo"] == "state_field_foo_val"
    assert form_data["filled_field"] == "filled_value"
    assert form_data["filled_field_2"] == "*****@*****.**"
    assert form_data.get("wrong_fill") is None
    assert form_data.get("wrong_fill_2") is None