test_cursors.py 1.69 KB
Newer Older
Mark Smith's avatar
Mark Smith committed
1
from tweepy import Cursor
2

3
from .config import TweepyTestCase, username, tape
4 5


Mark Smith's avatar
Mark Smith committed
6 7
class TweepyCursorTests(TweepyTestCase):
    @tape.use_cassette('testidcursoritems.json')
8 9 10 11
    def testidcursoritems(self):
        items = list(Cursor(self.api.user_timeline).items(25))
        self.assertEqual(len(items), 25)

Mark Smith's avatar
Mark Smith committed
12
    @tape.use_cassette('testidcursorpages.json')
13 14 15 16
    def testidcursorpages(self):
        pages = list(Cursor(self.api.user_timeline).pages(5))
        self.assertEqual(len(pages), 5)

Mark Smith's avatar
Mark Smith committed
17
    @tape.use_cassette('testcursorcursoritems.json')
18
    def testcursorcursoritems(self):
19 20
        items = list(Cursor(self.api.friends_ids).items(10))
        self.assertEqual(len(items), 10)
21

22 23
        items = list(Cursor(self.api.followers_ids, username).items(1))
        self.assertEqual(len(items), 1)
24

Mark Smith's avatar
Mark Smith committed
25
    @tape.use_cassette('testcursorcursorpages.json')
26
    def testcursorcursorpages(self):
27 28
        pages = list(Cursor(self.api.friends_ids).pages(1))
        self.assert_(len(pages) == 1)
29

Mark Smith's avatar
Mark Smith committed
30
        pages = list(Cursor(self.api.followers_ids, username).pages(1))
31
        self.assert_(len(pages) == 1)
32

Mark Smith's avatar
Mark Smith committed
33
    @tape.use_cassette('testcursorsetstartcursor.json')
34 35 36 37 38
    def testcursorsetstartcursor(self):
        c = Cursor(self.api.friends_ids, cursor=123456)
        self.assertEqual(c.iterator.next_cursor, 123456)
        self.assertFalse('cursor' in c.iterator.kargs)

Yuri Prezument's avatar
Yuri Prezument committed
39 40 41 42 43 44 45 46 47 48
    @tape.use_cassette('testcursornext.json')
    def testcursornext(self):
        """
        Test cursor.next() behavior, id being passed correctly.
        Regression test for issue #518
        """
        cursor = Cursor(self.api.user_timeline, id='twitter').items(5)
        status = cursor.next()

        self.assertEquals(status.user.screen_name, 'twitter')