Пример #1
0
    def test_upload_async(self):
        account = mock.Mock()
        self.dispatcher.accounts = mock.Mock()
        self.dispatcher.accounts.get.return_value = account

        success = mock.Mock()
        failure = mock.Mock()

        self.dispatcher.Upload('2',
                               'file://path/to/image.png',
                               'A thousand words',
                               success=success,
                               failure=failure)
        self.dispatcher.accounts.get.assert_called_once_with(2)
        account.protocol.assert_called_once_with(
            'upload',
            'file://path/to/image.png',
            'A thousand words',
            success=success,
            failure=failure,
        )

        self.assertEqual(
            self.log_mock.empty(), 'Clearing timer id: 42\n'
            'Uploading file://path/to/image.png to 2\n'
            'Starting new shutdown timer...\n')
Пример #2
0
    def test_send_thread_prepend_nick(self, *mocks):
        self.account.access_token = 'access'
        self.account.secret_token = 'secret'
        self.assertEqual(0, TestModel.get_n_rows())
        self.assertEqual(self.protocol.home(), 3)
        self.assertEqual(3, TestModel.get_n_rows())

        # If you forgot to @mention in your reply, we add it for you.
        get = self.protocol._get_url = mock.Mock()
        self.protocol._publish_tweet = mock.Mock()
        self.protocol.send_thread('240556426106372096',
                                  'Exciting and original response!')
        get.assert_called_once_with(
            'https://api.twitter.com/1.1/statuses/update.json',
            dict(status='@raffi Exciting and original response!',
                 in_reply_to_status_id='240556426106372096'))

        # If you remembered the @mention, we won't duplicate it.
        get.reset_mock()
        self.protocol.send_thread('240556426106372096',
                                  'You are the greatest, @raffi!')
        get.assert_called_once_with(
            'https://api.twitter.com/1.1/statuses/update.json',
            dict(status='You are the greatest, @raffi!',
                 in_reply_to_status_id='240556426106372096'))
Пример #3
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(),
             ])
Пример #4
0
    def test_upload(self, gfile):
        self.account.user_name = 'freddyjimbobjones'
        gfile.new_for_uri().load_contents.return_value = [True, 'data'.encode()]
        token = self.protocol._get_access_token = mock.Mock()
        publish = self.protocol._publish = mock.Mock()
        avatar = self.protocol._get_avatar = mock.Mock()
        avatar.return_value = '/path/to/cached/avatar'

        self.assertEqual(
            self.protocol.upload(
                'file:///path/to/some.jpg',
                'Beautiful photograph!'),
            'http://www.flickr.com/photos/freddyjimbobjones/8488552823')

        token.assert_called_with()
        publish.assert_called_with(
            message='Beautiful photograph!',
            timestamp='2013-02-19T16:53:13Z',
            stream='images',
            message_id='8488552823',
            from_me=True,
            sender=None,
            sender_nick='freddyjimbobjones',
            icon_uri='/path/to/cached/avatar',
            url='http://www.flickr.com/photos/freddyjimbobjones/8488552823',
            sender_id=None)
Пример #5
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(),
             ])
Пример #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')])
Пример #7
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')
     ])
Пример #8
0
    def test_mentions(self):
        get_url = self.protocol._get_url = mock.Mock(return_value=['tweet'])
        publish = self.protocol._publish_tweet = mock.Mock()

        self.assertEqual(self.protocol.mentions(), 0)

        publish.assert_called_with('tweet', stream='mentions')
        get_url.assert_called_with('https://api.twitter.com/1.1/statuses/' +
                                   'mentions_timeline.json?count=50')
Пример #9
0
    def test_home_url(self):
        get_url = self.protocol._get_url = mock.Mock(return_value=['tweet'])
        publish = self.protocol._publish_tweet = mock.Mock()

        self.assertEqual(self.protocol.home(), 0)

        publish.assert_called_with('tweet')
        get_url.assert_called_with(
            'https://api.twitter.com/1.1/statuses/home_timeline.json?count=50')
Пример #10
0
    def test_user(self):
        get_url = self.protocol._get_url = mock.Mock(return_value=['tweet'])
        publish = self.protocol._publish_tweet = mock.Mock()

        self.protocol.user()

        publish.assert_called_with('tweet', stream='messages')
        get_url.assert_called_with(
            'http://identi.ca/api/statuses/user_timeline.json?screen_name=')
Пример #11
0
    def test_mentions(self):
        get_url = self.protocol._get_url = mock.Mock(return_value=['tweet'])
        publish = self.protocol._publish_tweet = mock.Mock()

        self.protocol.mentions()

        publish.assert_called_with('tweet', stream='mentions')
        get_url.assert_called_with(
            'http://identi.ca/api/statuses/mentions.json?count=50')
Пример #12
0
    def test_delete(self):
        get_url = self.protocol._get_url = mock.Mock(return_value='tweet')
        publish = self.protocol._unpublish = mock.Mock()

        self.assertEqual(self.protocol.delete('1234'), '1234')

        publish.assert_called_with('1234')
        get_url.assert_called_with(
            'https://api.twitter.com/1.1/statuses/destroy/1234.json',
            dict(trim_user='******'))
Пример #13
0
    def test_send_private(self):
        get_url = self.protocol._get_url = mock.Mock(return_value='tweet')
        publish = self.protocol._publish_tweet = mock.Mock()

        self.protocol.send_private('pumpichank', 'Are you mocking me?')

        publish.assert_called_with('tweet', stream='private')
        get_url.assert_called_with(
            'http://identi.ca/api/direct_messages/new.json',
            dict(text='Are you mocking me?', screen_name='pumpichank'))
Пример #14
0
    def test_delete(self):
        get_url = self.protocol._get_url = mock.Mock(return_value='tweet')
        publish = self.protocol._unpublish = mock.Mock()

        self.protocol.delete('1234')

        publish.assert_called_with('1234')
        get_url.assert_called_with(
            'http://identi.ca/api/statuses/destroy/1234.json',
            dict(trim_user='******'))
Пример #15
0
    def test_list(self):
        get_url = self.protocol._get_url = mock.Mock(return_value=['tweet'])
        publish = self.protocol._publish_tweet = mock.Mock()

        self.assertEqual(self.protocol.list('some_list_id'), 0)

        publish.assert_called_with('tweet', stream='list/some_list_id')
        get_url.assert_called_with(
            'https://api.twitter.com/1.1/lists/statuses.json?list_id=some_list_id'
        )
Пример #16
0
    def test_user(self):
        get_url = self.protocol._get_url = mock.Mock(return_value=['tweet'])
        publish = self.protocol._publish_tweet = mock.Mock()

        self.assertEqual(self.protocol.user(), 0)

        publish.assert_called_with('tweet', stream='messages')
        get_url.assert_called_with(
            'https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name='
        )
Пример #17
0
    def test_search(self):
        get_url = self.protocol._get_url = mock.Mock(
            return_value=dict(results=['tweet']))
        publish = self.protocol._publish_tweet = mock.Mock()

        self.protocol.search('hello')

        publish.assert_called_with('tweet', stream='search/hello')
        get_url.assert_called_with(
            'http://identi.ca/api/search.json?q=hello')
Пример #18
0
    def test_lists(self):
        get_url = self.protocol._get_url = mock.Mock(
            return_value=[dict(id_str='twitlist')])
        publish = self.protocol.list = mock.Mock()

        self.assertEqual(self.protocol.lists(), 0)

        publish.assert_called_with('twitlist')
        get_url.assert_called_with(
            'https://api.twitter.com/1.1/lists/list.json')
Пример #19
0
    def test_send(self):
        get_url = self.protocol._get_url = mock.Mock(return_value='tweet')
        publish = self.protocol._publish_tweet = mock.Mock()

        self.protocol.send('Hello, twitterverse!')

        publish.assert_called_with('tweet')
        get_url.assert_called_with(
            'http://identi.ca/api/statuses/update.json',
            dict(status='Hello, twitterverse!'))
Пример #20
0
    def test_search(self):
        get_url = self.protocol._get_url = mock.Mock(return_value=dict(
            statuses=['tweet']))
        publish = self.protocol._publish_tweet = mock.Mock()

        self.assertEqual(self.protocol.search('hello'), 0)

        publish.assert_called_with('tweet', stream='search/hello')
        get_url.assert_called_with(
            'https://api.twitter.com/1.1/search/tweets.json?q=hello')
Пример #21
0
    def test_retweet(self):
        tweet=dict(tweet='twit')
        get_url = self.protocol._get_url = mock.Mock(return_value=tweet)
        publish = self.protocol._publish_tweet = mock.Mock()

        self.protocol.retweet('1234')

        publish.assert_called_with(tweet)
        get_url.assert_called_with(
            'http://identi.ca/api/statuses/retweet/1234.json',
            dict(trim_user='******'))
Пример #22
0
    def test_send(self):
        get_url = self.protocol._get_url = mock.Mock(return_value='tweet')
        publish = self.protocol._publish_tweet = mock.Mock(
            return_value='https://twitter.com/u/status/id')

        self.assertEqual(self.protocol.send('Hello, twitterverse!'),
                         'https://twitter.com/u/status/id')

        publish.assert_called_with('tweet')
        get_url.assert_called_with(
            'https://api.twitter.com/1.1/statuses/update.json',
            dict(status='Hello, twitterverse!'))
Пример #23
0
    def test_search(self):
        self.protocol._get_access_token = lambda: '12345'
        get_pages = self.protocol._follow_pagination = mock.Mock(
            return_value=['search results'])
        publish = self.protocol._publish_entry = mock.Mock()

        self.assertEqual(self.protocol.search('hello'), 1)

        publish.assert_called_with('search results', 'search/hello')
        get_pages.assert_called_with(
            'https://graph.facebook.com/search',
            dict(q='hello', access_token='12345'))
Пример #24
0
    def test_like(self):
        get_url = self.protocol._get_url = mock.Mock()
        inc_cell = self.protocol._inc_cell = mock.Mock()
        set_cell = self.protocol._set_cell = mock.Mock()

        self.assertEqual(self.protocol.like('1234'), '1234')

        inc_cell.assert_called_once_with('1234', 'likes')
        set_cell.assert_called_once_with('1234', 'liked', True)
        get_url.assert_called_with(
            'http://identi.ca/api/favorites/create/1234.json',
            dict(id='1234'))
Пример #25
0
    def test_retweet(self):
        tweet = dict(tweet='twit')
        get_url = self.protocol._get_url = mock.Mock(return_value=tweet)
        publish = self.protocol._publish_tweet = mock.Mock(
            return_value='tweet permalink')

        self.assertEqual(self.protocol.retweet('1234'), 'tweet permalink')

        publish.assert_called_with(tweet)
        get_url.assert_called_with(
            'https://api.twitter.com/1.1/statuses/retweet/1234.json',
            dict(trim_user='******'))
Пример #26
0
    def test_like(self):
        get_url = self.protocol._get_url = mock.Mock()
        inc_cell = self.protocol._inc_cell = mock.Mock()
        set_cell = self.protocol._set_cell = mock.Mock()

        self.assertEqual(self.protocol.like('1234'), '1234')

        inc_cell.assert_called_once_with('1234', 'likes')
        set_cell.assert_called_once_with('1234', 'liked', True)
        get_url.assert_called_with(
            'https://api.twitter.com/1.1/favorites/create.json',
            dict(id='1234'))
Пример #27
0
    def test_unlike(self):
        get_url = self.protocol._get_url = mock.Mock()
        dec_cell = self.protocol._dec_cell = mock.Mock()
        set_cell = self.protocol._set_cell = mock.Mock()

        self.assertEqual(self.protocol.unlike('1234'), '1234')

        dec_cell.assert_called_once_with('1234', 'likes')
        set_cell.assert_called_once_with('1234', 'liked', False)
        get_url.assert_called_with(
            'https://api.twitter.com/1.1/favorites/destroy.json',
            dict(id='1234'))
Пример #28
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')])
Пример #29
0
    def test_failing_upload(self, gfile):
        gfile.new_for_uri().load_contents.return_value = [True, 'data'.encode()]
        token = self.protocol._get_access_token = mock.Mock()
        publish = self.protocol._publish = mock.Mock()

        self.assertRaises(
            FriendsError,
            self.protocol.upload,
            'file:///path/to/some.jpg',
            'Beautiful photograph!')

        token.assert_called_with()
        self.assertEqual(publish.call_count, 0)
Пример #30
0
    def test_failing_do(self):
        account = mock.Mock()
        self.dispatcher.accounts = mock.Mock()
        self.dispatcher.accounts.get.return_value = None

        self.dispatcher.Do('unlike', '6', '23346356767354626')
        self.dispatcher.accounts.get.assert_called_once_with(6)
        self.assertEqual(account.protocol.call_count, 0)

        self.assertEqual(
            self.log_mock.empty(), 'Clearing timer id: 42\n'
            'Could not find account: 6\n'
            'Starting new shutdown timer...\n')