]>
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 | |
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 | twitter = Twitter(domain='api.twitter.com', | |
14 | auth=oauth, | |
15 | api_version='1') | |
16 | twitter_na = Twitter(domain='api.twitter.com', auth=noauth, api_version='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_get_some_public_tweets(): | |
26 | updates = twitter_na.statuses.public_timeline() | |
27 | assert updates | |
28 | assert updates[0]['created_at'] | |
29 | ||
30 | ||
31 | def test_API_set_tweet(): | |
32 | random_tweet = "A random tweet " + get_random_str() | |
33 | twitter.statuses.update(status=random_tweet) | |
34 | time.sleep(2) | |
35 | recent = twitter.statuses.user_timeline() | |
36 | assert recent | |
37 | assert isinstance(recent.rate_limit_remaining, int) | |
38 | assert isinstance(recent.rate_limit_reset, int) | |
39 | assert random_tweet == recent[0]['text'] | |
40 | ||
41 | ||
42 | def test_API_set_unicode_tweet(): | |
43 | random_tweet = u"A random tweet with unicode ⇰ÐÀ " + get_random_str() | |
44 | twitter.statuses.update(status=random_tweet) | |
45 | ||
46 | recent = twitter.statuses.user_timeline() | |
47 | assert recent | |
48 | assert random_tweet == recent[0]['text'] | |
49 | ||
50 | ||
51 | def test_API_friendship_exists(): | |
52 | assert True == twitter.friendships.exists( | |
53 | user_a='ptttest0001', user_b='sixohsix') | |
54 | assert False == twitter.friendships.exists( | |
55 | user_a='gruber', user_b='ptttest0001') | |
56 | ||
57 | ||
58 | def test_search(): | |
59 | t_search = Twitter(domain='search.twitter.com') | |
60 | results = t_search.search(q='foo') | |
61 | assert results | |
62 | ||
63 | ||
64 | def test_get_trends(): | |
65 | # This is one method of inserting parameters, using named | |
66 | # underscore params. | |
67 | world_trends = twitter.trends._woeid(_woeid=1) | |
68 | assert world_trends | |
69 | ||
70 | ||
71 | def test_get_trends_2(): | |
72 | # This is a nicer variation of the same call as above. | |
73 | world_trends = twitter.trends._(1) | |
74 | assert world_trends |