|
32 | 32 | import unittest |
33 | 33 |
|
34 | 34 | from .http_mock import HttpMockSequence |
| 35 | +import six |
| 36 | + |
35 | 37 | from oauth2client import file |
36 | 38 | from oauth2client import locked_file |
37 | 39 | from oauth2client import multistore_file |
@@ -178,6 +180,33 @@ def test_token_refresh_good_store(self): |
178 | 180 | credentials._refresh(lambda x: x) |
179 | 181 | self.assertEquals(credentials.access_token, 'bar') |
180 | 182 |
|
| 183 | + def test_token_refresh_stream_body(self): |
| 184 | + expiration = datetime.datetime.utcnow() + datetime.timedelta(minutes=15) |
| 185 | + credentials = self.create_test_credentials(expiration=expiration) |
| 186 | + |
| 187 | + s = file.Storage(FILENAME) |
| 188 | + s.put(credentials) |
| 189 | + credentials = s.get() |
| 190 | + new_cred = copy.copy(credentials) |
| 191 | + new_cred.access_token = 'bar' |
| 192 | + s.put(new_cred) |
| 193 | + |
| 194 | + valid_access_token = '1/3w' |
| 195 | + token_response = {'access_token': valid_access_token, 'expires_in': 3600} |
| 196 | + http = HttpMockSequence([ |
| 197 | + ({'status': '401'}, b'Initial token expired'), |
| 198 | + ({'status': '401'}, b'Store token expired'), |
| 199 | + ({'status': '200'}, json.dumps(token_response).encode('utf-8')), |
| 200 | + ({'status': '200'}, 'echo_request_body') |
| 201 | + ]) |
| 202 | + |
| 203 | + body = six.StringIO('streaming body') |
| 204 | + |
| 205 | + credentials.authorize(http) |
| 206 | + _, content = http.request('https://example.com', body=body) |
| 207 | + self.assertEquals(content, 'streaming body') |
| 208 | + self.assertEquals(credentials.access_token, valid_access_token) |
| 209 | + |
181 | 210 | def test_credentials_delete(self): |
182 | 211 | credentials = self.create_test_credentials() |
183 | 212 |
|
|
0 commit comments