forked from bisguzar/twitter-scraper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
43 lines (29 loc) · 1.26 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import unittest
from twitter_scraper import get_tweets
class TestFamilyUnderscore(unittest.TestCase):
def test_father(self):
user = '_'
tweets = list(get_tweets(query=user, pages=1))
self.assertTrue(tweets[0]['text'].__contains__('Want to feel old?'))
def test_mother(self):
user = '__'
tweets = list(get_tweets(query=user, pages=1))
self.assertTrue(tweets[0]['text'].__contains__('It is a gift to be alive in the time of Beyoncé'))
def test_child(self):
user = '___'
tweets = list(get_tweets(query=user, pages=1))
self.assertEqual(tweets[1]['text'], 'If I could, I would, but if I can’t, I wan’t.')
class TestPages(unittest.TestCase):
def test_25pages(self):
"""I don't know why but in some cases it only crawls 2~5 pages"""
user = 'kennethreitz'
tweets = list(get_tweets(query=user, pages=25))
self.assertGreater(len(tweets), 486)
def test_languages(self):
user = 'fcbarcelona_jp'
tweets = list(get_tweets(query=user, pages=1))
self.assertIn('likes', tweets[0])
self.assertIsInstance(tweets[0]['replies'], int)
self.assertGreaterEqual(tweets[1]['retweets'], 0)
if __name__ == '__main__':
unittest.main()