Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.

Commit

Permalink
Fixed get_thumbnail()
Browse files Browse the repository at this point in the history
  • Loading branch information
tals committed Feb 26, 2014
1 parent 9b3eba5 commit 335a559
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
4 changes: 4 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Release History
---------------

1.2.8
+++++
- Fixed get_thumbnail()

1.2.7
+++++
- Python 2.6 support (thanks @aaylward)
Expand Down
4 changes: 2 additions & 2 deletions box/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ def get_thumbnail(self, file_id, extension="png", min_height=None, max_height=No
if max_width is not None:
params['max_width'] = max_width

response = self._request("get", 'files/{0}/thumbnail.{1}'.format(file_id, extension), params=params)
response = self._request("get", 'files/{0}/thumbnail.{1}'.format(file_id, extension), params=params, stream=True)
if response.status_code == 202:
# Thumbnail not ready yet
ready_in_seconds = int(response.headers["Retry-After"])
Expand All @@ -528,7 +528,7 @@ def get_thumbnail(self, file_id, extension="png", min_height=None, max_height=No
# Wait for the thumbnail to get ready
time.sleep(ready_in_seconds)

response = requests.get(response.headers["Location"], headers=self.default_headers)
response = self._request("get", 'files/{0}/thumbnail.{1}'.format(file_id, extension), params=params, stream=True)
self._check_for_errors(response)
return response.raw
elif response.status_code == 302:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

setup(
name='box.py',
version='1.2.7',
version='1.2.8',
author='Sookasa',
author_email='dev@sookasa.com',
url='http://github.com/sookasa/box.py',
Expand Down
35 changes: 21 additions & 14 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,41 +331,46 @@ def test_get_thumbnail(self):
'https://api.box.com/2.0/files/123/thumbnail.png',
params={},
data=None,
headers=client.default_headers)
headers=client.default_headers,
stream=True)
.and_return(mocked_response(status_code=202, headers={"Location": "http://box.com", "Retry-After": "5"}))
.once())

thumbnail = client.get_thumbnail(123)
self.assertIsNone(thumbnail)

# Delayed within allowed wait time
def test_get_client_with_retry(self):
client = BoxClient("my_token")



(flexmock(requests)
.should_receive('request')
.with_args("get",
'https://api.box.com/2.0/files/123/thumbnail.png',
params={},
data=None,
headers=client.default_headers)
.and_return(mocked_response(status_code=202, headers={"Location": "http://box.com/url_to_thumbnail", "Retry-After": "1"}))
.once())

(flexmock(requests)
.should_receive('get')
.with_args('http://box.com/url_to_thumbnail', headers=client.default_headers)
.and_return(mocked_response(StringIO("Thumbnail contents")))
.once())
headers=client.default_headers,
stream=True)
.and_return(mocked_response(status_code=202, headers={"Location": "http://box.com/url_to_thumbnail", "Retry-After": "1"}),
mocked_response(StringIO("Thumbnail contents")))
.one_by_one())

thumbnail = client.get_thumbnail(123, max_wait=1)
self.assertEqual('Thumbnail contents', thumbnail.read())

def test_get_thumbnail_with_params(self):
client = BoxClient("my_token")

# Not available
(flexmock(requests)
.should_receive('request')
.with_args("get",
'https://api.box.com/2.0/files/123/thumbnail.png',
params={},
data=None,
headers=client.default_headers)
headers=client.default_headers,
stream=True)
.and_return(mocked_response(status_code=302))
.once())

Expand All @@ -379,7 +384,8 @@ def test_get_thumbnail(self):
'https://api.box.com/2.0/files/123/thumbnail.png',
params={},
data=None,
headers=client.default_headers)
headers=client.default_headers,
stream=True)
.and_return(mocked_response(StringIO("Thumbnail contents")))
.once())

Expand All @@ -396,7 +402,8 @@ def test_get_thumbnail(self):
"min_width": 3,
"max_width": 4},
data=None,
headers=client.default_headers)
headers=client.default_headers,
stream=True)
.and_return(mocked_response(StringIO("Thumbnail contents")))
.once())

Expand Down

0 comments on commit 335a559

Please sign in to comment.