Skip to content

Commit 98c3049

Browse files
committed
Merge branch 'master' into best_memcache
2 parents 9e05724 + fe59a33 commit 98c3049

File tree

3 files changed

+98
-1
lines changed

3 files changed

+98
-1
lines changed

appengine/images/api/blobstore.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright 2015 Google Inc. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""
16+
Sample application that demonstrates how to use the App Engine Images API.
17+
18+
For more information, see README.md.
19+
"""
20+
21+
# [START all]
22+
# [START thumbnailer]
23+
from google.appengine.api import images
24+
from google.appengine.ext import blobstore
25+
26+
import webapp2
27+
28+
29+
class Thumbnailer(webapp2.RequestHandler):
30+
def get(self):
31+
blob_key = self.request.get("blob_key")
32+
if blob_key:
33+
blob_info = blobstore.get(blob_key)
34+
35+
if blob_info:
36+
img = images.Image(blob_key=blob_key)
37+
img.resize(width=80, height=100)
38+
img.im_feeling_lucky()
39+
thumbnail = img.execute_transforms(output_encoding=images.JPEG)
40+
41+
self.response.headers['Content-Type'] = 'image/jpeg'
42+
self.response.out.write(thumbnail)
43+
return
44+
45+
# Either "blob_key" wasn't provided, or there was no value with that ID
46+
# in the Blobstore.
47+
self.error(404)
48+
# [END thumbnailer]
49+
50+
51+
app = webapp2.WSGIApplication([('/img', Thumbnailer)], debug=True)
52+
# [END all]
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright 2015 Google Inc. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import blobstore
16+
import mock
17+
import pytest
18+
import webtest
19+
20+
21+
@pytest.fixture
22+
def app(testbed):
23+
return webtest.TestApp(blobstore.app)
24+
25+
26+
def test_img(app):
27+
with mock.patch('blobstore.images') as mock_images:
28+
with mock.patch('blobstore.blobstore') as mock_blobstore:
29+
mock_blobstore.get.return_value = b'123'
30+
mock_images.resize.return_value = 'asdf'
31+
mock_images.im_feeling_lucky.return_value = 'gsdf'
32+
33+
response = app.get('/img?blob_key=123')
34+
35+
assert response.status_int == 200
36+
37+
38+
def test_img_missing(app):
39+
# Bogus blob_key, should get error
40+
app.get('/img?blob_key=123', status=404)
41+
42+
43+
def test_no_img_id(app):
44+
# No blob_key, should get error
45+
app.get('/img', status=404)

appengine/images/api/main_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ def test_img_missing(app):
4545

4646

4747
def test_no_img_id(app):
48-
# Bogus image id, should get error
48+
# No image id, should get error
4949
app.get('/img', status=404)

0 commit comments

Comments
 (0)