]>
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',
20 twitter11_na
= Twitter(domain
='api.twitter.com',
24 AZaz
= "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"
28 return ''.join(choice(AZaz
) for _
in range(10))
31 def test_API_set_tweet():
32 random_tweet
= "A random tweet " + get_random_str()
33 twitter11
.statuses
.update(status
=random_tweet
)
35 recent
= twitter11
.statuses
.home_timeline()
37 assert isinstance(recent
.rate_limit_remaining
, int)
38 assert isinstance(recent
.rate_limit_reset
, int)
39 assert random_tweet
== recent
[0]['text']
42 def test_API_set_unicode_tweet():
43 random_tweet
= u
"A random tweet with unicode üøπ" + get_random_str()
44 twitter11
.statuses
.update(status
=random_tweet
)
46 recent
= twitter11
.statuses
.home_timeline()
48 assert random_tweet
== recent
[0]['text']
52 # In 1.1, search works on api.twitter.com not search.twitter.com
53 # and requires authorisation
54 results
= twitter11
.search
.tweets(q
='foo')
58 def test_get_trends():
59 # This is one method of inserting parameters, using named
61 world_trends
= twitter11
.trends
.available(_woeid
=1)
65 def test_get_trends_2():
66 # This is a nicer variation of the same call as above.
67 world_trends
= twitter11
.trends
._(1)
71 def test_get_trends_3():
72 # Of course they broke it all again in 1.1...
73 assert twitter11
.trends
.place(_id
=1)
76 def test_TwitterHTTPError_raised_for_invalid_oauth():
79 twitter11_na
.statuses
.mentions_timeline()
80 except TwitterHTTPError
:
81 # this is the error we are looking for :)
86 def test_picklability():
87 res
= TwitterDictResponse({'a': 'b'}
)
89 res2
= pickle
.loads(p
)
91 assert res2
['a'] == 'b'
93 res
= TwitterListResponse([1, 2, 3])
95 res2
= pickle
.loads(p
)
100 def test_jsonifability():
101 res
= TwitterDictResponse({'a': 'b'}
)
105 assert res2
['a'] == 'b'
107 res
= TwitterListResponse([1, 2, 3])