forked from bisguzar/twitter-scraper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
58 lines (41 loc) · 1.55 KB
/
test.py
File metadata and controls
58 lines (41 loc) · 1.55 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import unittest
from twitter_scraper import get_tweets, get_trends
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'], '“Review mirror”')
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)
class TestTrends(unittest.TestCase):
def test_returned(self):
self.assertIsInstance(
get_trends(),
list
)
def test_returned_string(self):
for trend in get_trends():
self.assertIsInstance(
trend,
str
)
if __name__ == '__main__':
unittest.main()