]> jfr.im git - z_archive/twitter.git/blobdiff - tests/test_sanity.py
Merge
[z_archive/twitter.git] / tests / test_sanity.py
index 06cefafa82e9891235477b2db5480744cdaa4d75..19885060812c3a2c539ecd4ad9cd343c018dfbc3 100644 (file)
@@ -2,22 +2,28 @@
 
 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))
+              + (CONSUMER_KEY, CONSUMER_SECRET))
 
 twitter11 = Twitter(domain='api.twitter.com',
                     auth=oauth,
                     api_version='1.1')
-twitter11_na = Twitter(domain='api.twitter.com', auth=noauth, api_version='1.1')
 
+twitter11_na = Twitter(domain='api.twitter.com',
+                       auth=noauth,
+                       api_version='1.1')
 
 AZaz = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"
 
+
 def get_random_str():
     return ''.join(choice(AZaz) for _ in range(10))
 
@@ -43,14 +49,30 @@ def test_API_set_unicode_tweet():
 
 
 def test_search():
+    # In 1.1, search works on api.twitter.com not search.twitter.com
+    # and requires authorisation
     results = twitter11.search.tweets(q='foo')
     assert results
 
 
+def test_get_trends():
+    # This is one method of inserting parameters, using named
+    # underscore params.
+    world_trends = twitter11.trends.available(_woeid=1)
+    assert world_trends
+
+
+def test_get_trends_2():
+    # This is a nicer variation of the same call as above.
+    world_trends = twitter11.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:
@@ -59,3 +81,33 @@ 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
+
+# End of file