]> jfr.im git - z_archive/twitter.git/commitdiff
We have gone too long without tests.
authorMike Verdone <redacted>
Mon, 7 Mar 2011 21:45:00 +0000 (22:45 +0100)
committerMike Verdone <redacted>
Mon, 7 Mar 2011 21:45:00 +0000 (22:45 +0100)
tests/__init__.py [new file with mode: 0644]
tests/oauth_creds [new file with mode: 0644]
tests/test_sanity.py [new file with mode: 0644]

diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/oauth_creds b/tests/oauth_creds
new file mode 100644 (file)
index 0000000..a3378b0
--- /dev/null
@@ -0,0 +1,2 @@
+262332119-7bclllngLikvfVFAqgSe1cRNUE0cnVSYD2YOX7Ju
+aRTJHmcY6szoRLCfHZccTkCqX7yrL3B4fYjwB5ZrI
diff --git a/tests/test_sanity.py b/tests/test_sanity.py
new file mode 100644 (file)
index 0000000..9375963
--- /dev/null
@@ -0,0 +1,42 @@
+
+from random import choice
+
+from twitter import Twitter, NoAuth, OAuth, read_token_file
+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')
+twitter_na = Twitter(domain='api.twitter.com', auth=noauth, api_version='1')
+
+
+AZaz = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+
+def get_random_str():
+    return ''.join(choice(AZaz) for _ in range(10))
+
+
+def test_API_get_some_public_tweets():
+    updates = twitter_na.statuses.public_timeline()
+    assert updates
+    assert updates[0]['created_at']
+
+
+def test_API_set_tweet():
+    random_tweet = "A random tweet " + get_random_str()
+    twitter.statuses.update(status=random_tweet)
+
+    recent = twitter.statuses.user_timeline()
+    assert recent
+    assert random_tweet == recent[0]['text']
+
+
+def test_API_friendship_exists():
+    assert True == twitter.friendships.exists(
+        user_a='ptttest0001', user_b='sixohsix')
+    assert False == twitter.friendships.exists(
+        user_a='gruber', user_b='ptttest0001')