Skip to content

Commit

Permalink
Remove entity from campaign method (move-coop#1140)
Browse files Browse the repository at this point in the history
* introduce method for removing an entity record from a campaign

* lint with black

* lint with ruff

---------

Co-authored-by: Shauna Gordon-McKeon <shaunagm@gmail.com>
  • Loading branch information
ydamit and shaunagm authored Oct 12, 2024
1 parent c4c9a75 commit 941c6a4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
20 changes: 20 additions & 0 deletions parsons/action_builder/action_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions test/test_action_builder/test_action_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 941c6a4

Please sign in to comment.