# HG changeset patch # User dclinton@b35c0ba3-1128-0410-9219-0b39014e361d # Date 1251859405 0 # Branch dclinton # Node ID bc093eb1a8d8ef1cf81cee15dacf7bc8b03ea275 # Parent 2bb49ee4f1fa5ce7faefb21bafa64d78f94736f7 Added tests and completed implementation of ShowFriendships diff -r 2bb49ee4f1fa5ce7faefb21bafa64d78f94736f7 -r bc093eb1a8d8ef1cf81cee15dacf7bc8b03ea275 testdata/show_friendships.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testdata/show_friendships.json Wed Sep 02 02:43:25 2009 +0000 @@ -0,0 +1,1 @@ +{"relationship":{"target":{"following":true,"followed_by":true,"id":20,"screen_name":"ev"},"source":{"blocking":null,"following":true,"followed_by":true,"id":673483,"notifications_enabled":null,"screen_name":"dewitt"}}} \ No newline at end of file diff -r 2bb49ee4f1fa5ce7faefb21bafa64d78f94736f7 -r bc093eb1a8d8ef1cf81cee15dacf7bc8b03ea275 twitter.proto --- a/twitter.proto Tue Sep 01 14:51:20 2009 +0000 +++ b/twitter.proto Wed Sep 02 02:43:25 2009 +0000 @@ -176,6 +176,7 @@ optional bool following = 3; optional bool followed_by = 4; optional bool notifications_enabled = 5; + optional bool blocking = 6; } optional User source = 1; diff -r 2bb49ee4f1fa5ce7faefb21bafa64d78f94736f7 -r bc093eb1a8d8ef1cf81cee15dacf7bc8b03ea275 twitter.py --- a/twitter.py Tue Sep 01 14:51:20 2009 +0000 +++ b/twitter.py Wed Sep 02 02:43:25 2009 +0000 @@ -119,12 +119,15 @@ A Relationship instance ''' relationship = twitter_pb2.Relationship() - if 'source' in data: + if 'relationship' not in data: + return None + relationship_data = data['relationship'] + if 'source' in relationship_data: relationship.source.CopyFrom( - NewRelationshipUserFromJsonDict(data['source'])) - if 'target' in data: + NewRelationshipUserFromJsonDict(relationship_data['source'])) + if 'target' in relationship_data: relationship.target.CopyFrom( - NewRelationshipUserFromJsonDict(data['target'])) + NewRelationshipUserFromJsonDict(relationship_data['target'])) return relationship @@ -142,6 +145,7 @@ _CopyProperty(data, user, 'following') _CopyProperty(data, user, 'followed_by') _CopyProperty(data, user, 'notifications_enabled') + _CopyProperty(data, user, 'blocking') return user diff -r 2bb49ee4f1fa5ce7faefb21bafa64d78f94736f7 -r bc093eb1a8d8ef1cf81cee15dacf7bc8b03ea275 twitter_pb2.py --- a/twitter_pb2.py Tue Sep 01 14:51:20 2009 +0000 +++ b/twitter_pb2.py Wed Sep 02 02:43:25 2009 +0000 @@ -772,6 +772,13 @@ message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), + descriptor.FieldDescriptor( + name='blocking', full_name='twitter.Relationship.User.blocking', index=5, + number=6, type=8, cpp_type=7, label=1, + default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), ], extensions=[ ], diff -r 2bb49ee4f1fa5ce7faefb21bafa64d78f94736f7 -r bc093eb1a8d8ef1cf81cee15dacf7bc8b03ea275 twitter_test.py --- a/twitter_test.py Tue Sep 01 14:51:20 2009 +0000 +++ b/twitter_test.py Wed Sep 02 02:43:25 2009 +0000 @@ -490,6 +490,29 @@ results = self._api.Search('twitter') self.assertEqual(10, len(results.results)) + def testShowFriendships(self): + '''Test the Twitter.Api ShowFriendships method''' + self._AddHandler( + 'http://twitter.com/friendships/show.json' + + '?target_screen_name=ev' + + '&source_screen_name=dewitt', + curry(self._OpenTestData, 'show_friendships.json')) + relationship = self._api.ShowFriendships( + source_screen_name='dewitt', target_screen_name='ev') + self.assertTrue(relationship != None) + self.assertTrue(relationship._has_source) + self.assertTrue(relationship._has_target) + self.assertEqual(True, relationship.target.following) + self.assertEqual(True, relationship.target.followed_by) + self.assertEqual(20, relationship.target.id) + self.assertEqual('ev', relationship.target.screen_name) + self.assertEqual(False, relationship.source.notifications_enabled) + self.assertEqual(False, relationship.source.blocking) + self.assertEqual(True, relationship.source.following) + self.assertEqual(True, relationship.source.followed_by) + self.assertEqual(673483, relationship.source.id) + self.assertEqual('dewitt', relationship.source.screen_name) + def _AddHandler(self, url, callback): self._urllib.AddHandler(url, callback)