def test_complete_create( mock_check_unfinished, mock_get_absentee_contact_info, mock_get_regions_for_address, mock_verify_address, mock_finish, process_ballot_request, feature_flag_on, ): state = baker.make_recipe("election.state", code=VALID_ABSENTEE_INITIAL["state"],) set_fax_allowed(state) mock_get_absentee_contact_info.return_value = AbsenteeContactInfo( fax="+16175551234" ) mock_get_regions_for_address.return_value = ( [baker.make_recipe("official.region", external_id=12345)], False, ) mock_get_absentee_contact_info.return_value = AbsenteeContactInfo( fax="+16175551234" ) client = APIClient() response = client.post(ABSENTEE_API_ENDPOINT_COMPLETE, VALID_ABSENTEE_FULL) assert BallotRequest.objects.count() == 1 ballot_request = BallotRequest.objects.first() assert response.status_code == 200 assert response.json() == { "uuid": str(ballot_request.uuid), "action_id": str(ballot_request.action.pk), "esign_method": "leo_fax", "ovbm_link": "mock-ovbm-link", "region": 12345, "allow_print_and_forward": False, # "deliverable": True, # "mailing_deliverable": None, "request_mailing_deliverable": None, } assert ballot_request.region.external_id == 12345 mock_finish.delay.assert_called_once_with(ballot_request.action.pk) process_ballot_request.assert_called_with(ballot_request, None, True)
def test_contact_info_no_mailing_address(): office = baker.make_recipe("official.office") office.address_set.set([]) contact_info = get_absentee_contact_info(office.region.external_id) assert contact_info == AbsenteeContactInfo(address=None, email=None, phone=None, fax=None) assert contact_info.full_address is None assert contact_info.address1 is None assert contact_info.address2 is None assert contact_info.address3 is None assert contact_info.city_state_zip is None
def test_contact_info_no_email_or_phone(): office = baker.make_recipe("official.office") addr = baker.make_recipe( "official.absentee_ballot_address", office=office, email=None, phone=None, fax=None, ) assert get_absentee_contact_info( office.region.external_id) == AbsenteeContactInfo(address=addr, email=None, phone=None, fax=None)
def test_contact_info_all_in_one_address(): office = baker.make_recipe("official.office") wrong_addr = baker.make_recipe( "official.address", office=office, process_absentee_requests=True, is_physical=False, ) wrong_addr2 = baker.make_recipe( "official.address", office=office, process_absentee_requests=False, is_physical=True, ) wrong_addr3 = baker.make_recipe( "official.address", process_absentee_requests=True, is_physical=True, ) correct_addr = baker.make_recipe("official.absentee_ballot_address", office=office, is_physical=True) contact_info = get_absentee_contact_info(office.region.external_id) assert contact_info == AbsenteeContactInfo( address=correct_addr, email=correct_addr.email, phone=correct_addr.phone, fax=correct_addr.fax, ) assert contact_info.full_address == ABSENTEE_BALLOT_MAILING_ADDRESS assert contact_info.address1 == correct_addr.address assert contact_info.address2 == correct_addr.address2 assert contact_info.address3 == correct_addr.address3 assert ( contact_info.city_state_zip == f"{correct_addr.city.title()}, {correct_addr.state.code} {correct_addr.zipcode}" )
def test_incomplete_create_no_region_matching( mock_check_unfinished, mock_get_absentee_contact_info, mock_get_regions_for_address, mock_verify_address, ): state = baker.make_recipe("election.state", code=VALID_ABSENTEE_INITIAL["state"],) r1 = baker.make_recipe("official.region", state=state, name="B", external_id=2) baker.make_recipe("official.region", state=state, name="C", external_id=3) baker.make_recipe("official.region", state=state, name="A", external_id=1) mock_get_absentee_contact_info.return_value = AbsenteeContactInfo( fax="+16175551234" ) mock_get_regions_for_address.return_value = ([r1], False) client = APIClient() response = client.post( ABSENTEE_API_ENDPOINT_INCOMPLETE_NO_REGION_MATCH, VALID_ABSENTEE_INITIAL ) assert BallotRequest.objects.count() == 1 ballot_request = BallotRequest.objects.first() assert response.status_code == 200 assert response.json() == { "uuid": str(ballot_request.uuid), "action_id": str(ballot_request.action.pk), "region": None, "esign_method": None, "ovbm_link": "mock-ovbm-link", "regions": [ {"name": "A", "external_id": 1}, {"name": "B", "external_id": 2}, {"name": "C", "external_id": 3}, ], "allow_print_and_forward": False, # "deliverable": True, # "mailing_deliverable": None, "request_mailing_deliverable": None, }
def test_contact_info_email_only_override(): office = baker.make_recipe("official.office") correct_addr = baker.make_recipe("official.absentee_ballot_address", office=office, is_physical=True) LeoContactOverride( region=office.region, email="*****@*****.**", ).save() contact_info = get_absentee_contact_info(office.region.external_id) assert contact_info == AbsenteeContactInfo( address=correct_addr, email="*****@*****.**", phone=correct_addr.phone, fax=correct_addr.fax, )
def test_contact_info_method_only_override(): office = baker.make_recipe("official.office") correct_addr = baker.make_recipe("official.absentee_ballot_address", office=office, is_physical=True) LeoContactOverride( region=office.region, submission_method=enums.SubmissionType.SELF_PRINT, ).save() contact_info = get_absentee_contact_info(office.region.external_id) assert contact_info == AbsenteeContactInfo( address=correct_addr, email=correct_addr.email, phone=correct_addr.phone, fax=correct_addr.fax, submission_method_override=enums.SubmissionType.SELF_PRINT, )
def test_incomplete_update_with_esign_filling( mock_check_unfinished, mock_get_absentee_contact_info, mock_verify_address, feature_flag_on, ): state = baker.make_recipe("election.state", code=VALID_ABSENTEE_INITIAL["state"]) set_fax_allowed(state) baker.make_recipe("official.region", external_id=12345) mock_get_absentee_contact_info.return_value = AbsenteeContactInfo( fax="+16175551234" ) client = APIClient() client.post( ABSENTEE_API_ENDPOINT_INCOMPLETE_NO_REGION_MATCH, VALID_ABSENTEE_INITIAL ) assert BallotRequest.objects.count() == 1 ballot_request = BallotRequest.objects.first() response = client.patch( ABSENTEE_API_ENDPOINT_PATCH_INCOMPLETE.format(uuid=ballot_request.uuid), {"address1": "new_address", "region": 12345}, ) assert response.status_code == 200 assert response.json() == { "uuid": str(ballot_request.uuid), "action_id": str(ballot_request.action.pk), "esign_method": "leo_fax", "ovbm_link": "mock-ovbm-link", "region": 12345, "allow_print_and_forward": False, # "deliverable": True, # "mailing_deliverable": None, "request_mailing_deliverable": None, }
def test_contact_info_fallback(): office = baker.make_recipe("official.office") first_priority = baker.make_recipe( "official.absentee_ballot_address", office=office, email=None, phone=None, fax=None, is_physical=True, ) second_priority = baker.make_recipe( "official.address", office=office, process_absentee_requests=True, is_physical=False, email=None, phone="+16175552222", fax=None, ) third_priority = baker.make_recipe( "official.address", office=office, process_absentee_requests=False, is_physical=False, email="*****@*****.**", phone="+16175553333", fax="+16175554444", ) assert get_absentee_contact_info( office.region.external_id) == AbsenteeContactInfo( address=first_priority, email=third_priority.email, phone=second_priority.phone, fax=third_priority.fax, )
def test_incomplete_create_single_matching_region_email( mock_check_unfinished, mock_get_absentee_contact_info, mock_get_regions_for_address, mock_verify_address, feature_flag_on, ): state = baker.make_recipe("election.state", code=VALID_ABSENTEE_INITIAL["state"]) set_email_allowed(state) mock_get_absentee_contact_info.return_value = AbsenteeContactInfo( email="*****@*****.**" ) mock_get_regions_for_address.return_value = ( [baker.make_recipe("official.region", external_id=12345)], False, ) client = APIClient() response = client.post(ABSENTEE_API_ENDPOINT_INCOMPLETE, VALID_ABSENTEE_INITIAL) assert BallotRequest.objects.count() == 1 ballot_request = BallotRequest.objects.first() assert response.status_code == 200 assert response.json() == { "uuid": str(ballot_request.uuid), "action_id": str(ballot_request.action.pk), "region": 12345, "esign_method": "leo_email", "ovbm_link": "mock-ovbm-link", "allow_print_and_forward": False, # "deliverable": True, # "mailing_deliverable": None, "request_mailing_deliverable": None, }
def test_contact_info_full_override(): office = baker.make_recipe("official.office") correct_addr = baker.make_recipe("official.absentee_ballot_address", office=office, is_physical=True) LeoContactOverride( region=office.region, email="*****@*****.**", phone="+19875559876", fax="+18765558765", submission_method=enums.SubmissionType.LEO_FAX, ).save() contact_info = get_absentee_contact_info(office.region.external_id) assert contact_info == AbsenteeContactInfo( address=correct_addr, email="*****@*****.**", phone="+19875559876", fax="+18765558765", submission_method_override=enums.SubmissionType.LEO_FAX, )
def test_complete_lob_force_undeliverable( mock_check_unfinished, mock_get_absentee_contact_info, mock_verify_address, mock_finish, process_ballot_request, feature_flag_on, ): state = baker.make_recipe( "election.state", code=VALID_ABSENTEE_INITIAL["state"], allow_absentee_print_and_forward=True, ) baker.make_recipe("official.region", external_id=12345) mock_get_absentee_contact_info.return_value = AbsenteeContactInfo( fax="+16175551234" ) client = APIClient() response = client.post( ABSENTEE_API_ENDPOINT_INCOMPLETE_NO_REGION_MATCH, VALID_ABSENTEE_INITIAL ) assert BallotRequest.objects.count() == 1 ballot_request = BallotRequest.objects.first() assert response.json() == { "uuid": str(ballot_request.uuid), "action_id": str(ballot_request.action.pk), "esign_method": None, "ovbm_link": "mock-ovbm-link", "region": None, "regions": [], "allow_print_and_forward": True, # "deliverable": True, # "mailing_deliverable": None, "request_mailing_deliverable": None, } # bad address mock_verify_address.return_value = (False, {}) response = client.patch( ABSENTEE_API_ENDPOINT_PATCH_INCOMPLETE.format(uuid=ballot_request.uuid), { "request_mailing_address1": "123 A St NW foo", "request_mailing_city": "Washington", "request_mailing_state": "DC", "request_mailing_zipcode": "20001", "region": 12345, }, ) assert response.status_code == 400 assert "request_mailing_address1" in response.json() assert response.json()["request_mailing_deliverable_not_ignored"] # try to complete (and fail!) with undeliverable request_mailing_address response = client.patch( ABSENTEE_API_ENDPOINT_PATCH_COMPLETE.format(uuid=ballot_request.uuid), { "address1": "new_address", "region": 12345, "us_citizen": True, "is_18_or_over": True, }, ) assert response.status_code == 400 assert "request_mailing_address1" in response.json() assert response.json()["request_mailing_deliverable_not_ignored"] process_ballot_request.assert_not_called() ballot_request = BallotRequest.objects.first() assert ballot_request.status != TurnoutActionStatus.PENDING # ignore_undeliverable and complete response = client.patch( ABSENTEE_API_ENDPOINT_PATCH_COMPLETE.format(uuid=ballot_request.uuid), { "ignore_undeliverable": True, "region": 12345, "us_citizen": True, "is_18_or_over": True, }, ) assert response.status_code == 200 assert response.json() == { "uuid": str(ballot_request.uuid), "action_id": str(ballot_request.action.pk), "esign_method": "self_print", "ovbm_link": "mock-ovbm-link", "region": 12345, "allow_print_and_forward": True, # "deliverable": False, # "mailing_deliverable": None, "request_mailing_deliverable": False, } mock_finish.delay.assert_called_once_with(ballot_request.action.pk) process_ballot_request.assert_called_with(ballot_request, None, True)