]> jfr.im git - z_archive/twitter.git/blame - tests/test_sanity.py
Remove all keep-alive delimiters to allow the hangup patch to function.
[z_archive/twitter.git] / tests / test_sanity.py
CommitLineData
066c34e0 1# encoding: utf8
e541e268
MV
2
3from random import choice
c77b5e4b 4import time
e541e268 5
32a4811d 6from twitter import Twitter, NoAuth, OAuth, read_token_file, TwitterHTTPError
e541e268
MV
7from twitter.cmdline import CONSUMER_KEY, CONSUMER_SECRET
8
9noauth = NoAuth()
10oauth = OAuth(*read_token_file('tests/oauth_creds')
11 + (CONSUMER_KEY, CONSUMER_SECRET))
12
920528cd
MV
13twitter11 = Twitter(domain='api.twitter.com',
14 auth=oauth,
15 api_version='1.1')
32a4811d 16twitter11_na = Twitter(domain='api.twitter.com', auth=noauth, api_version='1.1')
e541e268
MV
17
18
19AZaz = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"
20
21def get_random_str():
22 return ''.join(choice(AZaz) for _ in range(10))
23
24
e541e268
MV
25def test_API_set_tweet():
26 random_tweet = "A random tweet " + get_random_str()
4a803760 27 twitter11.statuses.update(status=random_tweet)
c77b5e4b 28 time.sleep(2)
4a803760 29 recent = twitter11.statuses.home_timeline()
e541e268 30 assert recent
c77b5e4b
SK
31 assert isinstance(recent.rate_limit_remaining, int)
32 assert isinstance(recent.rate_limit_reset, int)
e541e268
MV
33 assert random_tweet == recent[0]['text']
34
35
066c34e0 36def test_API_set_unicode_tweet():
920528cd 37 random_tweet = u"A random tweet with unicode üøπ" + get_random_str()
4a803760 38 twitter11.statuses.update(status=random_tweet)
066c34e0 39
4a803760 40 recent = twitter11.statuses.home_timeline()
066c34e0 41 assert recent
42 assert random_tweet == recent[0]['text']
43
44
652c5402 45def test_search():
697d6b54 46 results = twitter11.search.tweets(q='foo')
652c5402 47 assert results
e748eed8 48
49
920528cd
MV
50def test_get_trends_3():
51 # Of course they broke it all again in 1.1...
52 assert twitter11.trends.place(_id=1)
53
32a4811d
HN
54def test_TwitterHTTPError_raised_for_invalid_oauth():
55 test_passed = False
56 try:
57 twitter11_na.statuses.mentions_timeline()
58 except TwitterHTTPError:
59 # this is the error we are looking for :)
60 test_passed = True
61 assert test_passed