Skip to content

Commit

Permalink
adding unique id lists support in ActionNetwork module (move-coop#1101)
Browse files Browse the repository at this point in the history
* adding unique id lists support in ActionNetwork module

* restoring googlesheets.py and google_cloud_storage.py

* adding newline end of files cause failing test
  • Loading branch information
NirTatcher authored Jul 16, 2024
1 parent 83a9c3f commit 686f722
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
30 changes: 30 additions & 0 deletions parsons/action_network/action_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -1909,3 +1909,33 @@ def get_wrapper(self, wrapper_id):
https://actionnetwork.org/docs/v2/wrappers
"""
return self.api.get_request(f"wrappers/{wrapper_id}")

# Unique ID Lists
def get_unique_id_lists(self, limit=None, per_page=25, page=None, filter=None):
"""
Args:
limit: The maximum number of unique ID lists to return.
When None, returns all unique ID lists.
per_page: The number of unique ID lists to return per page. Default is 25.
page: The specific page of unique ID lists to return.
filter: The filter criteria to apply when retrieving unique ID lists.
Returns:
A JSON response with the unique ID lists.
Documentation Reference:
https://actionnetwork.org/docs/v2/unique_id_lists
"""
if page:
return self._get_page("unique_id_lists", page, per_page, filter)
return self._get_entry_list("unique_id_lists", limit, per_page, filter)

def get_unique_id_list(self, unique_id_list_id):
"""
`Args:`
unique_id_list_id:
The unique id of the unique ID list
`Returns:`
A JSON response with the unique ID list details
`Documentation Reference`:
https://actionnetwork.org/docs/v2/unique_id_lists
"""
return self.api.get_request(f"unique_id_lists/{unique_id_list_id}")
75 changes: 75 additions & 0 deletions test/test_action_network/test_action_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -3263,6 +3263,53 @@ def setUp(self, m):
},
}

self.fake_unique_id_lists = {
"total_pages": 3,
"per_page": 25,
"page": 1,
"total_records": 50,
"_links": {
"next": {"href": f"{self.api_url}/unique_id_lists?page=2"},
"self": {"href": f"{self.api_url}/unique_id_lists"},
"osdi:unique_id_lists": [
{"href": f"{self.api_url}/unique_id_lists/fake_id"},
{"href": f"{self.api_url}/unique_id_lists/fake_id"},
],
"curies": [
{
"name": "osdi",
"href": "https://actionnetwork.org/docs/v2/{rel}",
"templated": True,
},
{
"name": "action_network",
"href": "https://actionnetwork.org/docs/v2/{rel}",
"templated": True,
},
],
},
"_embedded": {
"osdi:unique_id_lists": [
{
"identifiers": ["action_network:fake_id"],
"name": "Example Unique ID List",
"created_date": "2022-01-01T00:00:00Z",
"modified_date": "2022-01-01T00:00:00Z",
"description": "This is an example unique ID list.",
"administrative_url": "https://actionnetwork.org/unique_id_lists/1/edit",
},
{
"identifiers": ["action_network:fake_id"],
"name": "Another Unique ID List",
"created_date": "2022-01-02T00:00:00Z",
"modified_date": "2022-01-02T00:00:00Z",
"description": "This is another example unique ID list.",
"administrative_url": "https://actionnetwork.org/unique_id_lists/2/edit",
},
],
},
}

@requests_mock.Mocker()
def test_get_page(self, m):
m.get(
Expand Down Expand Up @@ -4245,3 +4292,31 @@ def test_get_wrapper(self, m):
self.an.get_wrapper("123"),
self.fake_wrapper,
)

# Unique ID Lists

@requests_mock.Mocker()
def test_get_unique_id_lists(self, m):
m.get(
f"{self.api_url}/unique_id_lists",
text=json.dumps(self.fake_unique_id_lists),
)
assert_matching_tables(
self.an.get_unique_id_lists(1),
self.fake_unique_id_lists["_embedded"][list(self.fake_unique_id_lists["_embedded"])[0]],
)

@requests_mock.Mocker()
def test_get_unique_id_list(self, m):
m.get(
f"{self.api_url}/unique_id_lists/123",
text=json.dumps(
self.fake_unique_id_lists["_embedded"][
list(self.fake_unique_id_lists["_embedded"])[0]
]
),
)
assert_matching_tables(
self.an.get_unique_id_list("123"),
self.fake_unique_id_lists["_embedded"][list(self.fake_unique_id_lists["_embedded"])[0]],
)

0 comments on commit 686f722

Please sign in to comment.