~ubuntu-branches/ubuntu/saucy/friends/saucy-proposed

« back to all changes in this revision

Viewing changes to friends/tests/test_identica.py

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Robert Bruce Park, Ubuntu daily release
  • Date: 2013-07-23 06:25:26 UTC
  • mfrom: (1.1.25)
  • Revision ID: package-import@ubuntu.com-20130723062526-55u1pi8mh35e23me
Tags: 0.2.0+13.10.20130723-0ubuntu1
[ Robert Bruce Park ]
* Vast simplification of contact logic.

[ Ubuntu daily release ]
* Automatic snapshot from revision 225

Show diffs side-by-side

added added

removed removed

Lines of Context:
221
221
        get_url.assert_called_with(
222
222
            'http://identi.ca/api/search.json?q=hello')
223
223
 
224
 
    def test_getfriendsids(self):
225
 
        get_url = self.protocol._get_url = mock.Mock(return_value=[1,2,3])
226
 
        ids = self.protocol._getfriendsids()
227
 
 
228
 
        get_url.assert_called_with(
229
 
            'http://identi.ca/api/friends/ids.json'
230
 
            )
231
 
        self.assertEqual(ids, [1,2,3])
232
 
 
233
 
    def test_showuser(self):
234
 
        get_url = self.protocol._get_url = mock.Mock(return_value={"name":"Alice"})
235
 
        userdata = self.protocol._showuser(1)
236
 
 
237
 
        get_url.assert_called_with(
238
 
            'http://identi.ca/api/users/show.json?user_id=1'
239
 
            )
240
 
        self.assertEqual(userdata, {"name":"Alice"})
241
 
 
242
224
    def test_like(self):
243
225
        get_url = self.protocol._get_url = mock.Mock()
244
226
        inc_cell = self.protocol._inc_cell = mock.Mock()
265
247
            'http://identi.ca/api/favorites/destroy/1234.json',
266
248
            dict(id='1234'))
267
249
 
268
 
    def test_create_contact(self, *mocks):
269
 
        # Receive the users friends.
270
 
        bare_contact = {'name': 'Alice Bob',
271
 
                        'screen_name': 'alice_bob',
272
 
                        'id': 13579}
273
 
 
274
 
        eds_contact = self.protocol._create_contact(bare_contact)
275
 
        twitter_id_attr = eds_contact.get_attribute('twitter-id')
276
 
        self.assertEqual(twitter_id_attr.get_value(), '13579')
277
 
        twitter_name_attr = eds_contact.get_attribute('twitter-name')
278
 
        self.assertEqual(twitter_name_attr.get_value(), 'Alice Bob')
279
 
        web_service_addrs = eds_contact.get_attribute('X-FOLKS-WEB-SERVICES-IDS')
280
 
        params= web_service_addrs.get_params()
281
 
        self.assertEqual(len(params), 2)
282
 
 
283
 
        test_remote_name = False
284
 
        test_twitter_id = False
285
 
 
286
 
        for p in params:
287
 
            if p.get_name() == 'remote-full-name':
288
 
                self.assertEqual(len(p.get_values()), 1)
289
 
                self.assertEqual(p.get_values()[0], 'Alice Bob')
290
 
                test_remote_name = True
291
 
            if p.get_name() == 'twitter-id':
292
 
                self.assertEqual(len(p.get_values()), 1)
293
 
                self.assertEqual(p.get_values()[0], '13579')
294
 
                test_twitter_id = True
295
 
 
296
 
        self.assertTrue(test_remote_name and test_twitter_id)
 
250
    def test_contacts(self):
 
251
        get = self.protocol._get_url = mock.Mock(
 
252
            return_value=dict(ids=[1,2],name='Bob',screen_name='bobby'))
 
253
        prev = self.protocol._previously_stored_contact = mock.Mock(return_value=False)
 
254
        push = self.protocol._push_to_eds = mock.Mock()
 
255
        self.assertEqual(self.protocol.contacts(), 2)
 
256
        self.assertEqual(
 
257
            get.call_args_list,
 
258
            [mock.call('http://identi.ca/api/friends/ids.json'),
 
259
             mock.call(url='http://identi.ca/api/users/show.json?user_id=1'),
 
260
             mock.call(url='http://identi.ca/api/users/show.json?user_id=2')])
 
261
        self.assertEqual(
 
262
            prev.call_args_list,
 
263
            [mock.call('1'), mock.call('2')])
 
264
        self.assertEqual(
 
265
            push.call_args_list,
 
266
            [mock.call({'identica-id': '1',
 
267
                        'X-FOLKS-WEB-SERVICES-IDS': {
 
268
                            'identica-id': '1',
 
269
                            'remote-full-name': 'Bob'},
 
270
                        'X-URIS': 'https://identi.ca/bobby',
 
271
                        'identica-name': 'Bob',
 
272
                        'identica-nick': 'bobby'}),
 
273
             mock.call({'identica-id': '2',
 
274
                        'X-FOLKS-WEB-SERVICES-IDS': {
 
275
                            'identica-id': '2',
 
276
                            'remote-full-name': 'Bob'},
 
277
                        'X-URIS': 'https://identi.ca/bobby',
 
278
                        'identica-name': 'Bob',
 
279
                        'identica-nick': 'bobby'})])