コード例 #1
0
    def test_given_token_is_not_provided_and_it_is_not_in_cache_then_token_is_fetched_and_added_to_cache(
            self, mock_session_wrapper, mock_basic_auth):
        mock_basic_auth.return_value = 'MyBasicAuth'

        mock_session_wrapper.return_value.token = {
            'token_type': 'bearer',
            'access_token': '789'
        }
        mock_session_wrapper.fetch_token.return_value = None

        auth = ClientGrantAuth('user', 'pass', 'http://identity')
        auth.init_session()

        assert_that(
            TokenCache._token_storage,
            is_({
                'user': {
                    'http://identity': {
                        'token_type': 'bearer',
                        'access_token': '789'
                    }
                }
            }))

        mock_session_wrapper.return_value.fetch_token.assert_called_once_with(
            auth='MyBasicAuth', timeout=0, token_url='http://identity')
コード例 #2
0
    def test_given_request_return_oauth_token_expired_error_then_except_sequoia_token_expired_error_is_raised(
            self, mock_oauth_request, mock_basic_auth):

        mock_basic_auth.return_value = 'MyBasicAuth'

        mock_oauth_request.side_effect = TokenExpiredError('Token expired')

        auth = ClientGrantAuth('user', 'pass', 'http://identity')

        with pytest.raises(error.TokenExpiredError):
            auth.session.request('GET', 'http://mydata')
コード例 #3
0
 def test_given_token_is_not_provided_and_there_is_a_token_in_cache_then_that_token_is_used(
         self):
     TokenCache().add_token('user', 'http://identity', {
         'token_type': 'bearer',
         'access_token': '567'
     })
     auth = ClientGrantAuth('user', 'pass', 'http://identity')
     assert_that(auth.token,
                 is_({
                     'token_type': 'bearer',
                     'access_token': '567'
                 }))
コード例 #4
0
    def test_given_token_is_not_provided_and_it_is_not_in_cache_then_token_is_fetched_and_added_to_cache(
            self):
        class MockSession:
            def __init__(self):
                self.token = {'token_type': 'bearer', 'access_token': '789'}

            def fetch_token(self, *args, **kwargs):
                pass

        auth = ClientGrantAuth('user', 'pass', 'http://identity')
        auth.session = MockSession()
        auth.init_session()

        assert_that(
            TokenCache._token_storage,
            is_({
                'user': {
                    'http://identity': {
                        'token_type': 'bearer',
                        'access_token': '789'
                    }
                }
            }))
コード例 #5
0
 def test_given_token_is_provided_then_that_token_is_used_and_added_to_cache(
         self):
     auth = ClientGrantAuth('user', 'pass', 'http://identity', '1234')
     assert_that(auth.token,
                 is_({
                     'token_type': 'bearer',
                     'access_token': '1234'
                 }))
     assert_that(
         TokenCache._token_storage,
         is_({
             'user': {
                 'http://identity': {
                     'token_type': 'bearer',
                     'access_token': '1234'
                 }
             }
         }))
コード例 #6
0
 def test_given_token_is_not_provided_and_it_is_not_in_cache_then_token_is_none(
         self):
     auth = ClientGrantAuth('user', 'pass', 'http://identity')
     assert_that(auth.token, is_(None))