]> jfr.im git - z_archive/twitter.git/blob - tests/test_sanity.py
- Check rate limit using the command line tool. Patch by @stalkr_
[z_archive/twitter.git] / tests / test_sanity.py
1
2 from random import choice
3
4 from twitter import Twitter, NoAuth, OAuth, read_token_file
5 from twitter.cmdline import CONSUMER_KEY, CONSUMER_SECRET
6
7 noauth = NoAuth()
8 oauth = OAuth(*read_token_file('tests/oauth_creds')
9 + (CONSUMER_KEY, CONSUMER_SECRET))
10
11 twitter = Twitter(domain='api.twitter.com',
12 auth=oauth,
13 api_version='1')
14 twitter_na = Twitter(domain='api.twitter.com', auth=noauth, api_version='1')
15
16
17 AZaz = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"
18
19 def get_random_str():
20 return ''.join(choice(AZaz) for _ in range(10))
21
22
23 def test_API_get_some_public_tweets():
24 updates = twitter_na.statuses.public_timeline()
25 assert updates
26 assert updates[0]['created_at']
27
28
29 def test_API_set_tweet():
30 random_tweet = "A random tweet " + get_random_str()
31 twitter.statuses.update(status=random_tweet)
32
33 recent = twitter.statuses.user_timeline()
34 assert recent
35 assert random_tweet == recent[0]['text']
36
37
38 def test_API_friendship_exists():
39 assert True == twitter.friendships.exists(
40 user_a='ptttest0001', user_b='sixohsix')
41 assert False == twitter.friendships.exists(
42 user_a='gruber', user_b='ptttest0001')
43
44
45 def test_search():
46 t_search = Twitter(domain='search.twitter.com')
47 results = t_search.search(q='foo')
48 assert results