]>
jfr.im git - z_archive/twitter.git/blob - tests/test_sanity.py
3 from random
import choice
6 from twitter
import Twitter
, NoAuth
, OAuth
, read_token_file
, TwitterHTTPError
7 from twitter
.cmdline
import CONSUMER_KEY
, CONSUMER_SECRET
10 oauth
= OAuth(*read_token_file('tests/oauth_creds')
11 + (CONSUMER_KEY
, CONSUMER_SECRET
))
13 twitter11
= Twitter(domain
='api.twitter.com',
16 twitter11_na
= Twitter(domain
='api.twitter.com', auth
=noauth
, api_version
='1.1')
19 AZaz
= "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"
22 return ''.join(choice(AZaz
) for _
in range(10))
25 def test_API_set_tweet():
26 random_tweet
= "A random tweet " + get_random_str()
27 twitter11
.statuses
.update(status
=random_tweet
)
29 recent
= twitter11
.statuses
.home_timeline()
31 assert isinstance(recent
.rate_limit_remaining
, int)
32 assert isinstance(recent
.rate_limit_reset
, int)
33 assert random_tweet
== recent
[0]['text']
36 def test_API_set_unicode_tweet():
37 random_tweet
= u
"A random tweet with unicode üøπ" + get_random_str()
38 twitter11
.statuses
.update(status
=random_tweet
)
40 recent
= twitter11
.statuses
.home_timeline()
42 assert random_tweet
== recent
[0]['text']
46 results
= twitter11
.search
.tweets(q
='foo')
50 def test_get_trends_3():
51 # Of course they broke it all again in 1.1...
52 assert twitter11
.trends
.place(_id
=1)
54 def test_TwitterHTTPError_raised_for_invalid_oauth():
57 twitter11_na
.statuses
.mentions_timeline()
58 except TwitterHTTPError
:
59 # this is the error we are looking for :)