Merge lp:~robru/gwibber/twitter-from-me-fix into lp:~barry/gwibber/py3

Proposed by Robert Bruce Park
Status: Merged
Merged at revision: 1450
Proposed branch: lp:~robru/gwibber/twitter-from-me-fix
Merge into: lp:~barry/gwibber/py3
Diff against target: 163 lines (+122/-1)
3 files modified
gwibber/gwibber/protocols/twitter.py (+1/-1)
gwibber/gwibber/tests/data/twitter-send.dat (+87/-0)
gwibber/gwibber/tests/test_twitter.py (+34/-0)
To merge this branch: bzr merge lp:~robru/gwibber/twitter-from-me-fix
Reviewer Review Type Date Requested Status
Barry Warsaw Pending
Review via email: mp+128834@code.launchpad.net

Description of the change

Minor bugfix for Twitter. I'm surprised neither of us noticed this ;-)

To post a comment you must log in.
Revision history for this message
Barry Warsaw (barry) wrote :

On Oct 09, 2012, at 10:45 PM, Robert Bruce Park wrote:

>Robert Bruce Park has proposed merging lp:~robru/gwibber/twitter-from-me-fix into lp:~barry/gwibber/py3.
>
>Requested reviews:
> Barry Warsaw (barry)
>
>For more details, see:
>https://code.launchpad.net/~robru/gwibber/twitter-from-me-fix/+merge/128834
>
>Minor bugfix for Twitter. I'm surprised neither of us noticed this ;-)

Any chance you can write a test case for this? The test should fail without
the fix and pass after the fix. Feel free to use FakeData <wink>.

1450. By Robert Bruce Park

Add a test for that id/name mixup.

Revision history for this message
Robert Bruce Park (robru) wrote :

Alright barry, I added a test that does indeed fail if the original commit is reverted.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'gwibber/gwibber/protocols/twitter.py'
2--- gwibber/gwibber/protocols/twitter.py 2012-10-09 19:56:07 +0000
3+++ gwibber/gwibber/protocols/twitter.py 2012-10-10 17:00:27 +0000
4@@ -113,7 +113,7 @@
5 stream='messages',
6 sender=user.get('name', ''),
7 sender_nick=screen_name,
8- from_me=(screen_name == self._account.user_id),
9+ from_me=(screen_name == self._account.user_name),
10 icon_uri=user.get('profile_image_url_https', ''),
11 liked=tweet.get('favorited', False),
12 url=self._tweet_permalink.format(user_id=screen_name,
13
14=== added file 'gwibber/gwibber/tests/data/twitter-send.dat'
15--- gwibber/gwibber/tests/data/twitter-send.dat 1970-01-01 00:00:00 +0000
16+++ gwibber/gwibber/tests/data/twitter-send.dat 2012-10-10 17:00:27 +0000
17@@ -0,0 +1,87 @@
18+ {
19+ "coordinates": null,
20+ "truncated": false,
21+ "created_at": "Tue Aug 28 21:16:23 +0000 2012",
22+ "favorited": false,
23+ "id_str": "240558470661799936",
24+ "in_reply_to_user_id_str": null,
25+ "entities": {
26+ "urls": [
27+
28+ ],
29+ "hashtags": [
30+
31+ ],
32+ "user_mentions": [
33+
34+ ]
35+ },
36+ "text": "just another test",
37+ "contributors": null,
38+ "id": 240558470661799936,
39+ "retweet_count": 0,
40+ "in_reply_to_status_id_str": null,
41+ "geo": null,
42+ "retweeted": false,
43+ "in_reply_to_user_id": null,
44+ "place": null,
45+ "source": "<a href=\"http://realitytechnicians.com\" rel=\"nofollow\">OAuth Dancer Reborn</a>",
46+ "user": {
47+ "name": "OAuth Dancer",
48+ "profile_sidebar_fill_color": "DDEEF6",
49+ "profile_background_tile": true,
50+ "profile_sidebar_border_color": "C0DEED",
51+ "profile_image_url": "http://a0.twimg.com/profile_images/730275945/oauth-dancer_normal.jpg",
52+ "created_at": "Wed Mar 03 19:37:35 +0000 2010",
53+ "location": "San Francisco, CA",
54+ "follow_request_sent": false,
55+ "id_str": "119476949",
56+ "is_translator": false,
57+ "profile_link_color": "0084B4",
58+ "entities": {
59+ "url": {
60+ "urls": [
61+ {
62+ "expanded_url": null,
63+ "url": "http://bit.ly/oauth-dancer",
64+ "indices": [
65+ 0,
66+ 26
67+ ],
68+ "display_url": null
69+ }
70+ ]
71+ },
72+ "description": null
73+ },
74+ "default_profile": false,
75+ "url": "http://bit.ly/oauth-dancer",
76+ "contributors_enabled": false,
77+ "favourites_count": 7,
78+ "utc_offset": null,
79+ "profile_image_url_https": "https://si0.twimg.com/profile_images/730275945/oauth-dancer_normal.jpg",
80+ "id": 119476949,
81+ "listed_count": 1,
82+ "profile_use_background_image": true,
83+ "profile_text_color": "333333",
84+ "followers_count": 28,
85+ "lang": "en",
86+ "protected": false,
87+ "geo_enabled": true,
88+ "notifications": false,
89+ "description": "",
90+ "profile_background_color": "C0DEED",
91+ "verified": false,
92+ "time_zone": null,
93+ "profile_background_image_url_https": "https://si0.twimg.com/profile_background_images/80151733/oauth-dance.png",
94+ "statuses_count": 166,
95+ "profile_background_image_url": "http://a0.twimg.com/profile_background_images/80151733/oauth-dance.png",
96+ "default_profile_image": false,
97+ "friends_count": 14,
98+ "following": false,
99+ "show_all_inline_media": false,
100+ "screen_name": "oauth_dancer"
101+ },
102+ "in_reply_to_screen_name": null,
103+ "in_reply_to_status_id": null
104+ }
105
106=== modified file 'gwibber/gwibber/tests/test_twitter.py'
107--- gwibber/gwibber/tests/test_twitter.py 2012-10-05 01:23:56 +0000
108+++ gwibber/gwibber/tests/test_twitter.py 2012-10-10 17:00:27 +0000
109@@ -48,6 +48,7 @@
110 """Test the Twitter API."""
111
112 def setUp(self):
113+ TestModel.clear()
114 self.account = FakeAccount()
115 self.protocol = Twitter(self.account)
116 self.log_mock = LogMock('gwibber.utils.base',
117@@ -110,6 +111,8 @@
118 FakeData('gwibber.tests.data', 'twitter-home.dat'))
119 @mock.patch('gwibber.protocols.twitter.Twitter._login',
120 return_value=True)
121+ @mock.patch('gwibber.utils.base._seen_messages', {})
122+ @mock.patch('gwibber.utils.base._seen_ids', {})
123 def test_home(self, *mocks):
124 self.account.access_token = 'access'
125 self.account.secret_token = 'secret'
126@@ -152,6 +155,37 @@
127 for got, want in zip(TestModel.get_row(i), expected_row):
128 self.assertEqual(got, want)
129
130+ @mock.patch('gwibber.utils.base.Model', TestModel)
131+ @mock.patch('gwibber.utils.download.urlopen',
132+ FakeData('gwibber.tests.data', 'twitter-send.dat'))
133+ @mock.patch('gwibber.protocols.twitter.Twitter._login',
134+ return_value=True)
135+ @mock.patch('gwibber.utils.base._seen_messages', {})
136+ @mock.patch('gwibber.utils.base._seen_ids', {})
137+ def test_from_me(self, *mocks):
138+ self.account.access_token = 'access'
139+ self.account.secret_token = 'secret'
140+ self.account.user_name = 'oauth_dancer'
141+ self.account.auth.parameters = dict(
142+ ConsumerKey='key',
143+ ConsumerSecret='secret')
144+ self.assertEqual(0, TestModel.get_n_rows())
145+ self.protocol.send('some message')
146+ self.assertEqual(1, TestModel.get_n_rows())
147+
148+ # This test data was ripped directly from Twitter's API docs.
149+ expected_row = [
150+ [['twitter', 'faker/than fake', '240558470661799936']],
151+ 'messages', 'OAuth Dancer', 'oauth_dancer', True,
152+ '2012-08-28T21:16:23', 'just another test', '',
153+ 'https://si0.twimg.com/profile_images/730275945/oauth-dancer_normal.jpg',
154+ 'https://twitter.com/oauth_dancer/status/240558470661799936', '',
155+ '', '', '', 0.0, False, '', '', '', '', '', '', '', '', '', '',
156+ '', '', '', '', '', '', '', '', '', '', '',
157+ ]
158+ for got, want in zip(TestModel.get_row(0), expected_row):
159+ self.assertEqual(got, want)
160+
161 def test_mentions(self):
162 get_url = self.protocol._get_url = mock.Mock(return_value=['tweet'])
163 publish = self.protocol._publish_tweet = mock.Mock()

Subscribers

People subscribed via source and target branches