]> jfr.im git - z_archive/twitter.git/blame - tests/test_sanity.py
Make the code python 2 and 3 compatible.
[z_archive/twitter.git] / tests / test_sanity.py
CommitLineData
e541e268
MV
1
2from random import choice
3
4from twitter import Twitter, NoAuth, OAuth, read_token_file
5from twitter.cmdline import CONSUMER_KEY, CONSUMER_SECRET
6
7noauth = NoAuth()
8oauth = OAuth(*read_token_file('tests/oauth_creds')
9 + (CONSUMER_KEY, CONSUMER_SECRET))
10
11twitter = Twitter(domain='api.twitter.com',
12 auth=oauth,
13 api_version='1')
14twitter_na = Twitter(domain='api.twitter.com', auth=noauth, api_version='1')
15
16
17AZaz = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"
18
19def get_random_str():
20 return ''.join(choice(AZaz) for _ in range(10))
21
22
23def test_API_get_some_public_tweets():
24 updates = twitter_na.statuses.public_timeline()
25 assert updates
26 assert updates[0]['created_at']
27
28
29def 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
38def 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')