-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved image guestbook, added basic image example
- Loading branch information
1 parent
fddf5e6
commit 9d37f16
Showing
12 changed files
with
136 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
## Images Guestbook Sample | ||
|
||
This is a sample app for Google App Engine that demonstrates the [Images Python | ||
API](https://cloud.google.com/appengine/docs/python/images/usingimages). | ||
|
||
<!-- auto-doc-link --> | ||
These samples are used on the following documentation page: | ||
|
||
> https://cloud.google.com/appengine/docs/python/images/ | ||
<!-- end-auto-doc-link --> | ||
|
||
Refer to the [App Engine Samples README](../../README.md) for information on how to run and deploy this sample. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
runtime: python27 | ||
api_version: 1 | ||
threadsafe: yes | ||
|
||
handlers: | ||
|
||
- url: .* | ||
script: main.app |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Copyright 2015 Google Inc. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
""" | ||
Sample application that demonstrates how to use the App Engine Images API. | ||
For more information, see README.md. | ||
""" | ||
|
||
# [START all] | ||
# [START thumbnailer] | ||
from google.appengine.api import images | ||
from google.appengine.ext import ndb | ||
|
||
import webapp2 | ||
|
||
|
||
class Photo(ndb.Model): | ||
title = ndb.StringProperty() | ||
full_size_image = ndb.BlobProperty() | ||
|
||
|
||
class Thumbnailer(webapp2.RequestHandler): | ||
def get(self): | ||
if self.request.get("id"): | ||
photo = Photo.get_by_id(int(self.request.get("id"))) | ||
|
||
if photo: | ||
img = images.Image(photo.full_size_image) | ||
img.resize(width=80, height=100) | ||
img.im_feeling_lucky() | ||
thumbnail = img.execute_transforms(output_encoding=images.JPEG) | ||
|
||
self.response.headers['Content-Type'] = 'image/jpeg' | ||
self.response.out.write(thumbnail) | ||
return | ||
|
||
# Either "id" wasn't provided, or there was no image with that ID | ||
# in the datastore. | ||
self.error(404) | ||
# [END thumbnailer] | ||
|
||
|
||
app = webapp2.WSGIApplication([('/img', Thumbnailer)], debug=True) | ||
# [END all] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Copyright 2015 Google Inc. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import main | ||
import pytest | ||
import mock | ||
import webtest | ||
|
||
|
||
@pytest.fixture | ||
def app(testbed): | ||
return webtest.TestApp(main.app) | ||
|
||
|
||
def test_img(app): | ||
with mock.patch('main.images') as mock_images: | ||
mock_images.resize.return_value = 'asdf' | ||
mock_images.im_feeling_lucky.return_value = 'gsdf' | ||
photo = main.Photo( | ||
id=234 | ||
) | ||
photo.title='asdf' | ||
photo.full_size_image=b'123' | ||
photo.put() | ||
print photo.key.id() | ||
|
||
response = app.get('/img?id=%s' % photo.key.id()) | ||
|
||
assert response.status_int == 200 | ||
|
||
|
||
def test_img_missing(app): | ||
# Bogus image id, should get error | ||
app.get('/img?id=123', status=404) | ||
|
||
|
||
def test_no_img_id(app): | ||
# Bogus image id, should get error | ||
app.get('/img', status=404) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
runtime: python27 | ||
api_version: 1 | ||
threadsafe: yes | ||
|
||
handlers: | ||
|
||
- url: .* | ||
script: main.app |
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.