Skip to content

Commit

Permalink
add phone to ngpvan apply canvass result (move-coop#705)
Browse files Browse the repository at this point in the history
* first draft

* fixed error message

* switched from `input_type_id` to `contact_type_id`

* added tests

* linting
  • Loading branch information
bzupnick authored Jul 7, 2022
1 parent 683d4b0 commit a27b2e0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
19 changes: 16 additions & 3 deletions parsons/ngpvan/people.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def get_person(self, id, id_type='vanid', expand_fields=[
return self.connection.get_request(url, params={'$expand': expand_fields})

def apply_canvass_result(self, id, result_code_id, id_type='vanid', contact_type_id=None,
input_type_id=None, date_canvassed=None):
input_type_id=None, date_canvassed=None, phone=None):
"""
Apply a canvass result to a person. Use this end point for attempts that do not
result in a survey response or an activist code (e.g. Not Home).
Expand All @@ -392,14 +392,16 @@ def apply_canvass_result(self, id, result_code_id, id_type='vanid', contact_type
`Optional`; Defaults to 11 (API Input)
date_canvassed : str
`Optional`; ISO 8601 formatted date. Defaults to todays date
phone: str
`Optional`; Phone number of any type (Work, Cell, Home)
`Returns:`
``None``
"""

logger.info(f'Applying result code {result_code_id} to {id_type} {id}.')
self.apply_response(id, None, id_type=id_type, contact_type_id=contact_type_id,
input_type_id=input_type_id, date_canvassed=date_canvassed,
result_code_id=result_code_id)
result_code_id=result_code_id, phone=phone)

def toggle_volunteer_action(self, id, volunteer_activity_id, action, id_type='vanid',
result_code_id=None, contact_type_id=None, input_type_id=None,
Expand Down Expand Up @@ -444,7 +446,7 @@ def toggle_volunteer_action(self, id, volunteer_activity_id, action, id_type='va

def apply_response(self, id, response, id_type='vanid', contact_type_id=None,
input_type_id=None, date_canvassed=None, result_code_id=None,
omit_contact=False):
omit_contact=False, phone=None):
"""
Apply responses such as survey questions, activist codes, and volunteer actions
to a person record. This method allows you apply multiple responses (e.g. two survey
Expand Down Expand Up @@ -477,6 +479,8 @@ def apply_response(self, id, response, id_type='vanid', contact_type_id=None,
Omit adding contact history to the response. This is particularly
useful when adding activist codes that are not based on contact
attempts.
phone: str
`Optional`; Phone number of any type (Work, Cell, Home)
`Returns:`
``True`` if successful
Expand Down Expand Up @@ -505,6 +509,15 @@ def apply_response(self, id, response, id_type='vanid', contact_type_id=None,
"omitActivistCodeContactHistory": omit_contact},
"resultCodeId": result_code_id}

if contact_type_id == 1 or contact_type_id == 37:
if phone:
json['canvassContext']['phone'] = {
"dialingPrefix": "1",
"phoneNumber": phone
}
else:
raise Exception('A phone number must be provided if canvassed via phone or SMS')

if response:
json['responses'] = response

Expand Down
7 changes: 7 additions & 0 deletions test/test_van/test_people.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ def test_apply_canvass_result(self, m):
m.post(self.van.connection.uri + 'people/DWID:2335282/canvassResponses', status_code=204)
self.van.apply_canvass_result(2335282, 18, id_type='DWID')

# test canvassing via phone or sms without providing phone number
self.assertRaises(Exception, self.van.apply_canvass_result, 2335282, 18, contact_type_id=37)

# test canvassing via phone or sms with providing phone number
m.post(self.van.connection.uri + 'people/2335282/canvassResponses', status_code=204)
self.van.apply_canvass_result(2335282, 18, contact_type_id=37, phone='(516)-555-2342')

@requests_mock.Mocker()
def test_apply_survey_question(self, m):

Expand Down

0 comments on commit a27b2e0

Please sign in to comment.