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
1=== modified file 'friends/protocols/twitter.py'
2--- friends/protocols/twitter.py 2013-04-12 22:06:57 +0000
3+++ friends/protocols/twitter.py 2013-04-16 18:11:25 +0000
4@@ -78,11 +78,6 @@
5 self._account.secret_token = authdata.get('TokenSecret')
6 self._account.user_id = authdata.get('UserId')
7 self._account.user_name = authdata.get('ScreenName')
8- user = self._showuser(self._account.user_id)
9- self._account.user_full_name = user.get('name', '')
10- self._account.avatar_url = (user.get('profile_image_url_https') or
11- user.get('profile_image_url') or
12- '')
13
14 def _get_url(self, url, data=None):
15 """Access the Twitter API with correct OAuth signed headers."""
16@@ -288,15 +283,7 @@
17 def retweet(self, message_id):
18 """Republish somebody else's tweet with your name on it."""
19 url = self._retweet.format(message_id)
20- tweet = self._get_url(url, dict(trim_user='true'))
21- user = tweet.get('user', {}) or tweet.get('sender', {})
22-
23- # Fill in the blanks...
24- user.update(
25- name=self._account.user_full_name,
26- screen_name=self._account.user_name,
27- profile_image_url=self._account.avatar_url,
28- )
29+ tweet = self._get_url(url, dict(trim_user='false'))
30
31 return self._publish_tweet(tweet)
32
33
34=== modified file 'friends/tests/data/twitter-retweet.dat'
35--- friends/tests/data/twitter-retweet.dat 2013-04-12 22:19:35 +0000
36+++ friends/tests/data/twitter-retweet.dat 2013-04-16 18:11:25 +0000
37@@ -1,1 +1,1 @@
38-{"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}
39+{"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}]}}
40
41=== modified file 'friends/tests/mocks.py'
42--- friends/tests/mocks.py 2013-04-12 22:06:57 +0000
43+++ friends/tests/mocks.py 2013-04-16 18:11:25 +0000
44@@ -119,7 +119,6 @@
45 def __init__(self, service=None, account_id=88):
46 self.access_token = None
47 self.secret_token = None
48- self.avatar_url = None
49 self.user_full_name = None
50 self.user_name = None
51 self.user_id = None
52
53=== modified file 'friends/tests/test_identica.py'
54--- friends/tests/test_identica.py 2013-04-12 22:06:57 +0000
55+++ friends/tests/test_identica.py 2013-04-16 18:11:25 +0000
56@@ -178,7 +178,7 @@
57 publish.assert_called_with(tweet)
58 get_url.assert_called_with(
59 'http://identi.ca/api/statuses/retweet/1234.json',
60- dict(trim_user='true'))
61+ dict(trim_user='false'))
62
63 def test_unfollow(self):
64 get_url = self.protocol._get_url = mock.Mock()
65
66=== modified file 'friends/tests/test_twitter.py'
67--- friends/tests/test_twitter.py 2013-04-12 22:06:57 +0000
68+++ friends/tests/test_twitter.py 2013-04-16 18:11:25 +0000
69@@ -71,13 +71,8 @@
70 TokenSecret='sssssshhh!',
71 UserId='1234',
72 ScreenName='stephenfry'))
73- @mock.patch('friends.protocols.twitter.Twitter._showuser',
74- return_value=dict(name='Stephen Fry',
75- profile_image_url='http://example.com/me.jpg'))
76 def test_successful_authentication(self, *mocks):
77 self.assertTrue(self.protocol._login())
78- self.assertEqual(self.account.avatar_url, 'http://example.com/me.jpg')
79- self.assertEqual(self.account.user_full_name, 'Stephen Fry')
80 self.assertEqual(self.account.user_name, 'stephenfry')
81 self.assertEqual(self.account.user_id, '1234')
82 self.assertEqual(self.account.access_token, 'some clever fake data')
83@@ -455,7 +450,7 @@
84 publish.assert_called_with(tweet)
85 get_url.assert_called_with(
86 'https://api.twitter.com/1.1/statuses/retweet/1234.json',
87- dict(trim_user='true'))
88+ dict(trim_user='false'))
89
90 @mock.patch('friends.utils.base.Model', TestModel)
91 @mock.patch('friends.utils.http.Soup.Message',
92@@ -466,27 +461,26 @@
93 def test_retweet_with_data(self, *mocks):
94 self.account.access_token = 'access'
95 self.account.secret_token = 'secret'
96- self.account.user_name = 'some_guy'
97- self.account.user_full_name = 'Guy Man'
98- self.account.avatar_url = 'http://example.com/me.jpg'
99+ self.account.user_name = 'therealrobru'
100 self.account.auth.parameters = dict(
101 ConsumerKey='key',
102 ConsumerSecret='secret')
103 self.assertEqual(0, TestModel.get_n_rows())
104 self.assertEqual(
105 self.protocol.retweet('240558470661799936'),
106- 'https://twitter.com/some_guy/status/322807141108944896')
107+ 'https://twitter.com/therealrobru/status/324220250889543682')
108 self.assertEqual(1, TestModel.get_n_rows())
109
110+ self.maxDiff = None
111 expected_row = [
112- 'twitter', 88, '322807141108944896',
113- 'messages', 'Guy Man', '836242932', 'some_guy', True,
114- '2013-04-12T20:23:14Z', 'RT @ubuntudesigners: Reading \'Core utility'
115- ' apps visual exploration\' at Design <a href="http://t.co/'
116- '36tT53C37n">http://t.co/36tT53C37n</a>',
117+ 'twitter', 88, '324220250889543682',
118+ 'messages', 'Robert Bruce', '836242932', 'therealrobru', True,
119+ '2013-04-16T17:58:26Z', 'RT @tarek_ziade: Just found a "Notification '
120+ 'of Inspection" card in the bottom of my bag. looks like they were '
121+ 'curious about those raspbe ...',
122 GLib.get_user_cache_dir() +
123- '/friends/avatars/6e8af1e6860da04a6f42cb1e6934e191f7c38c6d',
124- 'https://twitter.com/some_guy/status/322807141108944896',
125+ '/friends/avatars/1444c8a86dbbe7a6f5f89a8135e770824d7b22bc',
126+ 'https://twitter.com/therealrobru/status/324220250889543682',
127 0, False, '', '', '', '', '', '', '', 0.0, 0.0,
128 ]
129 self.assertEqual(list(TestModel.get_row(0)), expected_row)

Subscribers

People subscribed via source and target branches