]>
Commit | Line | Data |
---|---|---|
1 | # encoding: utf8 | |
2 | ||
3 | from random import choice | |
4 | import time | |
5 | ||
6 | from twitter import Twitter, NoAuth, OAuth, read_token_file, TwitterHTTPError | |
7 | from twitter.cmdline import CONSUMER_KEY, CONSUMER_SECRET | |
8 | ||
9 | noauth = NoAuth() | |
10 | oauth = OAuth(*read_token_file('tests/oauth_creds') | |
11 | + (CONSUMER_KEY, CONSUMER_SECRET)) | |
12 | ||
13 | twitter11 = Twitter(domain='api.twitter.com', | |
14 | auth=oauth, | |
15 | api_version='1.1') | |
16 | twitter11_na = Twitter(domain='api.twitter.com', auth=noauth, api_version='1.1') | |
17 | ||
18 | ||
19 | AZaz = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
20 | ||
21 | def get_random_str(): | |
22 | return ''.join(choice(AZaz) for _ in range(10)) | |
23 | ||
24 | ||
25 | def test_API_set_tweet(): | |
26 | random_tweet = "A random tweet " + get_random_str() | |
27 | twitter11.statuses.update(status=random_tweet) | |
28 | time.sleep(2) | |
29 | recent = twitter11.statuses.home_timeline() | |
30 | assert recent | |
31 | assert isinstance(recent.rate_limit_remaining, int) | |
32 | assert isinstance(recent.rate_limit_reset, int) | |
33 | assert random_tweet == recent[0]['text'] | |
34 | ||
35 | ||
36 | def test_API_set_unicode_tweet(): | |
37 | random_tweet = u"A random tweet with unicode üøπ" + get_random_str() | |
38 | twitter11.statuses.update(status=random_tweet) | |
39 | ||
40 | recent = twitter11.statuses.home_timeline() | |
41 | assert recent | |
42 | assert random_tweet == recent[0]['text'] | |
43 | ||
44 | ||
45 | def test_search(): | |
46 | results = twitter11.search.tweets(q='foo') | |
47 | assert results | |
48 | ||
49 | ||
50 | def test_get_trends_3(): | |
51 | # Of course they broke it all again in 1.1... | |
52 | assert twitter11.trends.place(_id=1) | |
53 | ||
54 | def 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 |