]> jfr.im git - z_archive/twitter.git/commitdiff
add tests for update_with_media api function
authorRouxRC <redacted>
Sun, 28 Sep 2014 23:48:19 +0000 (01:48 +0200)
committerRouxRC <redacted>
Sun, 28 Sep 2014 23:48:19 +0000 (01:48 +0200)
tests/test_sanity.py

index 6e5f0c492a7880e4f13ff06e8fe5e502011e9bb6..8cfe322976235b43ad67cd326023a444c4233a48 100644 (file)
@@ -1,6 +1,7 @@
 # encoding: utf-8
 from __future__ import unicode_literals
 
+import os
 from random import choice
 import time
 import pickle
@@ -51,6 +52,37 @@ def test_API_set_unicode_tweet():
     assert random_tweet in texts
 
 
+def clean_link(text):
+    pos = text.find(" http://t.co")
+    if pos != -1:
+        return text[:pos]
+    return text
+
+__location__ = os.path.realpath(
+    os.path.join(os.getcwd(), os.path.dirname(__file__)))
+
+def test_API_set_unicode_twitpic(base64=False):
+    random_tweet = "A random twitpic from %s with unicode üøπ" % \
+                    ("base64" if base64 else "file") + get_random_str()
+    if base64:
+        img = b"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB94JFhMBAJv5kaUAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAA4UlEQVQoz7WSIZLGIAxG6c5OFZjianBcIOfgPkju1DsEBWfAUEcNGGpY8Xe7dDoVFRvHfO8NJGRorZE39UVe1nd/WNfVObcsi3OOEAIASikAmOf5D2q/FWPUWgshKKWfiFIqhNBaxxhPjPQ05/z+Bs557xw9hBC89ymlu5BS8t6HEC5NW2sR8alRRLTWXoRSSinlSejT12M9BAAAgCeoTw9BSimlfBIu6WdYtVZEVErdaaUUItZaL/9wOsaY83YAMMb0dGtt6Jdv3/ec87ZtOWdCCGNsmibG2DiOJzP8+7b+AAOmsiPxyHWCAAAAAElFTkSuQmCC"
+    else:
+        with open(os.path.join(__location__, "test.png"), "rb") as f:
+            img = f.read()
+    params = {"status": random_tweet, "media[]": img}
+    if base64:
+        params["_base64"] = True
+    twitter11.statuses.update_with_media(**params)
+    time.sleep(5)
+    recent = twitter11.statuses.home_timeline()
+    assert recent
+    texts = [clean_link(tweet['text']) for tweet in recent]
+    assert random_tweet in texts
+
+def test_API_set_unicode_twitpic_base64():
+    test_API_set_unicode_twitpic(base64=True)
+
+
 def test_search():
     # In 1.1, search works on api.twitter.com not search.twitter.com
     # and requires authorisation