X-Git-Url: https://jfr.im/git/z_archive/twitter.git/blobdiff_plain/697d6b54ddcd8921773304f0b75d2db77b9c92b5..454fc9c0555c2995f0b231cfe5b760164989c4f7:/tests/test_sanity.py diff --git a/tests/test_sanity.py b/tests/test_sanity.py index cb9bf17..880edc9 100644 --- a/tests/test_sanity.py +++ b/tests/test_sanity.py @@ -2,21 +2,20 @@ from random import choice import time +import pickle +import json from twitter import Twitter, NoAuth, OAuth, read_token_file, TwitterHTTPError +from twitter.api import TwitterDictResponse, TwitterListResponse from twitter.cmdline import CONSUMER_KEY, CONSUMER_SECRET noauth = NoAuth() oauth = OAuth(*read_token_file('tests/oauth_creds') + (CONSUMER_KEY, CONSUMER_SECRET)) -twitter = Twitter(domain='api.twitter.com', - auth=oauth, - api_version='1') twitter11 = Twitter(domain='api.twitter.com', auth=oauth, api_version='1.1') -twitter_na = Twitter(domain='api.twitter.com', auth=noauth, api_version='1') twitter11_na = Twitter(domain='api.twitter.com', auth=noauth, api_version='1.1') @@ -28,9 +27,9 @@ def get_random_str(): def test_API_set_tweet(): random_tweet = "A random tweet " + get_random_str() - twitter.statuses.update(status=random_tweet) + twitter11.statuses.update(status=random_tweet) time.sleep(2) - recent = twitter.statuses.user_timeline() + recent = twitter11.statuses.home_timeline() assert recent assert isinstance(recent.rate_limit_remaining, int) assert isinstance(recent.rate_limit_reset, int) @@ -39,9 +38,9 @@ def test_API_set_tweet(): def test_API_set_unicode_tweet(): random_tweet = u"A random tweet with unicode üøπ" + get_random_str() - twitter.statuses.update(status=random_tweet) + twitter11.statuses.update(status=random_tweet) - recent = twitter.statuses.user_timeline() + recent = twitter11.statuses.home_timeline() assert recent assert random_tweet == recent[0]['text'] @@ -51,23 +50,11 @@ def test_search(): assert results -def test_get_trends(): - # This is one method of inserting parameters, using named - # underscore params. - world_trends = twitter.trends._woeid(_woeid=1) - assert world_trends - - -def test_get_trends_2(): - # This is a nicer variation of the same call as above. - world_trends = twitter.trends._(1) - assert world_trends - - def test_get_trends_3(): # Of course they broke it all again in 1.1... assert twitter11.trends.place(_id=1) + def test_TwitterHTTPError_raised_for_invalid_oauth(): test_passed = False try: @@ -76,3 +63,31 @@ def test_TwitterHTTPError_raised_for_invalid_oauth(): # this is the error we are looking for :) test_passed = True assert test_passed + + +def test_picklability(): + res = TwitterDictResponse({'a': 'b'}) + p = pickle.dumps(res) + res2 = pickle.loads(p) + assert res == res2 + assert res2['a'] == 'b' + + res = TwitterListResponse([1, 2, 3]) + p = pickle.dumps(res) + res2 = pickle.loads(p) + assert res == res2 + assert res2[2] == 3 + + +def test_jsonifability(): + res = TwitterDictResponse({'a': 'b'}) + p = json.dumps(res) + res2 = json.loads(p) + assert res == res2 + assert res2['a'] == 'b' + + res = TwitterListResponse([1, 2, 3]) + p = json.dumps(res) + res2 = json.loads(p) + assert res == res2 + assert res2[2] == 3