Skip to content

Commit

Permalink
Add support for deleting person from NGPVAN (#834)
Browse files Browse the repository at this point in the history
* Add support for deleting person from NGPVAN

* Add deletion response for testing

* Add test for deleting person entry

* Remove extra blank line

* Remove extra blank line

* Run Black formatter

---------

Co-authored-by: Shauna <[email protected]>
  • Loading branch information
sjwmoveon and shaunagm authored Jun 20, 2023
1 parent e7f1e94 commit b8f41b5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
15 changes: 15 additions & 0 deletions parsons/ngpvan/people.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,21 @@ def get_person(
logger.info(f'Getting person with {id_type or "vanid"} of {id} at url {url}')
return self.connection.get_request(url, params={"$expand": expand_fields})

def delete_person(self, vanid):
"""
Suppress the given VANID in databases where contact records can be suppressed.
`Args:`
vanid: str
The person's VAN ID.
`Returns:`
Success or error.
"""
url = f"people/{vanid}"
r = self.connection.delete_request(url)
logger.info(f"Van ID {vanid} suppressed.")
return r

def apply_canvass_result(
self,
id,
Expand Down
2 changes: 2 additions & 0 deletions test/test_van/responses_people.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,5 @@
}

merge_contacts_response = {"vanId": 56789}

delete_person_response = {}
26 changes: 9 additions & 17 deletions test/test_van/test_people.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@
find_people_response,
get_person_response,
merge_contacts_response,
delete_person_response,
)

os.environ["VAN_API_KEY"] = "SOME_KEY"


class TestNGPVAN(unittest.TestCase):
def setUp(self):

self.van = VAN(os.environ["VAN_API_KEY"], db="MyVoters", raise_for_status=False)

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

m.post(
self.van.connection.uri + "people/find",
json=find_people_response,
Expand All @@ -34,7 +33,6 @@ def test_find_person(self, m):

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

json = {
"firstName": "Bob",
"lastName": "Smith",
Expand All @@ -52,28 +50,22 @@ def test_find_person_json(self, m):
self.assertEqual(person, find_people_response)

def test_upsert_person(self):

pass

def test_upsert_person_json(self):

pass

def test_update_person(self):

pass

def test_update_person_json(self):

pass

def test_people_search(self):

# Already tested as part of upsert and find person methods
pass

def test_valid_search(self):

# Fails with FN / LN Only
self.assertRaises(
ValueError,
Expand Down Expand Up @@ -128,7 +120,6 @@ def test_valid_search(self):

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

json = get_person_response

# Test works with external ID
Expand All @@ -142,8 +133,15 @@ def test_get_person(self, m):
self.assertEqual(get_person_response, person)

@requests_mock.Mocker()
def test_apply_canvass_result(self, m):
def test_delete_person(self, m):
json = delete_person_response
# Test works with vanid
m.delete(self.van.connection.uri + "people/19722445", json=json)
response = self.van.delete_person("19722445")
self.assertEqual(delete_person_response, response)

@requests_mock.Mocker()
def test_apply_canvass_result(self, m):
# Test a valid attempt
m.post(
self.van.connection.uri + "people/2335282/canvassResponses", status_code=204
Expand Down Expand Up @@ -206,7 +204,6 @@ def test_apply_canvass_result(self, m):

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

# Test valid survey question
m.post(
self.van.connection.uri + "people/2335282/canvassResponses", status_code=204
Expand Down Expand Up @@ -244,16 +241,13 @@ def test_apply_survey_question(self, m):
self.assertRaises(HTTPError, self.van.apply_survey_response, 2335282, 351006, 0)

def test_toggle_volunteer_action(self):

pass

def test_apply_response(self):

pass

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

relationship_id = 12
bad_vanid_1 = 99999
good_vanid_1 = 12345
Expand Down Expand Up @@ -291,7 +285,6 @@ def test_create_relationship(self, m):

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

vanid = 999
code_id = 888

Expand All @@ -305,7 +298,6 @@ def test_apply_person_code(self, m):

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

source_vanid = 12345

m.put(
Expand Down

0 comments on commit b8f41b5

Please sign in to comment.