Merge lp:~robru/gwibber/publish-fixup-real into lp:~barry/gwibber/py3

Proposed by Robert Bruce Park
Status: Merged
Merged at revision: 1440
Proposed branch: lp:~robru/gwibber/publish-fixup-real
Merge into: lp:~barry/gwibber/py3
Diff against target: 189 lines (+21/-27)
4 files modified
gwibber/gwibber/protocols/flickr.py (+0/-1)
gwibber/gwibber/protocols/foursquare.py (+0/-1)
gwibber/gwibber/tests/test_protocols.py (+14/-19)
gwibber/gwibber/utils/base.py (+7/-6)
To merge this branch: bzr merge lp:~robru/gwibber/publish-fixup-real
Reviewer Review Type Date Requested Status
Barry Warsaw Pending
Review via email: mp+125820@code.launchpad.net

Description of the change

Simplifies Base._publish, introspecting the account id from self, so that all our subclass methods no longer need to specify it manually. Now the only required kwarg is message_id.

To post a comment you must log in.
lp:~robru/gwibber/publish-fixup-real updated
1440. By Robert Bruce Park

Update Flickr to the same great new _publish stuff.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'gwibber/gwibber/protocols/flickr.py'
2--- gwibber/gwibber/protocols/flickr.py 2012-09-21 21:45:06 +0000
3+++ gwibber/gwibber/protocols/flickr.py 2012-09-21 21:53:20 +0000
4@@ -138,7 +138,6 @@
5 nsid=owner, secret=secret,
6 type='t')
7 self._publish(
8- account_id=self._account.id,
9 message_id=data.get('id', ''),
10 stream='images',
11 sender=owner,
12
13=== modified file 'gwibber/gwibber/protocols/foursquare.py'
14--- gwibber/gwibber/protocols/foursquare.py 2012-09-21 18:03:01 +0000
15+++ gwibber/gwibber/protocols/foursquare.py 2012-09-21 21:53:20 +0000
16@@ -107,7 +107,6 @@
17 tz_offset = checkin.get('timeZoneOffset', 0)
18 epoch = checkin.get('createdAt')
19 self._publish(
20- account_id=self._account.id,
21 message_id=checkin_id,
22 stream='messages',
23 sender=_full_name(user),
24
25=== modified file 'gwibber/gwibber/tests/test_protocols.py'
26--- gwibber/gwibber/tests/test_protocols.py 2012-09-21 16:40:41 +0000
27+++ gwibber/gwibber/tests/test_protocols.py 2012-09-21 21:53:20 +0000
28@@ -136,29 +136,29 @@
29 def test_shared_model_successfully_mocked(self):
30 self.assertEqual(Model.get_n_rows(), 0)
31 self.assertEqual(TestModel.get_n_rows(), 0)
32- base = Base(None)
33- base._publish('a', 'b', message='a')
34- base._publish('a', 'b', message='b')
35- base._publish('a', 'b', message='c')
36+ base = Base(FakeAccount())
37+ base._publish('alpha', message='a')
38+ base._publish('beta', message='b')
39+ base._publish('omega', message='c')
40 self.assertEqual(Model.get_n_rows(), 0)
41 self.assertEqual(TestModel.get_n_rows(), 3)
42
43 @mock.patch('gwibber.utils.base.Model', TestModel)
44 def test_invalid_argument(self):
45- base = Base(None)
46+ base = Base(FakeAccount())
47 self.assertEqual(0, TestModel.get_n_rows())
48 with self.assertRaises(TypeError) as cm:
49- base._publish('x', 'y', invalid_argument='not good')
50+ base._publish('message_id', invalid_argument='not good')
51 self.assertEqual(str(cm.exception),
52 'Unexpected keyword arguments: invalid_argument')
53
54 @mock.patch('gwibber.utils.base.Model', TestModel)
55 def test_invalid_arguments(self):
56 # All invalid arguments are mentioned in the exception message.
57- base = Base(None)
58+ base = Base(FakeAccount())
59 self.assertEqual(0, TestModel.get_n_rows())
60 with self.assertRaises(TypeError) as cm:
61- base._publish('x', 'y', bad='no', wrong='yes')
62+ base._publish('p.middy', bad='no', wrong='yes')
63 self.assertEqual(str(cm.exception),
64 'Unexpected keyword arguments: bad, wrong')
65
66@@ -166,10 +166,9 @@
67 @mock.patch('gwibber.utils.base._seen_messages', {})
68 def test_one_message(self):
69 # Test that publishing a message inserts a row into the model.
70- base = Base(None)
71+ base = Base(FakeAccount())
72 self.assertEqual(0, TestModel.get_n_rows())
73 self.assertTrue(base._publish(
74- account_id='1/facebook',
75 message_id='1234',
76 stream='messages',
77 sender='fred',
78@@ -185,7 +184,7 @@
79 def V(column_name):
80 return row[COLUMN_INDICES[column_name]]
81 self.assertEqual(V('message_ids'),
82- [['base', '1/facebook', '1234']])
83+ [['base', 'faker/than fake', '1234']])
84 self.assertEqual(V('stream'), 'messages')
85 self.assertEqual(V('sender'), 'fred')
86 self.assertEqual(V('sender_nick'), 'freddy')
87@@ -209,12 +208,11 @@
88 # _make_key() test in base.py, are published, only one ends up in the
89 # model. However, the message_ids list-of-lists gets both sets of
90 # identifiers.
91- base = Base(None)
92+ base = Base(FakeAccount())
93 self.assertEqual(0, TestModel.get_n_rows())
94 # Insert the first message into the table. The key will be the string
95 # 'fredhellojimmy'
96 self.assertTrue(base._publish(
97- account_id='1/facebook',
98 message_id='1234',
99 stream='messages',
100 sender='fred',
101@@ -228,7 +226,6 @@
102 # punctuation was stripped from the above message, this one will also
103 # have the key 'fredhellojimmy', thus it will be deemed a duplicate.
104 self.assertTrue(base._publish(
105- account_id='2/twitter',
106 message_id='5678',
107 stream='messages',
108 sender='fred',
109@@ -245,8 +242,8 @@
110 self.assertEqual(row[COLUMN_INDICES['message']], 'hello, @jimmy')
111 # Both message ids will be present, in the order they were published.
112 self.assertEqual(row[COLUMN_INDICES['message_ids']],
113- [['base', '1/facebook', '1234'],
114- ['base', '2/twitter', '5678']])
115+ [['base', 'faker/than fake', '1234'],
116+ ['base', 'faker/than fake', '5678']])
117
118 @mock.patch('gwibber.utils.base.Model', TestModel)
119 @mock.patch('gwibber.utils.base._seen_messages', {})
120@@ -254,11 +251,10 @@
121 # Because both the sender and message contribute to the unique key we
122 # use to identify messages, if two messages are published with
123 # different senders, both are inserted into the table.
124- base = Base(None)
125+ base = Base(FakeAccount())
126 self.assertEqual(0, TestModel.get_n_rows())
127 # The key for this row is 'fredhellojimmy'
128 self.assertTrue(base._publish(
129- account_id='1/facebook',
130 message_id='1234',
131 stream='messages',
132 sender='fred',
133@@ -271,7 +267,6 @@
134 self.assertEqual(1, TestModel.get_n_rows())
135 # The key for this row is 'tedtholomewhellojimmy'
136 self.assertTrue(base._publish(
137- account_id='1/facebook',
138 message_id='34567',
139 stream='messages',
140 sender='tedtholomew',
141
142=== modified file 'gwibber/gwibber/utils/base.py'
143--- gwibber/gwibber/utils/base.py 2012-09-21 18:03:01 +0000
144+++ gwibber/gwibber/utils/base.py 2012-09-21 21:53:20 +0000
145@@ -36,15 +36,18 @@
146 MESSAGE_IDX = COLUMN_INDICES['message']
147 IDS_IDX = COLUMN_INDICES['message_ids']
148
149+
150 # This is a mapping from Dee.SharedModel row keys to the DeeModelIters
151 # representing the rows matching those keys. It is used for quickly finding
152 # duplicates when we want to insert new rows into the model.
153 _seen_messages = {}
154
155+
156 # Protocol __call__() methods run in threads, so we need to serialize
157 # publishing new data into the SharedModel.
158 _publish_lock = threading.Lock()
159
160+
161 log = logging.getLogger('gwibber.service')
162
163
164@@ -138,13 +141,9 @@
165 if barrier is not None:
166 barrier.wait()
167
168- def _publish(self, account_id, message_id, **kwargs):
169+ def _publish(self, message_id, **kwargs):
170 """Publish fresh data into the model, ignoring duplicates.
171
172- :param account_id: The libaccounts id representing the account this
173- message is published from. Serves as the second component of the
174- unique 'message_ids' column.
175- :type account_id: string
176 :param message_id: The service-specific id of the message being
177 published. Serves as the third component of the unique
178 'message_ids' column.
179@@ -161,7 +160,9 @@
180 # The column value is a list of lists (see gwibber/utils/model.py for
181 # details), and because the arguments are themselves a list, this gets
182 # initialized as a triply-nested list.
183- args = [[[self.__class__.__name__.lower(), account_id, message_id]]]
184+ args = [[[self.__class__.__name__.lower(),
185+ self._account.id,
186+ message_id]]]
187 # Now iterate through all the column names listed in the SCHEMA,
188 # except for the first, since we just composed its value in the
189 # preceding line. Pop matching column values from the kwargs, in the

Subscribers

People subscribed via source and target branches