Exemplo n.º 1
0
    def test_send_to_my_friends_wall(self, dload):
        dload().get_json.return_value = dict(id='post_id')
        token = self.protocol._get_access_token = mock.Mock(
            return_value='face')
        publish = self.protocol._publish_entry = mock.Mock(
            return_value='http://facebook.com/new_post_id')

        self.assertEqual(
            self.protocol.send('I can see the writing on my friend\'s wall.',
                               'friend_id'),
            'http://facebook.com/new_post_id')

        token.assert_called_once_with()
        publish.assert_called_with(entry={'id': 'post_id'},
                                   stream='messages')
        self.assertEqual(
            dload.mock_calls,
            [mock.call(),
             mock.call(
                    'https://graph.facebook.com/friend_id/feed',
                    method='POST',
                    params=dict(
                       access_token='face',
                       message='I can see the writing on my friend\'s wall.')),
             mock.call().get_json(),
             mock.call('https://graph.facebook.com/post_id',
                       params=dict(access_token='face')),
             mock.call().get_json(),
             ])
Exemplo n.º 2
0
    def test_send_thread(self, dload):
        dload().get_json.return_value = dict(id='comment_id')
        token = self.protocol._get_access_token = mock.Mock(
            return_value='face')
        publish = self.protocol._publish_entry = mock.Mock(
            return_value='http://facebook.com/private_message_id')

        self.assertEqual(
            self.protocol.send_thread('post_id', 'Some witty response!'),
            'http://facebook.com/private_message_id')

        token.assert_called_once_with()
        publish.assert_called_with(entry={'id': 'comment_id'},
                                   stream='reply_to/post_id')
        self.assertEqual(
            dload.mock_calls,
            [mock.call(),
             mock.call(
                    'https://graph.facebook.com/post_id/comments',
                    method='POST',
                    params=dict(
                        access_token='face',
                        message='Some witty response!')),
             mock.call().get_json(),
             mock.call('https://graph.facebook.com/comment_id',
                       params=dict(access_token='face')),
             mock.call().get_json(),
             ])
Exemplo n.º 3
0
    def test_private(self):
        get_url = self.protocol._get_url = mock.Mock(return_value=['tweet'])
        publish = self.protocol._publish_tweet = mock.Mock()

        self.protocol.private()

        publish.assert_called_with('tweet', stream='private')
        self.assertEqual(
            get_url.mock_calls,
            [mock.call('http://identi.ca/api/direct_messages.json?count=50'),
             mock.call('http://identi.ca/api/direct_messages' +
                       '/sent.json?count=50')])
Exemplo n.º 4
0
 def test_contacts(self, *mocks):
     push = self.protocol._push_to_eds = mock.Mock()
     prev = self.protocol._previously_stored_contact = mock.Mock(
         return_value=False)
     token = self.protocol._get_access_token = mock.Mock(return_value='foo')
     self.protocol._create_contact = lambda arg: arg
     self.assertEqual(self.protocol.contacts(), 4)
     self.assertEqual(push.mock_calls, [
         mock.call(link='https://www.linkedin.com', name='H A', uid='IFDI'),
         mock.call(link='https://www.linkedin.com', name='C A', uid='AefF'),
         mock.call(link='https://www.linkedin.com', name='R A', uid='DFdV'),
         mock.call(link='https://www.linkedin.com', name='A Z', uid='xkBU')
     ])
Exemplo n.º 5
0
 def test_contacts(self):
     get = self.protocol._get_url = mock.Mock(
         return_value=dict(ids=[1, 2], name='Bob', screen_name='bobby'))
     prev = self.protocol._previously_stored_contact = mock.Mock(
         return_value=False)
     push = self.protocol._push_to_eds = mock.Mock()
     self.assertEqual(self.protocol.contacts(), 2)
     self.assertEqual(get.call_args_list, [
         mock.call('https://api.twitter.com/1.1/friends/ids.json'),
         mock.call(
             url='https://api.twitter.com/1.1/users/show.json?user_id=1'),
         mock.call(
             url='https://api.twitter.com/1.1/users/show.json?user_id=2')
     ])
     self.assertEqual(prev.call_args_list, [mock.call('1'), mock.call('2')])
     self.assertEqual(push.call_args_list, [
         mock.call(link='https://twitter.com/bobby',
                   uid='1',
                   name='Bob',
                   nick='bobby'),
         mock.call(link='https://twitter.com/bobby',
                   uid='2',
                   name='Bob',
                   nick='bobby')
     ])
Exemplo n.º 6
0
 def test_contacts(self, downloader):
     downloader().get_json.return_value = dict(
         name='Joe Blow', username='******', link='example.com', gender='male')
     downloader.reset_mock()
     self.protocol._get_access_token = mock.Mock(return_value='broken')
     follow = self.protocol._follow_pagination = mock.Mock(
         return_value=[dict(id='contact1'), dict(id='contact2')])
     prev = self.protocol._previously_stored_contact = mock.Mock(return_value=False)
     push = self.protocol._push_to_eds = mock.Mock()
     self.assertEqual(self.protocol.contacts(), 2)
     follow.assert_called_once_with(
         params={'access_token': 'broken', 'limit': 1000},
         url='https://graph.facebook.com/me/friends',
         limit=1000)
     self.assertEqual(
         prev.call_args_list,
         [mock.call('contact1'), mock.call('contact2')])
     self.assertEqual(
         downloader.call_args_list,
         [mock.call(url='https://graph.facebook.com/contact1',
                    params={'access_token': 'broken'}),
          mock.call(url='https://graph.facebook.com/contact2',
                    params={'access_token': 'broken'})])
     self.assertEqual(
         push.call_args_list,
         [mock.call(gender='male', jabber='*****@*****.**',
                    nick='jblow', link='example.com', name='Joe Blow',
                    uid='contact1'),
          mock.call(gender='male', jabber='*****@*****.**',
                    nick='jblow', link='example.com', name='Joe Blow',
                    uid='contact2')])
Exemplo n.º 7
0
    def test_send_thread(self, dload):
        dload().get_json.return_value = dict(id='comment_id')
        token = self.protocol._get_access_token = mock.Mock(return_value='abc')
        publish = self.protocol._publish_entry = mock.Mock(
            return_value='http://instagram.com/p/post_id')

        self.assertEqual(
            self.protocol.send_thread('post_id', 'Some witty response!'),
            'http://instagram.com/p/post_id')
        token.assert_called_once_with()
        publish.assert_called_with(entry={'id': 'comment_id'},
                                   stream='reply_to/post_id')
        self.assertEqual(dload.mock_calls, [
            mock.call(),
            mock.call(
                'https://api.instagram.com/v1/media/post_id/comments?access_token=abc',
                method='POST',
                params=dict(access_token='abc', text='Some witty response!')),
            mock.call().get_json(),
            mock.call(
                'https://api.instagram.com/v1/media/post_id/comments?access_token=abc',
                params=dict(access_token='abc')),
            mock.call().get_json(),
        ])
Exemplo n.º 8
0
    def test_private_avatars(self):
        get_url = self.protocol._get_url = mock.Mock(return_value=[
            dict(
                created_at='Sun Nov 04 17:14:52 2012',
                text='Does my avatar show up?',
                id_str='1452456',
                sender=dict(
                    screen_name='some_guy',
                    name='Bob',
                    profile_image_url_https='https://example.com/bob.jpg',
                ),
            )
        ])
        publish = self.protocol._publish = mock.Mock()

        self.protocol.private()

        publish.assert_called_with(
            liked=False,
            sender='Bob',
            stream='private',
            url='https://twitter.com/some_guy/status/1452456',
            icon_uri='https://example.com/bob.jpg',
            link_picture='',
            sender_nick='some_guy',
            sender_id='',
            from_me=False,
            timestamp='2012-11-04T17:14:52Z',
            message='Does my avatar show up?',
            message_id='1452456')
        self.assertEqual(get_url.mock_calls, [
            mock.call('https://api.twitter.com/1.1/' +
                      'direct_messages.json?count=50'),
            mock.call('https://api.twitter.com/1.1/' +
                      'direct_messages/sent.json?count=50&since_id=1452456')
        ])