test_file.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:deb-python-oauth2client 作者: openstack 项目源码 文件源码
def test_token_refresh_store_expires_soon(self):
        # Tests the case where an access token that is valid when it is read
        # from the store expires before the original request succeeds.
        expiration = (datetime.datetime.utcnow() +
                      datetime.timedelta(minutes=15))
        credentials = self._create_test_credentials(expiration=expiration)

        storage = file_module.Storage(FILENAME)
        storage.put(credentials)
        credentials = storage.get()
        new_cred = copy.copy(credentials)
        new_cred.access_token = 'bar'
        storage.put(new_cred)

        access_token = '1/3w'
        token_response = {'access_token': access_token, 'expires_in': 3600}
        http = http_mock.HttpMockSequence([
            ({'status': http_client.UNAUTHORIZED},
             b'Initial token expired'),
            ({'status': http_client.UNAUTHORIZED},
             b'Store token expired'),
            ({'status': http_client.OK},
             json.dumps(token_response).encode('utf-8')),
            ({'status': http_client.OK},
             b'Valid response to original request')
        ])

        credentials.authorize(http)
        transport.request(http, 'https://example.com')
        self.assertEqual(credentials.access_token, access_token)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号