Merge lp:~robru/friends/better-retweet into lp:friends

Proposed by Robert Bruce Park
Status: Merged
Approved by: Ken VanDine
Approved revision: 193
Merged at revision: 192
Proposed branch: lp:~robru/friends/better-retweet
Merge into: lp:friends
Diff against target: 129 lines (+14/-34)
5 files modified
friends/protocols/twitter.py (+1/-14)
friends/tests/data/twitter-retweet.dat (+1/-1)
friends/tests/mocks.py (+0/-1)
friends/tests/test_identica.py (+1/-1)
friends/tests/test_twitter.py (+11/-17)
To merge this branch: bzr merge lp:~robru/friends/better-retweet
Reviewer Review Type Date Requested Status
Ken VanDine Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+159213@code.launchpad.net

Commit message

Save an extra HTTP request for each Twitter retweet we do.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:193
http://jenkins.qa.ubuntu.com/job/friends-ci/38/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/friends-raring-amd64-ci/38

Click here to trigger a rebuild:
http://s-jenkins:8080/job/friends-ci/38/rebuild

review: Approve (continuous-integration)
Revision history for this message
Ken VanDine (ken-vandine) wrote :

Even better!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'friends/protocols/twitter.py'
--- friends/protocols/twitter.py 2013-04-12 22:06:57 +0000
+++ friends/protocols/twitter.py 2013-04-16 18:11:25 +0000
@@ -78,11 +78,6 @@
78 self._account.secret_token = authdata.get('TokenSecret')78 self._account.secret_token = authdata.get('TokenSecret')
79 self._account.user_id = authdata.get('UserId')79 self._account.user_id = authdata.get('UserId')
80 self._account.user_name = authdata.get('ScreenName')80 self._account.user_name = authdata.get('ScreenName')
81 user = self._showuser(self._account.user_id)
82 self._account.user_full_name = user.get('name', '')
83 self._account.avatar_url = (user.get('profile_image_url_https') or
84 user.get('profile_image_url') or
85 '')
8681
87 def _get_url(self, url, data=None):82 def _get_url(self, url, data=None):
88 """Access the Twitter API with correct OAuth signed headers."""83 """Access the Twitter API with correct OAuth signed headers."""
@@ -288,15 +283,7 @@
288 def retweet(self, message_id):283 def retweet(self, message_id):
289 """Republish somebody else's tweet with your name on it."""284 """Republish somebody else's tweet with your name on it."""
290 url = self._retweet.format(message_id)285 url = self._retweet.format(message_id)
291 tweet = self._get_url(url, dict(trim_user='true'))286 tweet = self._get_url(url, dict(trim_user='false'))
292 user = tweet.get('user', {}) or tweet.get('sender', {})
293
294 # Fill in the blanks...
295 user.update(
296 name=self._account.user_full_name,
297 screen_name=self._account.user_name,
298 profile_image_url=self._account.avatar_url,
299 )
300287
301 return self._publish_tweet(tweet)288 return self._publish_tweet(tweet)
302289
303290
=== modified file 'friends/tests/data/twitter-retweet.dat'
--- friends/tests/data/twitter-retweet.dat 2013-04-12 22:19:35 +0000
+++ friends/tests/data/twitter-retweet.dat 2013-04-16 18:11:25 +0000
@@ -1,1 +1,1 @@
1{"place":null,"user":{"id_str":"836242932","id":836242932},"retweet_count":6,"created_at":"Fri Apr 12 20:23:14 +0000 2013","geo":null,"contributors":null,"retweeted":true,"id_str":"322807141108944896","coordinates":null,"truncated":false,"retweeted_status":{"place":null,"user":{"id_str":"45840709","id":45840709},"retweet_count":6,"created_at":"Fri Apr 12 16:52:59 +0000 2013","geo":null,"contributors":null,"retweeted":true,"id_str":"322754231591387136","coordinates":null,"truncated":false,"in_reply_to_status_id":null,"in_reply_to_screen_name":null,"possibly_sensitive":false,"favorited":false,"text":"Reading 'Core utility apps visual exploration' at Design http:\/\/t.co\/36tT53C37n","in_reply_to_status_id_str":null,"source":"\u003Ca href=\"http:\/\/twitter.com\/tweetbutton\" rel=\"nofollow\"\u003ETweet Button\u003C\/a\u003E","id":322754231591387136,"in_reply_to_user_id_str":null,"entities":{"hashtags":[],"user_mentions":[],"urls":[{"url":"http:\/\/t.co\/36tT53C37n","display_url":"design.canonical.com\/2013\/04\/core-u\u2026","indices":[57,79],"expanded_url":"http:\/\/design.canonical.com\/2013\/04\/core-utility-apps-visual-exploration\/"}]},"in_reply_to_user_id":null},"in_reply_to_status_id":null,"in_reply_to_screen_name":null,"possibly_sensitive":false,"favorited":false,"text":"RT @ubuntudesigners: Reading 'Core utility apps visual exploration' at Design http:\/\/t.co\/36tT53C37n","in_reply_to_status_id_str":null,"source":"\u003Ca href=\"http:\/\/www.ubuntu.com\" rel=\"nofollow\"\u003EUbuntu Online Accounts\u003C\/a\u003E","id":322807141108944896,"in_reply_to_user_id_str":null,"entities":{"hashtags":[],"user_mentions":[{"name":"Ubuntu Designers","screen_name":"ubuntudesigners","id_str":"45840709","indices":[3,19],"id":45840709}],"urls":[{"url":"http:\/\/t.co\/36tT53C37n","display_url":"design.canonical.com\/2013\/04\/core-u\u2026","indices":[78,100],"expanded_url":"http:\/\/design.canonical.com\/2013\/04\/core-utility-apps-visual-exploration\/"}]},"in_reply_to_user_id":null}1{"place":null,"user":{"id":836242932,"profile_background_tile":false,"geo_enabled":false,"profile_sidebar_fill_color":"DDEEF6","utc_offset":null,"entities":{"description":{"urls":[]}},"name":"Robert Bruce","is_translator":false,"default_profile_image":false,"profile_background_color":"C0DEED","favourites_count":9,"statuses_count":96,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/2631306428\/2a509db8a05b4310394b832d34a137a4_normal.png","protected":false,"created_at":"Thu Sep 20 19:53:35 +0000 2012","lang":"en","profile_background_image_url":"http:\/\/a0.twimg.com\/images\/themes\/theme1\/bg.png","profile_link_color":"0084B4","friends_count":44,"follow_request_sent":false,"profile_use_background_image":true,"default_profile":true,"profile_text_color":"333333","screen_name":"therealrobru","contributors_enabled":false,"url":null,"verified":false,"profile_background_image_url_https":"https:\/\/si0.twimg.com\/images\/themes\/theme1\/bg.png","time_zone":null,"followers_count":8,"following":false,"id_str":"836242932","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/2631306428\/2a509db8a05b4310394b832d34a137a4_normal.png","location":null,"profile_sidebar_border_color":"C0DEED","description":"Misanthrope. No pants. Tied to a tree with a skipping rope.","listed_count":0,"notifications":false},"favorited":false,"contributors":null,"in_reply_to_user_id":null,"id_str":"324220250889543682","retweet_count":1,"truncated":true,"created_at":"Tue Apr 16 17:58:26 +0000 2013","geo":null,"in_reply_to_status_id_str":null,"retweeted":true,"coordinates":null,"text":"RT @tarek_ziade: Just found a \"Notification of Inspection\" card in the bottom of my bag. looks like they were curious about those raspbe ...","in_reply_to_user_id_str":null,"retweeted_status":{"place":null,"user":{"id":15821652,"profile_background_tile":true,"geo_enabled":true,"profile_sidebar_fill_color":"DAECF4","utc_offset":3600,"entities":{"url":{"urls":[{"indices":[0,16],"url":"http:\/\/ziade.org","display_url":null,"expanded_url":null}]},"description":{"urls":[]}},"name":"Tarek Ziad\u00e9","is_translator":false,"default_profile_image":false,"profile_background_color":"C6E2EE","favourites_count":175,"statuses_count":8673,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/3308520017\/f35acb40d385f320eea8a789c2a5a37b_normal.jpeg","protected":false,"created_at":"Tue Aug 12 12:40:35 +0000 2008","lang":"en","profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/800421101\/30f37bcf2208ea3700fe07ce22722667.jpeg","profile_link_color":"1F98C7","friends_count":93,"follow_request_sent":false,"profile_use_background_image":true,"default_profile":false,"profile_text_color":"663B12","screen_name":"tarek_ziade","contributors_enabled":false,"url":"http:\/\/ziade.org","verified":false,"profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/800421101\/30f37bcf2208ea3700fe07ce22722667.jpeg","time_zone":"Paris","followers_count":3032,"following":true,"id_str":"15821652","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/3308520017\/f35acb40d385f320eea8a789c2a5a37b_normal.jpeg","location":"Turcey, France","profile_sidebar_border_color":"FFFFFF","description":"Country-side Python developer \u00b7 Works at Mozilla \u00b7 wrote some books","listed_count":279,"notifications":false},"favorited":false,"contributors":null,"in_reply_to_user_id":null,"id_str":"324200722273009666","retweet_count":1,"truncated":false,"created_at":"Tue Apr 16 16:40:50 +0000 2013","geo":null,"in_reply_to_status_id_str":null,"retweeted":true,"coordinates":null,"text":"Just found a \"Notification of Inspection\" card in the bottom of my bag. looks like they were curious about those raspberry-pi :O","in_reply_to_user_id_str":null,"in_reply_to_status_id":null,"source":"\u003Ca href=\"http:\/\/www.tweetdeck.com\" rel=\"nofollow\"\u003ETweetDeck\u003C\/a\u003E","in_reply_to_screen_name":null,"id":324200722273009666,"entities":{"urls":[],"hashtags":[],"user_mentions":[]}},"in_reply_to_status_id":null,"source":"\u003Ca href=\"http:\/\/www.ubuntu.com\" rel=\"nofollow\"\u003EUbuntu Online Accounts\u003C\/a\u003E","in_reply_to_screen_name":null,"id":324220250889543682,"entities":{"urls":[],"hashtags":[],"user_mentions":[{"name":"Tarek Ziad\u00e9","id_str":"15821652","indices":[3,15],"screen_name":"tarek_ziade","id":15821652}]}}
22
=== modified file 'friends/tests/mocks.py'
--- friends/tests/mocks.py 2013-04-12 22:06:57 +0000
+++ friends/tests/mocks.py 2013-04-16 18:11:25 +0000
@@ -119,7 +119,6 @@
119 def __init__(self, service=None, account_id=88):119 def __init__(self, service=None, account_id=88):
120 self.access_token = None120 self.access_token = None
121 self.secret_token = None121 self.secret_token = None
122 self.avatar_url = None
123 self.user_full_name = None122 self.user_full_name = None
124 self.user_name = None123 self.user_name = None
125 self.user_id = None124 self.user_id = None
126125
=== modified file 'friends/tests/test_identica.py'
--- friends/tests/test_identica.py 2013-04-12 22:06:57 +0000
+++ friends/tests/test_identica.py 2013-04-16 18:11:25 +0000
@@ -178,7 +178,7 @@
178 publish.assert_called_with(tweet)178 publish.assert_called_with(tweet)
179 get_url.assert_called_with(179 get_url.assert_called_with(
180 'http://identi.ca/api/statuses/retweet/1234.json',180 'http://identi.ca/api/statuses/retweet/1234.json',
181 dict(trim_user='true'))181 dict(trim_user='false'))
182182
183 def test_unfollow(self):183 def test_unfollow(self):
184 get_url = self.protocol._get_url = mock.Mock()184 get_url = self.protocol._get_url = mock.Mock()
185185
=== modified file 'friends/tests/test_twitter.py'
--- friends/tests/test_twitter.py 2013-04-12 22:06:57 +0000
+++ friends/tests/test_twitter.py 2013-04-16 18:11:25 +0000
@@ -71,13 +71,8 @@
71 TokenSecret='sssssshhh!',71 TokenSecret='sssssshhh!',
72 UserId='1234',72 UserId='1234',
73 ScreenName='stephenfry'))73 ScreenName='stephenfry'))
74 @mock.patch('friends.protocols.twitter.Twitter._showuser',
75 return_value=dict(name='Stephen Fry',
76 profile_image_url='http://example.com/me.jpg'))
77 def test_successful_authentication(self, *mocks):74 def test_successful_authentication(self, *mocks):
78 self.assertTrue(self.protocol._login())75 self.assertTrue(self.protocol._login())
79 self.assertEqual(self.account.avatar_url, 'http://example.com/me.jpg')
80 self.assertEqual(self.account.user_full_name, 'Stephen Fry')
81 self.assertEqual(self.account.user_name, 'stephenfry')76 self.assertEqual(self.account.user_name, 'stephenfry')
82 self.assertEqual(self.account.user_id, '1234')77 self.assertEqual(self.account.user_id, '1234')
83 self.assertEqual(self.account.access_token, 'some clever fake data')78 self.assertEqual(self.account.access_token, 'some clever fake data')
@@ -455,7 +450,7 @@
455 publish.assert_called_with(tweet)450 publish.assert_called_with(tweet)
456 get_url.assert_called_with(451 get_url.assert_called_with(
457 'https://api.twitter.com/1.1/statuses/retweet/1234.json',452 'https://api.twitter.com/1.1/statuses/retweet/1234.json',
458 dict(trim_user='true'))453 dict(trim_user='false'))
459454
460 @mock.patch('friends.utils.base.Model', TestModel)455 @mock.patch('friends.utils.base.Model', TestModel)
461 @mock.patch('friends.utils.http.Soup.Message',456 @mock.patch('friends.utils.http.Soup.Message',
@@ -466,27 +461,26 @@
466 def test_retweet_with_data(self, *mocks):461 def test_retweet_with_data(self, *mocks):
467 self.account.access_token = 'access'462 self.account.access_token = 'access'
468 self.account.secret_token = 'secret'463 self.account.secret_token = 'secret'
469 self.account.user_name = 'some_guy'464 self.account.user_name = 'therealrobru'
470 self.account.user_full_name = 'Guy Man'
471 self.account.avatar_url = 'http://example.com/me.jpg'
472 self.account.auth.parameters = dict(465 self.account.auth.parameters = dict(
473 ConsumerKey='key',466 ConsumerKey='key',
474 ConsumerSecret='secret')467 ConsumerSecret='secret')
475 self.assertEqual(0, TestModel.get_n_rows())468 self.assertEqual(0, TestModel.get_n_rows())
476 self.assertEqual(469 self.assertEqual(
477 self.protocol.retweet('240558470661799936'),470 self.protocol.retweet('240558470661799936'),
478 'https://twitter.com/some_guy/status/322807141108944896')471 'https://twitter.com/therealrobru/status/324220250889543682')
479 self.assertEqual(1, TestModel.get_n_rows())472 self.assertEqual(1, TestModel.get_n_rows())
480473
474 self.maxDiff = None
481 expected_row = [475 expected_row = [
482 'twitter', 88, '322807141108944896',476 'twitter', 88, '324220250889543682',
483 'messages', 'Guy Man', '836242932', 'some_guy', True,477 'messages', 'Robert Bruce', '836242932', 'therealrobru', True,
484 '2013-04-12T20:23:14Z', 'RT @ubuntudesigners: Reading \'Core utility'478 '2013-04-16T17:58:26Z', 'RT @tarek_ziade: Just found a "Notification '
485 ' apps visual exploration\' at Design <a href="http://t.co/'479 'of Inspection" card in the bottom of my bag. looks like they were '
486 '36tT53C37n">http://t.co/36tT53C37n</a>',480 'curious about those raspbe ...',
487 GLib.get_user_cache_dir() +481 GLib.get_user_cache_dir() +
488 '/friends/avatars/6e8af1e6860da04a6f42cb1e6934e191f7c38c6d',482 '/friends/avatars/1444c8a86dbbe7a6f5f89a8135e770824d7b22bc',
489 'https://twitter.com/some_guy/status/322807141108944896',483 'https://twitter.com/therealrobru/status/324220250889543682',
490 0, False, '', '', '', '', '', '', '', 0.0, 0.0,484 0, False, '', '', '', '', '', '', '', 0.0, 0.0,
491 ]485 ]
492 self.assertEqual(list(TestModel.get_row(0)), expected_row)486 self.assertEqual(list(TestModel.get_row(0)), expected_row)

Subscribers

People subscribed via source and target branches