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