-
Notifications
You must be signed in to change notification settings - Fork 715
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: drop the page limit calculation and correct the page limit stop …
…condition (#523) Dropping the page limit calculation since it's no longer used and doesn't make sense to be calculated on a record limit. Also correct the page limit stop logic (with added tests) where an extra page was being queried.
- Loading branch information
childish-sambino
authored
Jun 3, 2020
1 parent
3907610
commit 39b8e2f
Showing
2 changed files
with
72 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
from tests import IntegrationTestCase | ||
from tests.holodeck import Request | ||
from twilio.base.page import Page | ||
from twilio.http.response import Response | ||
|
||
|
||
class TestPage(Page): | ||
def __init__(self, version, response, *_args, **_kwargs): | ||
super(TestPage, self).__init__(version, response) | ||
|
||
def get_instance(self, payload): | ||
return payload | ||
|
||
|
||
class VersionTestCase(IntegrationTestCase): | ||
def setUp(self): | ||
super(VersionTestCase, self).setUp() | ||
|
||
self.holodeck.mock(Response( | ||
200, | ||
''' | ||
{ | ||
"next_page_uri": "/2010-04-01/Accounts/AC123/Messages.json?Page=1", | ||
"messages": [{"body": "payload0"}, {"body": "payload1"}] | ||
} | ||
''' | ||
), Request(url='https://api.twilio.com/2010-04-01/Accounts/AC123/Messages.json')) | ||
|
||
self.holodeck.mock(Response( | ||
200, | ||
''' | ||
{ | ||
"next_page_uri": "/2010-04-01/Accounts/AC123/Messages.json?Page=2", | ||
"messages": [{"body": "payload2"}, {"body": "payload3"}] | ||
} | ||
''' | ||
), Request(url='https://api.twilio.com/2010-04-01/Accounts/AC123/Messages.json?Page=1')) | ||
|
||
self.holodeck.mock(Response( | ||
200, | ||
''' | ||
{ | ||
"next_page_uri": null, | ||
"messages": [{"body": "payload4"}] | ||
} | ||
''' | ||
), Request(url='https://api.twilio.com/2010-04-01/Accounts/AC123/Messages.json?Page=2')) | ||
|
||
self.version = self.client.api.v2010 | ||
self.response = self.version.page(method='GET', uri='/Accounts/AC123/Messages.json') | ||
self.page = TestPage(self.version, self.response) | ||
|
||
def test_stream(self): | ||
messages = list(self.version.stream(self.page)) | ||
|
||
self.assertEqual(len(messages), 5) | ||
|
||
def test_stream_limit(self): | ||
messages = list(self.version.stream(self.page, limit=3)) | ||
|
||
self.assertEqual(len(messages), 3) | ||
|
||
def test_stream_page_limit(self): | ||
messages = list(self.version.stream(self.page, page_limit=1)) | ||
|
||
self.assertEqual(len(messages), 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters