Beispiel #1
0
    def test_fetch_token_invalid_response(self):
        auth = OAuth1Session('foo')
        auth.send = mock_text_response('not valid urlencoded response!')
        self.assertRaises(ValueError, auth.fetch_request_token,
                          'https://example.com/token')

        for code in (400, 401, 403):
            auth.send = mock_text_response('valid=response', code)
            # use try/catch rather than self.assertRaises, so we can
            # assert on the properties of the exception
            try:
                auth.fetch_request_token('https://example.com/token')
            except OAuthError as err:
                self.assertEqual(err.error, 'fetch_token_denied')
            else:  # no exception raised
                self.fail("ValueError not raised")
Beispiel #2
0
    def test_fetch_access_token(self):
        auth = OAuth1Session('foo', verifier='bar')
        auth.send = mock_text_response('oauth_token=foo')
        resp = auth.fetch_access_token('https://example.com/token')
        self.assertEqual(resp['oauth_token'], 'foo')
        for k, v in resp.items():
            self.assertTrue(isinstance(k, unicode_type))
            self.assertTrue(isinstance(v, unicode_type))

        auth = OAuth1Session('foo', verifier='bar')
        auth.send = mock_text_response('{"oauth_token":"foo"}')
        resp = auth.fetch_access_token('https://example.com/token')
        self.assertEqual(resp['oauth_token'], 'foo')

        auth = OAuth1Session('foo')
        auth.send = mock_text_response('oauth_token=foo')
        resp = auth.fetch_access_token('https://example.com/token',
                                       verifier='bar')
        self.assertEqual(resp['oauth_token'], 'foo')
Beispiel #3
0
 def test_fetch_access_token_with_optional_arguments(self):
     auth = OAuth1Session('foo', verifier='bar')
     auth.send = mock_text_response('oauth_token=foo')
     resp = auth.fetch_access_token('https://example.com/token',
                                    verify=False,
                                    stream=True)
     self.assertEqual(resp['oauth_token'], 'foo')
     for k, v in resp.items():
         self.assertTrue(isinstance(k, unicode_type))
         self.assertTrue(isinstance(v, unicode_type))
Beispiel #4
0
    def _test_fetch_access_token_raises_error(self, session):
        """Assert that an error is being raised whenever there's no verifier
        passed in to the client.
        """
        session.send = mock_text_response('oauth_token=foo')

        # Use a try-except block so that we can assert on the exception message
        # being raised and also keep the Python2.6 compatibility where
        # assertRaises is not a context manager.
        try:
            session.fetch_access_token('https://example.com/token')
        except OAuthError as exc:
            self.assertEqual(exc.error, 'missing_verifier')
Beispiel #5
0
    def test_fetch_request_token(self):
        auth = OAuth1Session('foo')
        auth.send = mock_text_response('oauth_token=foo')
        resp = auth.fetch_request_token('https://example.com/token')
        self.assertEqual(resp['oauth_token'], 'foo')
        for k, v in resp.items():
            self.assertTrue(isinstance(k, unicode_type))
            self.assertTrue(isinstance(v, unicode_type))

        resp = auth.fetch_request_token('https://example.com/token', realm='A')
        self.assertEqual(resp['oauth_token'], 'foo')
        resp = auth.fetch_request_token('https://example.com/token',
                                        realm=['A', 'B'])
        self.assertEqual(resp['oauth_token'], 'foo')