Added some more tests. Applied a fix to direct message parsing.
authorJosh Roesslein <jroesslein@gmail.com>
Fri, 7 Aug 2009 16:32:41 +0000 (11:32 -0500)
committerJosh Roesslein <jroesslein@gmail.com>
Fri, 7 Aug 2009 16:32:41 +0000 (11:32 -0500)
tests.py
tweepy/parsers.py

index 6bce512e9e39862a637d9d461a5aaf7749304ab9..62347ca572c3e3c847e2cdf03ca4436dbbd0ee31 100644 (file)
--- a/tests.py
+++ b/tests.py
@@ -25,8 +25,8 @@ class TweepyAPITests(unittest.TestCase):
     self.assert_(isinstance(s[0],Status))
 
   def testfriendstimeline(self):
-    s = self.api.friends_timeline(count=5)
-    self.assert_(len(s) == 5)
+    s = self.api.friends_timeline(count=1)
+    self.assert_(len(s) == 1)
     self.assert_(isinstance(s[0],Status))
 
   def testusertimeline(self):
@@ -67,6 +67,28 @@ class TweepyAPITests(unittest.TestCase):
     self.assert_(isinstance(me,User))
     self.assertEqual(me.screen_name, self.username)
 
+  def testfriends(self):
+    friends = self.api.friends()
+    self.assert_(len(friends) > 0)
+    self.assert_(isinstance(friends[0], User))
+
+  def testfollowers(self):
+    followers = self.api.followers()
+    self.assert_(len(followers) > 0)
+    self.assert_(isinstance(followers[0], User))
+
+  def testdirectmessages(self):
+    dms = self.api.direct_messages()
+    self.assert_(len(dms) > 0)
+    self.assert_(isinstance(dms[0], DirectMessage))
+
+  def testsenddirectmessage(self):
+    dm = self.api.send_direct_message(self.username, 'test message')
+    self.assert_(isinstance(dm, DirectMessage))
+    self.assertEqual(dm.text, 'test message')
+    self.assertEqual(dm.sender.screen_name, self.username)
+    self.assertEqual(dm.recipient.screen_name, self.username)
+
 if __name__ == '__main__':
   unittest.main()
     
index e54b3c647a5cfd8e04e0d37f338f9427e8fe07e4..f7704e84be5402ddc1bb138866f8f031c2bf4a8a 100644 (file)
@@ -85,7 +85,7 @@ def _parse_dm(obj, api):
   dm = api.classes['direct_message']()
   dm._api = api
   for k,v in obj.items():
-    if k == 'sender':
+    if k == 'sender' or k == 'recipient':
       setattr(dm, k, _parse_user(v, api))
     elif k == 'created_at':
       setattr(dm, k, _parse_datetime(v))