Skip to content

Commit

Permalink
Merge pull request #300 from bartonip/feature/filter-by-ids
Browse files Browse the repository at this point in the history
Implement filter by ids
  • Loading branch information
freakboy3742 authored Aug 30, 2020
2 parents aaa2e7e + c10239c commit d9478ab
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,23 @@ def test_filter(self):

self.assertEqual(params, {"where": 'AmountPaid=="0.0"'})

def test_filter_ids(self):
"""The filter function should correctly handle various arguments"""
credentials = Mock(base_url="")
manager = Manager("contacts", credentials)

uri, params, method, body, headers, singleobject = manager._filter(
IDs=["1", "2", "3", "4", "5"]
)

self.assertEqual(method, "get")
self.assertFalse(singleobject)

expected_params = {
"IDs": "1,2,3,4,5"
}
self.assertEqual(params, expected_params)

def test_rawfilter(self):
"""The filter function should correctly handle various arguments"""
credentials = Mock(base_url="")
Expand Down
5 changes: 5 additions & 0 deletions xero/basemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,11 @@ def _filter(self, **kwargs):
headers = self.prepare_filtering_date(val)
del kwargs["since"]

# Accept IDs parameter for Invoices and Contacts endpoints
if "IDs" in kwargs:
params["IDs"] = ",".join(kwargs["IDs"])
del kwargs["IDs"]

def get_filter_params(key, value):
last_key = key.split("_")[-1]
if last_key.endswith("ID"):
Expand Down

0 comments on commit d9478ab

Please sign in to comment.