Merge lp:~robru/friends/better-retweet into lp:friends
- better-retweet
- Merge into trunk
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 |
Related bugs: |
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.
Description of the change
To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : | # |
review:
Approve
(continuous-integration)
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 | 78 | self._account.secret_token = authdata.get('TokenSecret') | 78 | self._account.secret_token = authdata.get('TokenSecret') |
6 | 79 | self._account.user_id = authdata.get('UserId') | 79 | self._account.user_id = authdata.get('UserId') |
7 | 80 | self._account.user_name = authdata.get('ScreenName') | 80 | self._account.user_name = authdata.get('ScreenName') |
8 | 81 | user = self._showuser(self._account.user_id) | ||
9 | 82 | self._account.user_full_name = user.get('name', '') | ||
10 | 83 | self._account.avatar_url = (user.get('profile_image_url_https') or | ||
11 | 84 | user.get('profile_image_url') or | ||
12 | 85 | '') | ||
13 | 86 | 81 | ||
14 | 87 | def _get_url(self, url, data=None): | 82 | def _get_url(self, url, data=None): |
15 | 88 | """Access the Twitter API with correct OAuth signed headers.""" | 83 | """Access the Twitter API with correct OAuth signed headers.""" |
16 | @@ -288,15 +283,7 @@ | |||
17 | 288 | def retweet(self, message_id): | 283 | def retweet(self, message_id): |
18 | 289 | """Republish somebody else's tweet with your name on it.""" | 284 | """Republish somebody else's tweet with your name on it.""" |
19 | 290 | url = self._retweet.format(message_id) | 285 | url = self._retweet.format(message_id) |
29 | 291 | tweet = self._get_url(url, dict(trim_user='true')) | 286 | tweet = self._get_url(url, dict(trim_user='false')) |
21 | 292 | user = tweet.get('user', {}) or tweet.get('sender', {}) | ||
22 | 293 | |||
23 | 294 | # Fill in the blanks... | ||
24 | 295 | user.update( | ||
25 | 296 | name=self._account.user_full_name, | ||
26 | 297 | screen_name=self._account.user_name, | ||
27 | 298 | profile_image_url=self._account.avatar_url, | ||
28 | 299 | ) | ||
30 | 300 | 287 | ||
31 | 301 | return self._publish_tweet(tweet) | 288 | return self._publish_tweet(tweet) |
32 | 302 | 289 | ||
33 | 303 | 290 | ||
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 @@ | |||
39 | 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}]}} |
40 | 2 | 2 | ||
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 | 119 | def __init__(self, service=None, account_id=88): | 119 | def __init__(self, service=None, account_id=88): |
46 | 120 | self.access_token = None | 120 | self.access_token = None |
47 | 121 | self.secret_token = None | 121 | self.secret_token = None |
48 | 122 | self.avatar_url = None | ||
49 | 123 | self.user_full_name = None | 122 | self.user_full_name = None |
50 | 124 | self.user_name = None | 123 | self.user_name = None |
51 | 125 | self.user_id = None | 124 | self.user_id = None |
52 | 126 | 125 | ||
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 | 178 | publish.assert_called_with(tweet) | 178 | publish.assert_called_with(tweet) |
58 | 179 | get_url.assert_called_with( | 179 | get_url.assert_called_with( |
59 | 180 | 'http://identi.ca/api/statuses/retweet/1234.json', | 180 | 'http://identi.ca/api/statuses/retweet/1234.json', |
61 | 181 | dict(trim_user='true')) | 181 | dict(trim_user='false')) |
62 | 182 | 182 | ||
63 | 183 | def test_unfollow(self): | 183 | def test_unfollow(self): |
64 | 184 | get_url = self.protocol._get_url = mock.Mock() | 184 | get_url = self.protocol._get_url = mock.Mock() |
65 | 185 | 185 | ||
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 | 71 | TokenSecret='sssssshhh!', | 71 | TokenSecret='sssssshhh!', |
71 | 72 | UserId='1234', | 72 | UserId='1234', |
72 | 73 | ScreenName='stephenfry')) | 73 | ScreenName='stephenfry')) |
73 | 74 | @mock.patch('friends.protocols.twitter.Twitter._showuser', | ||
74 | 75 | return_value=dict(name='Stephen Fry', | ||
75 | 76 | profile_image_url='http://example.com/me.jpg')) | ||
76 | 77 | def test_successful_authentication(self, *mocks): | 74 | def test_successful_authentication(self, *mocks): |
77 | 78 | self.assertTrue(self.protocol._login()) | 75 | self.assertTrue(self.protocol._login()) |
78 | 79 | self.assertEqual(self.account.avatar_url, 'http://example.com/me.jpg') | ||
79 | 80 | self.assertEqual(self.account.user_full_name, 'Stephen Fry') | ||
80 | 81 | self.assertEqual(self.account.user_name, 'stephenfry') | 76 | self.assertEqual(self.account.user_name, 'stephenfry') |
81 | 82 | self.assertEqual(self.account.user_id, '1234') | 77 | self.assertEqual(self.account.user_id, '1234') |
82 | 83 | self.assertEqual(self.account.access_token, 'some clever fake data') | 78 | self.assertEqual(self.account.access_token, 'some clever fake data') |
83 | @@ -455,7 +450,7 @@ | |||
84 | 455 | publish.assert_called_with(tweet) | 450 | publish.assert_called_with(tweet) |
85 | 456 | get_url.assert_called_with( | 451 | get_url.assert_called_with( |
86 | 457 | 'https://api.twitter.com/1.1/statuses/retweet/1234.json', | 452 | 'https://api.twitter.com/1.1/statuses/retweet/1234.json', |
88 | 458 | dict(trim_user='true')) | 453 | dict(trim_user='false')) |
89 | 459 | 454 | ||
90 | 460 | @mock.patch('friends.utils.base.Model', TestModel) | 455 | @mock.patch('friends.utils.base.Model', TestModel) |
91 | 461 | @mock.patch('friends.utils.http.Soup.Message', | 456 | @mock.patch('friends.utils.http.Soup.Message', |
92 | @@ -466,27 +461,26 @@ | |||
93 | 466 | def test_retweet_with_data(self, *mocks): | 461 | def test_retweet_with_data(self, *mocks): |
94 | 467 | self.account.access_token = 'access' | 462 | self.account.access_token = 'access' |
95 | 468 | self.account.secret_token = 'secret' | 463 | self.account.secret_token = 'secret' |
99 | 469 | self.account.user_name = 'some_guy' | 464 | self.account.user_name = 'therealrobru' |
97 | 470 | self.account.user_full_name = 'Guy Man' | ||
98 | 471 | self.account.avatar_url = 'http://example.com/me.jpg' | ||
100 | 472 | self.account.auth.parameters = dict( | 465 | self.account.auth.parameters = dict( |
101 | 473 | ConsumerKey='key', | 466 | ConsumerKey='key', |
102 | 474 | ConsumerSecret='secret') | 467 | ConsumerSecret='secret') |
103 | 475 | self.assertEqual(0, TestModel.get_n_rows()) | 468 | self.assertEqual(0, TestModel.get_n_rows()) |
104 | 476 | self.assertEqual( | 469 | self.assertEqual( |
105 | 477 | self.protocol.retweet('240558470661799936'), | 470 | self.protocol.retweet('240558470661799936'), |
107 | 478 | 'https://twitter.com/some_guy/status/322807141108944896') | 471 | 'https://twitter.com/therealrobru/status/324220250889543682') |
108 | 479 | self.assertEqual(1, TestModel.get_n_rows()) | 472 | self.assertEqual(1, TestModel.get_n_rows()) |
109 | 480 | 473 | ||
110 | 474 | self.maxDiff = None | ||
111 | 481 | expected_row = [ | 475 | expected_row = [ |
117 | 482 | 'twitter', 88, '322807141108944896', | 476 | 'twitter', 88, '324220250889543682', |
118 | 483 | 'messages', 'Guy Man', '836242932', 'some_guy', True, | 477 | 'messages', 'Robert Bruce', '836242932', 'therealrobru', True, |
119 | 484 | '2013-04-12T20:23:14Z', 'RT @ubuntudesigners: Reading \'Core utility' | 478 | '2013-04-16T17:58:26Z', 'RT @tarek_ziade: Just found a "Notification ' |
120 | 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 ' |
121 | 486 | '36tT53C37n">http://t.co/36tT53C37n</a>', | 480 | 'curious about those raspbe ...', |
122 | 487 | GLib.get_user_cache_dir() + | 481 | GLib.get_user_cache_dir() + |
125 | 488 | '/friends/avatars/6e8af1e6860da04a6f42cb1e6934e191f7c38c6d', | 482 | '/friends/avatars/1444c8a86dbbe7a6f5f89a8135e770824d7b22bc', |
126 | 489 | 'https://twitter.com/some_guy/status/322807141108944896', | 483 | 'https://twitter.com/therealrobru/status/324220250889543682', |
127 | 490 | 0, False, '', '', '', '', '', '', '', 0.0, 0.0, | 484 | 0, False, '', '', '', '', '', '', '', 0.0, 0.0, |
128 | 491 | ] | 485 | ] |
129 | 492 | self.assertEqual(list(TestModel.get_row(0)), expected_row) | 486 | self.assertEqual(list(TestModel.get_row(0)), expected_row) |
PASSED: Continuous integration, rev:193 jenkins. qa.ubuntu. com/job/ friends- ci/38/ jenkins. qa.ubuntu. com/job/ friends- raring- amd64-ci/ 38
http://
Executed test runs:
SUCCESS: http://
Click here to trigger a rebuild: s-jenkins: 8080/job/ friends- ci/38/rebuild
http://