8000 Ensure the `Calls.iter` method filters like the `Calls.list` method. by goodtune · Pull Request #193 · twilio/twilio-python · GitHub
[go: up one dir, main page]

Skip to content

Ensure the Calls.iter method filters like the Calls.list method. #193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 20, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff vi 10000 ew
Diff view
12 changes: 12 additions & 0 deletions tests/test_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ def test_paging(mock):
mock.assert_called_with("GET", uri, params=exp_params, auth=AUTH)


@patch("twilio.rest.resources.base.make_twilio_request")
def test_paging_iter(mock):
resp = create_mock_json("tests/resources/calls_list.json")
mock.return_value = resp

uri = "%s/Calls" % (BASE_URI)
next(list_resource.iter(started_before=date(2010, 12, 5)))
exp_params = {'StartTime<': '2010-12-05'}

mock.assert_called_with("GET", uri, params=exp_params, auth=AUTH)


@patch("twilio.rest.resources.base.make_twilio_request")
def test_get(mock):
resp = create_mock_json("tests/resources/calls_instance.json")
Expand Down
19 changes: 19 additions & 0 deletions twilio/rest/resources/calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,25 @@ def list(self, from_=None, ended_after=None,
kwargs["EndTime"] = parse_date(ended)
return self.get_instances(kwargs)

@normalize_dates
def iter(self, from_=None, ended_after=None,
ended_before=None, ended=None, started_before=None,
started_after=None, started=None, **kwargs):
"""
Returns an iterator of :class:`Call` resources.

:param date after: Only list calls started after this datetime
:param date before: Only list calls started before this datetime
"""
kwargs["from"] = from_
kwargs["StartTime<"] = started_before
kwargs["StartTime>"] = started_after
kwargs["StartTime"] = parse_date(started)
kwargs["EndTime<"] = ended_before
kwargs["EndTime>"] = ended_after
kwargs["EndTime"] = parse_date(ended)
return super(Calls, self).iter(**kwargs)

def create(self, to, from_, url, status_method=None, **kwargs):
"""
Make a phone call to a number.
Expand Down
0