~ps-jenkins/friends/latestsnapshot-0.2.0daily13.05.07.1-0ubuntu1

« back to all changes in this revision

Viewing changes to friends/tests/test_twitter.py

  • Committer: Robert Bruce Park
  • Date: 2013-05-01 17:05:12 UTC
  • mfrom: (160.11.31 trunk-next)
  • Revision ID: robert.park@canonical.com-20130501170512-d3xrvv4vmv24k3ir
Land trunk-next into lp:friends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
        self.log_mock.stop()
58
58
        shutil.rmtree(self._temp_cache)
59
59
 
 
60
    @mock.patch('friends.utils.authentication.manager')
 
61
    @mock.patch('friends.utils.authentication.Accounts')
60
62
    @mock.patch.dict('friends.utils.authentication.__dict__', LOGIN_TIMEOUT=1)
61
63
    @mock.patch('friends.utils.authentication.Signon.AuthSession.new')
62
64
    @mock.patch('friends.protocols.twitter.Downloader.get_json',
63
65
                return_value=None)
64
 
    def test_unsuccessful_authentication(self, dload, login):
 
66
    def test_unsuccessful_authentication(self, dload, login, *mocks):
65
67
        self.assertRaises(AuthorizationError, self.protocol._login)
66
68
        self.assertIsNone(self.account.user_name)
67
69
        self.assertIsNone(self.account.user_id)
68
70
 
 
71
    @mock.patch('friends.utils.authentication.manager')
 
72
    @mock.patch('friends.utils.authentication.Accounts')
 
73
    @mock.patch('friends.utils.authentication.Authentication.__init__',
 
74
                return_value=None)
69
75
    @mock.patch('friends.utils.authentication.Authentication.login',
70
76
                return_value=dict(AccessToken='some clever fake data',
71
77
                                  TokenSecret='sssssshhh!',
83
89
                lambda: 'once upon a nonce')
84
90
    @mock.patch('oauthlib.oauth1.rfc5849.generate_timestamp',
85
91
                lambda: '1348690628')
86
 
    def test_signatures(self, dload, params=None):
87
 
        if params is None:
88
 
            params = dict(ConsumerKey='consume',
89
 
                          ConsumerSecret='obey')
 
92
    def test_signatures(self, dload):
90
93
        self.account.secret_token = 'alpha'
91
94
        self.account.access_token = 'omega'
92
 
        self.account.auth.id = 6
93
 
        self.account.auth.method = 'oauth2'
94
 
        self.account.auth.mechanism = 'HMAC-SHA1'
95
 
        self.account.auth.parameters = params
 
95
        self.account.consumer_secret = 'obey'
 
96
        self.account.consumer_key = 'consume'
 
97
        self.account.auth.get_credentials_id = lambda *ignore: 6
 
98
        self.account.auth.get_method = lambda *ignore: 'oauth2'
 
99
        self.account.auth.get_mechanism = lambda *ignore: 'HMAC-SHA1'
96
100
 
97
101
        result = '''\
98
102
OAuth oauth_nonce="once%20upon%20a%20nonce", \
116
120
            params=None,
117
121
            method='GET')
118
122
 
119
 
    def test_signatures_sohu(self):
120
 
        params = dict(ClientId='consume',
121
 
                      ClientSecret='obey')
122
 
        self.test_signatures(params=params)
123
 
 
124
123
    @mock.patch('friends.utils.base.Model', TestModel)
125
124
    @mock.patch('friends.utils.http.Soup.Message',
126
125
                FakeSoupMessage('friends.tests.data', 'twitter-home.dat'))
130
129
    def test_home(self, *mocks):
131
130
        self.account.access_token = 'access'
132
131
        self.account.secret_token = 'secret'
133
 
        self.account.auth.parameters = dict(
134
 
            ConsumerKey='key',
135
 
            ConsumerSecret='secret')
136
132
        self.assertEqual(0, TestModel.get_n_rows())
137
133
        self.assertEqual(self.protocol.home(), 3)
138
134
        self.assertEqual(3, TestModel.get_n_rows())
180
176
    def test_home_since_id(self, *mocks):
181
177
        self.account.access_token = 'access'
182
178
        self.account.secret_token = 'secret'
183
 
        self.account.auth.parameters = dict(
184
 
            ConsumerKey='key',
185
 
            ConsumerSecret='secret')
186
179
        self.assertEqual(self.protocol.home(), 3)
187
180
 
188
181
        with open(self._root.format('twitter_ids'), 'r') as fd:
205
198
        self.account.access_token = 'access'
206
199
        self.account.secret_token = 'secret'
207
200
        self.account.user_name = 'oauth_dancer'
208
 
        self.account.auth.parameters = dict(
209
 
            ConsumerKey='key',
210
 
            ConsumerSecret='secret')
211
201
        self.assertEqual(0, TestModel.get_n_rows())
212
202
        self.assertEqual(
213
203
            self.protocol.send('some message'),
408
398
    def test_send_thread_prepend_nick(self, *mocks):
409
399
        self.account.access_token = 'access'
410
400
        self.account.secret_token = 'secret'
411
 
        self.account.auth.parameters = dict(
412
 
            ConsumerKey='key',
413
 
            ConsumerSecret='secret')
414
401
        self.assertEqual(0, TestModel.get_n_rows())
415
402
        self.assertEqual(self.protocol.home(), 3)
416
403
        self.assertEqual(3, TestModel.get_n_rows())
754
741
    def test_protocol_rate_limiting(self, time, sleep, login):
755
742
        self.account.access_token = 'access'
756
743
        self.account.secret_token = 'secret'
757
 
        self.account.auth.parameters = dict(
758
 
            ConsumerKey='key',
759
 
            ConsumerSecret='secret')
760
744
        # Test rate limiting via the Twitter plugin API.
761
745
        #
762
746
        # The first call doesn't get rate limited.