501
501
params={'access_token': 'broken'})])
502
502
self.assertEqual(
503
503
push.call_args_list,
505
'X-FOLKS-WEB-SERVICES-IDS': {
506
'jabber': '-contact1@chat.facebook.com',
507
'facebook-id': 'contact1',
508
'remote-full-name': 'Joe Blow'},
510
'facebook-name': 'Joe Blow',
511
'facebook-id': 'contact1',
512
'X-URIS': 'example.com',
513
'facebook-nick': 'jblow'}),
515
'X-FOLKS-WEB-SERVICES-IDS': {
516
'jabber': '-contact2@chat.facebook.com',
517
'facebook-id': 'contact2',
518
'remote-full-name': 'Joe Blow'},
520
'facebook-name': 'Joe Blow',
521
'facebook-id': 'contact2',
522
'X-URIS': 'example.com',
523
'facebook-nick': 'jblow'})])
504
[mock.call(gender='male', jabber='-contact1@chat.facebook.com',
505
nick='jblow', link='example.com', name='Joe Blow',
507
mock.call(gender='male', jabber='-contact2@chat.facebook.com',
508
nick='jblow', link='example.com', name='Joe Blow',
525
511
def test_create_contact(self, *mocks):
526
512
# Receive the users friends.
528
'facebook-id': '555555555',
529
'facebook-name': 'Lucy Baron',
530
'facebook-nick': 'lucy.baron5',
531
'X-URIS': 'http:www.facebook.com/lucy.baron5',
532
'X-GENDER': 'female',
533
'X-FOLKS-WEB-SERVICES-IDS': {
534
'jabber': '-555555555@chat.facebook.com',
535
'remote-full-name': 'Lucy Baron',
536
'facebook-id': '555555555',
538
eds_contact = self.protocol._create_contact(bare_contact)
513
eds_contact = self.protocol._create_contact(
518
link='http:www.facebook.com/lucy.baron5',
519
jabber='-555555555@chat.facebook.com')
539
520
facebook_id_attr = eds_contact.get_attribute('facebook-id')
540
521
self.assertEqual(facebook_id_attr.get_value(), '555555555')
541
facebook_name_attr = eds_contact.get_attribute('facebook-name')
542
self.assertEqual(facebook_name_attr.get_value(), 'Lucy Baron')
543
522
web_service_addrs = eds_contact.get_attribute('X-FOLKS-WEB-SERVICES-IDS')
544
523
params= web_service_addrs.get_params()
546
self.assertEqual(len(params), 3)
549
test_remote_name = False
550
test_facebook_id = False
553
if p.get_name() == 'jabber':
554
self.assertEqual(len(p.get_values()), 1)
555
self.assertEqual(p.get_values()[0], '-555555555@chat.facebook.com')
557
if p.get_name() == 'remote-full-name':
558
self.assertEqual(len(p.get_values()), 1)
559
self.assertEqual(p.get_values()[0], 'Lucy Baron')
560
test_remote_name = True
561
if p.get_name() == 'facebook-id':
562
self.assertEqual(len(p.get_values()), 1)
563
self.assertEqual(p.get_values()[0], '555555555')
564
test_facebook_id = True
565
# Finally test to ensure all key value pairs were tested
566
self.assertTrue(test_jabber and test_remote_name and test_facebook_id)
524
self.assertEqual(len(params), 5)
526
# Can't compare the vcard string directly because it is sorted randomly...
527
vcard = eds_contact.to_string(
528
EBookContacts.VCardFormat(1)).replace('\r\n ', '')
530
'social-networking-attributes.X-URIS:http:www.facebook.com/lucy.baron5',
533
'social-networking-attributes.X-GENDER:female',
536
'social-networking-attributes.facebook-id:555555555',
542
'NICKNAME:lucy.baron5',
545
'social-networking-attributes.X-FOLKS-WEB-SERVICES-IDS;',
548
'remote-full-name="Lucy Baron"',
551
'facebook-id=555555555',
554
'jabber="-555555555@chat.facebook.com"',
557
'facebook-nick="lucy.baron5"',
568
560
@mock.patch('friends.utils.base.Base._prepare_eds_connections',
569
561
return_value=True)
571
563
return_value=EDSBookClientMock())
572
564
def test_successfull_push_to_eds(self, *mocks):
573
565
bare_contact = {'name': 'Lucy Baron',
575
'username': 'lucy.baron5',
567
'nick': 'lucy.baron5',
576
568
'link': 'http:www.facebook.com/lucy.baron5'}
577
569
self.protocol._address_book = 'test-address-book'
578
570
client = self.protocol._book_client = mock.Mock()
579
571
client.add_contact_sync.return_value = True
580
572
# Implicitely fail test if the following raises any exceptions
581
self.protocol._push_to_eds(bare_contact)
573
self.protocol._push_to_eds(**bare_contact)
583
575
@mock.patch('friends.utils.base.Base._prepare_eds_connections',
584
576
return_value=None)
585
577
def test_unsuccessfull_push_to_eds(self, *mocks):
586
578
bare_contact = {'name': 'Lucy Baron',
588
'username': 'lucy.baron5',
580
'nick': 'lucy.baron5',
589
581
'link': 'http:www.facebook.com/lucy.baron5'}
590
582
self.protocol._address_book = 'test-address-book'
591
583
client = self.protocol._book_client = mock.Mock()