]> jfr.im git - z_archive/twitter.git/blame - tests/test_sanity.py
Fix test_search()
[z_archive/twitter.git] / tests / test_sanity.py
CommitLineData
066c34e0 1# encoding: utf8
e541e268
MV
2
3from random import choice
c77b5e4b 4import time
e541e268
MV
5
6from twitter import Twitter, NoAuth, OAuth, read_token_file
7from twitter.cmdline import CONSUMER_KEY, CONSUMER_SECRET
8
9noauth = NoAuth()
10oauth = OAuth(*read_token_file('tests/oauth_creds')
2cf5509c 11 + (CONSUMER_KEY, CONSUMER_SECRET))
12
13twitter1 = Twitter(domain='api.twitter.com',
14 auth=oauth,
15 api_version='1')
e541e268 16
920528cd
MV
17twitter11 = Twitter(domain='api.twitter.com',
18 auth=oauth,
19 api_version='1.1')
e541e268 20
2cf5509c 21twitter_na = Twitter(domain='api.twitter.com', auth=noauth, api_version='1.1')
e541e268
MV
22
23AZaz = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"
24
2cf5509c 25
e541e268
MV
26def get_random_str():
27 return ''.join(choice(AZaz) for _ in range(10))
28
29
2cf5509c 30def test_v1_not_supported():
31 # Arrange
32 random_tweet = "Random tweet that shouldn't be posted " + get_random_str()
33
34 # Act
35 try:
36 twitter1.statuses.update(status=random_tweet)
37 time.sleep(2)
38 error = False
39 except:
40 error = True
41
42 # Assert
43 assert error
44
45
e541e268
MV
46def test_API_set_tweet():
47 random_tweet = "A random tweet " + get_random_str()
2cf5509c 48 twitter11.statuses.update(status=random_tweet)
c77b5e4b 49 time.sleep(2)
2cf5509c 50 recent = twitter11.statuses.user_timeline()
e541e268 51 assert recent
c77b5e4b
SK
52 assert isinstance(recent.rate_limit_remaining, int)
53 assert isinstance(recent.rate_limit_reset, int)
e541e268
MV
54 assert random_tweet == recent[0]['text']
55
56
066c34e0 57def test_API_set_unicode_tweet():
920528cd 58 random_tweet = u"A random tweet with unicode üøπ" + get_random_str()
2cf5509c 59 twitter11.statuses.update(status=random_tweet)
066c34e0 60
2cf5509c 61 recent = twitter11.statuses.user_timeline()
066c34e0 62 assert recent
63 assert random_tweet == recent[0]['text']
64
65
652c5402 66def test_search():
fcf08b18 67 # In 1.1, search works on api.twitter.com not search.twitter.com
68 # and requires authorisation
ed074882 69 results = twitter11.search.tweets(q='foo')
652c5402 70 assert results
e748eed8 71
72
73def test_get_trends():
74 # This is one method of inserting parameters, using named
75 # underscore params.
2cf5509c 76 world_trends = twitter11.trends._woeid(_woeid=1)
e748eed8 77 assert world_trends
78
79
80def test_get_trends_2():
81 # This is a nicer variation of the same call as above.
2cf5509c 82 world_trends = twitter11.trends._(1)
e748eed8 83 assert world_trends
920528cd
MV
84
85
86def test_get_trends_3():
87 # Of course they broke it all again in 1.1...
88 assert twitter11.trends.place(_id=1)
89
2cf5509c 90# End of file