Esempio n. 1
0
    def test_max_tweets_zero(self):
        api = twitter.TwitterAPI(self.credentials)
        corpus = api.search_content('hello', max_tweets=0)
        self.assertEqual(len(corpus), 20)   # 20 is the #tweets in cache

        corpus = api.search_authors('hello', max_tweets=0)
        self.assertEqual(len(corpus), 20)  # 20 is the #tweets in cache
Esempio n. 2
0
 def test_error_reporting(self):
     with unittest.mock.patch('tweepy.Cursor.items') as mock:
         mock.side_effect = tweepy.TweepError('', Response(500))
         error_callback = unittest.mock.Mock()
         api = twitter.TwitterAPI(self.credentials, on_error=error_callback)
         api.search_authors('hello', max_tweets=5)
         self.assertEqual(error_callback.call_count, 1)
Esempio n. 3
0
 def test_search_author_collecting(self):
     api = twitter.TwitterAPI(self.credentials)
     with unittest.mock.patch('tweepy.Cursor', MyCursor) as mock:
         corpus = api.search_authors('hello', max_tweets=5)
         self.assertEqual(len(corpus), 5)
     # MyCursor2 so we get different tweets
     with unittest.mock.patch('tweepy.Cursor', MyCursor2) as mock:
         corpus = api.search_authors('world', max_tweets=5, collecting=True)
         self.assertEqual(len(corpus), 10)
Esempio n. 4
0
    def test_search_callbacks(self):
        self.checker = 0

        def on_progress(total, current):
            self.assertTrue(total % 20 == 0)
            self.checker += 1

        api = twitter.TwitterAPI(self.credentials, on_progress=on_progress)
        api.search_content('hello', max_tweets=20, lang='en')
        self.assertEqual(self.checker, 1)
Esempio n. 5
0
 def update_api(self, key):
     if key:
         self.Error.key_missing.clear()
         self.api = twitter.TwitterAPI(
             key,
             on_error=self.Error.api,
             on_rate_limit=self.Error.rate_limit,
             should_break=self.search.should_break,
             on_progress=self.update_tweets_num)
     else:
         self.api = None
Esempio n. 6
0
    def test_search_callbacks(self):
        self.checker = 0

        def on_progress(_):
            self.checker += 1

        api = twitter.TwitterAPI(self.credentials)
        api.search_content(
            "hello", max_tweets=20, lang="en", callback=on_progress
        )
        self.assertEqual(self.checker, 1)
Esempio n. 7
0
    def test_breaking(self):
        count = 0

        def should_break():
            nonlocal count
            if count == 1:
                return True
            count += 1
            return False

        api = twitter.TwitterAPI(self.credentials, should_break=should_break)
        corpus = api.search_content('hello', max_tweets=10)
        self.assertEqual(len(corpus), 1)
Esempio n. 8
0
 def update_api(self, key):
     if key:
         self.Error.key_missing.clear()
         self.api = twitter.TwitterAPI(key)
     else:
         self.api = None
Esempio n. 9
0
 def setUp(self):
     self.credentials = get_credentials()
     self.api = twitter.TwitterAPI(self.credentials)
Esempio n. 10
0
 def test_search_author(self):
     api = twitter.TwitterAPI(self.credentials)
     corpus = api.search_authors('hello', max_tweets=5)
     self.assertEqual(len(corpus), 5)
Esempio n. 11
0
 def test_empty_content(self):
     api = twitter.TwitterAPI(self.credentials)
     corpus = api.search_content('', max_tweets=10, allow_retweets=False)
     self.assertEqual(len(corpus), 10)
Esempio n. 12
0
 def test_report(self):
     api = twitter.TwitterAPI(self.credentials)
     api.search_content('hello', max_tweets=5, collecting=True)
     self.assertEqual(len(api.report()), 1)
     api.search_content('world', collecting=True)
     self.assertEqual(len(api.report()), 2)
Esempio n. 13
0
 def setUp(self):
     self.client = twitter.TwitterAPI("key")
Esempio n. 14
0
 def test_rate_limit_reporting(self):
     with unittest.mock.patch("tweepy.Cursor.items") as mock:
         mock.side_effect = tweepy.TweepError("", Response(429))
         api = twitter.TwitterAPI(self.credentials)
         with self.assertRaises(TweepError):
             api.search_authors("hello", max_tweets=5)