From 941c6a4a9d7ab979bb0242caf910dfaad4c15c7b Mon Sep 17 00:00:00 2001 From: ydamit <29988641+ydamit@users.noreply.github.com> Date: Sat, 12 Oct 2024 17:27:54 -0400 Subject: [PATCH] Remove entity from campaign method (#1140) * introduce method for removing an entity record from a campaign * lint with black * lint with ruff --------- Co-authored-by: Shauna Gordon-McKeon --- parsons/action_builder/action_builder.py | 20 +++++++++++++++++++ .../test_action_builder.py | 14 +++++++++++++ 2 files changed, 34 insertions(+) diff --git a/parsons/action_builder/action_builder.py b/parsons/action_builder/action_builder.py index 5249213a7b..12d0f6f69f 100644 --- a/parsons/action_builder/action_builder.py +++ b/parsons/action_builder/action_builder.py @@ -246,6 +246,26 @@ def update_entity_record(self, identifier, data, campaign=None): return self._upsert_entity(data=data, campaign=campaign) + def remove_entity_record_from_campaign(self, identifier, campaign=None): + """ + Remove an entity record from a campaign. Records cannot be permanently deleted, but a + record that has been removed from a campaign will not appear in the UI. + `Args:` + identifier: str + The unique identifier for the record being removed. ID strings will need to begin + with the origin system, followed by a colon, e.g. `action_builder:abc123-...`. + campaign: str + Optional. The 36-character "interact ID" of the campaign whose data is to be + retrieved or edited. Not necessary if supplied when instantiating the class. + `Returns:` + Dict with HTTP response. + """ + + campaign = self._campaign_check(campaign) + + url = f"campaigns/{campaign}/people/{identifier}" + return self.api.delete_request(url=url) + def add_section_field_values_to_record(self, identifier, section, field_values, campaign=None): """ Add one or more tags (i.e. custom field value) to an existing entity record in Action diff --git a/test/test_action_builder/test_action_builder.py b/test/test_action_builder/test_action_builder.py index d0a71dd2e5..da2fb2a102 100644 --- a/test/test_action_builder/test_action_builder.py +++ b/test/test_action_builder/test_action_builder.py @@ -343,6 +343,20 @@ def test_update_entity_record(self, m): self.assertEqual(person_comp, update_response_comp) + @requests_mock.Mocker() + def test_remove_entity_record_from_campaign(self, m): + m.delete( + f"{self.api_url}/people/{self.fake_entity_id}", + json="{'message': 'Entity has been removed from the campaign'}", + ) + + remove_response = self.bldr.remove_entity_record_from_campaign(self.fake_entity_id) + + self.assertEqual( + remove_response, + "{'message': 'Entity has been removed from the campaign'}", + ) + def tagging_callback(self, request, context): # Internal method for returning the constructed tag data to test