Fix a bug in cursors and tweak tests.
authorJoshua Roesslein <jroesslein@gmail.com>
Sun, 16 Jun 2013 19:40:37 +0000 (12:40 -0700)
committerJoshua Roesslein <jroesslein@gmail.com>
Sun, 16 Jun 2013 19:40:37 +0000 (12:40 -0700)
tests/test_cursors.py
tweepy/cursor.py

index cfcb9f1765ca7d467db9c9ad65b801fbb9fa93a4..ecffd38d12696eb7f92ba052bdebec7371120816 100644 (file)
@@ -8,8 +8,6 @@ class TweepyCursorTests(unittest.TestCase):
 
     def setUp(self):
         self.api = API(create_auth())
-        self.api.retry_count = 2
-        self.api.retry_delay = 5
 
     def testidcursoritems(self):
         items = list(Cursor(self.api.user_timeline).items(25))
@@ -20,16 +18,16 @@ class TweepyCursorTests(unittest.TestCase):
         self.assertEqual(len(pages), 5)
 
     def testcursorcursoritems(self):
-        items = list(Cursor(self.api.friends_ids).items())
-        self.assert_(len(items) > 0)
+        items = list(Cursor(self.api.friends_ids).items(10))
+        self.assertEqual(len(items), 10)
 
-        items = list(Cursor(self.api.followers_ids, 'twitter').items(30))
-        self.assert_(len(items) == 30)
+        items = list(Cursor(self.api.followers_ids, 'twitter').items(10))
+        self.assertEqual(len(items), 10)
 
     def testcursorcursorpages(self):
-        pages = list(Cursor(self.api.friends_ids).pages())
-        self.assert_(len(pages) > 0)
+        pages = list(Cursor(self.api.friends_ids).pages(1))
+        self.assert_(len(pages) == 1)
 
-        pages = list(Cursor(self.api.followers_ids, 'twitter').pages(5))
-        self.assert_(len(pages) == 5)
+        pages = list(Cursor(self.api.followers_ids, 'twitter').pages(1))
+        self.assert_(len(pages) == 1)
 
index edda0ba623cab72c589b585826cf971416fcbfdd..9061bfd6c50076e2156511188c661516e28d50f2 100644 (file)
@@ -84,9 +84,13 @@ class IdIterator(BaseIterator):
         BaseIterator.__init__(self, method, args, kargs)
         self.max_id = kargs.get('max_id')
         self.since_id = kargs.get('since_id')
+        self.count = 0
 
     def next(self):
         """Fetch a set of items with IDs less than current set."""
+        if self.limit and self.limit == self.count:
+            raise StopIteration
+
         # max_id is inclusive so decrement by one
         # to avoid requesting duplicate items.
         max_id = self.since_id - 1 if self.max_id else None
@@ -95,16 +99,21 @@ class IdIterator(BaseIterator):
             raise StopIteration
         self.max_id = data.max_id
         self.since_id = data.since_id
+        self.count += 1
         return data
 
     def prev(self):
         """Fetch a set of items with IDs greater than current set."""
+        if self.limit and self.limit == self.count:
+            raise StopIteration
+
         since_id = self.max_id
         data = self.method(since_id = since_id, *self.args, **self.kargs)
         if len(data) == 0:
             raise StopIteration
         self.max_id = data.max_id
         self.since_id = data.since_id
+        self.count += 1
         return data
 
 class PageIterator(BaseIterator):