]>
jfr.im git - z_archive/twitter.git/blob - tests/test_sanity.py
3 from random
import choice
8 from twitter
import Twitter
, NoAuth
, OAuth
, read_token_file
, TwitterHTTPError
9 from twitter
.api
import TwitterDictResponse
, TwitterListResponse
10 from twitter
.cmdline
import CONSUMER_KEY
, CONSUMER_SECRET
13 oauth
= OAuth(*read_token_file('tests/oauth_creds')
14 + (CONSUMER_KEY
, CONSUMER_SECRET
))
16 twitter11
= Twitter(domain
='api.twitter.com',
19 twitter11_na
= Twitter(domain
='api.twitter.com', auth
=noauth
, api_version
='1.1')
22 AZaz
= "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"
25 return ''.join(choice(AZaz
) for _
in range(10))
28 def test_API_set_tweet():
29 random_tweet
= "A random tweet " + get_random_str()
30 twitter11
.statuses
.update(status
=random_tweet
)
32 recent
= twitter11
.statuses
.home_timeline()
34 assert isinstance(recent
.rate_limit_remaining
, int)
35 assert isinstance(recent
.rate_limit_reset
, int)
36 assert random_tweet
== recent
[0]['text']
39 def test_API_set_unicode_tweet():
40 random_tweet
= u
"A random tweet with unicode üøπ" + get_random_str()
41 twitter11
.statuses
.update(status
=random_tweet
)
43 recent
= twitter11
.statuses
.home_timeline()
45 assert random_tweet
== recent
[0]['text']
49 results
= twitter11
.search
.tweets(q
='foo')
53 def test_get_trends_3():
54 # Of course they broke it all again in 1.1...
55 assert twitter11
.trends
.place(_id
=1)
58 def test_TwitterHTTPError_raised_for_invalid_oauth():
61 twitter11_na
.statuses
.mentions_timeline()
62 except TwitterHTTPError
:
63 # this is the error we are looking for :)
68 def test_picklability():
69 res
= TwitterDictResponse({'a': 'b'}
)
71 res2
= pickle
.loads(p
)
73 assert res2
['a'] == 'b'
75 res
= TwitterListResponse([1, 2, 3])
77 res2
= pickle
.loads(p
)
82 def test_jsonifability():
83 res
= TwitterDictResponse({'a': 'b'}
)
87 assert res2
['a'] == 'b'
89 res
= TwitterListResponse([1, 2, 3])