diff --git a/parsons/ngpvan/people.py b/parsons/ngpvan/people.py index 3b22cbe7d7..c3a5dfe9d1 100644 --- a/parsons/ngpvan/people.py +++ b/parsons/ngpvan/people.py @@ -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, diff --git a/test/test_van/responses_people.py b/test/test_van/responses_people.py index 5048b13700..db6299fda7 100644 --- a/test/test_van/responses_people.py +++ b/test/test_van/responses_people.py @@ -152,3 +152,5 @@ } merge_contacts_response = {"vanId": 56789} + +delete_person_response = {} diff --git a/test/test_van/test_people.py b/test/test_van/test_people.py index f104cf610e..eebcf77205 100644 --- a/test/test_van/test_people.py +++ b/test/test_van/test_people.py @@ -7,6 +7,7 @@ find_people_response, get_person_response, merge_contacts_response, + delete_person_response, ) os.environ["VAN_API_KEY"] = "SOME_KEY" @@ -14,12 +15,10 @@ 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, @@ -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", @@ -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, @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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(