File tree Expand file tree Collapse file tree 2 files changed +43
-1
lines changed
appengine/standard/images/api Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -48,5 +48,26 @@ def get(self):
48
48
# [END thumbnailer]
49
49
50
50
51
- app = webapp2 .WSGIApplication ([('/img' , Thumbnailer )], debug = True )
51
+ class ServingUrlRedirect (webapp2 .RequestHandler ):
52
+ def get (self ):
53
+ blob_key = self .request .get ("blob_key" )
54
+
55
+ if blob_key :
56
+ blob_info = blobstore .get (blob_key )
57
+
58
+ if blob_info :
59
+ # [START get_serving_url]
60
+ url = images .get_serving_url (
61
+ blob_key , size = 150 , crop = True , secure_url = True )
62
+ # [END get_serving_url]
63
+ return webapp2 .redirect (url )
64
+
65
+ # Either "blob_key" wasn't provided, or there was no value with that ID
66
+ # in the Blobstore.
67
+ self .error (404 )
68
+
69
+
70
+ app = webapp2 .WSGIApplication (
71
+ [('/img' , Thumbnailer ),
72
+ ('/redirect' , ServingUrlRedirect )], debug = True )
52
73
# [END all]
Original file line number Diff line number Diff line change @@ -44,3 +44,24 @@ def test_img_missing(app):
44
44
def test_no_img_id (app ):
45
45
# No blob_key, should get error
46
46
app .get ('/img' , status = 404 )
47
+
48
+
49
+ def test_url_redirect (app ):
50
+ with mock .patch ('blobstore.images' ) as mock_images :
51
+ with mock .patch ('blobstore.blobstore' ) as mock_blobstore :
52
+ mock_blobstore .get .return_value = b'123'
53
+ mock_images .get_serving_url .return_value = 'http://lh3.ggpht.com/X'
54
+
55
+ response = app .get ('/redirect?blob_key=123' )
56
+
57
+ assert response .status_int == 302
58
+
59
+
60
+ def test_url_redirect_missing (app ):
61
+ # Bogus blob_key, should get error
62
+ app .get ('/redirect?blob_key=123' , status = 404 )
63
+
64
+
65
+ def test_url_redirect_no_key (app ):
66
+ # No blob_key, should get error
67
+ app .get ('/redirect' , status = 404 )
You can’t perform that action at this time.
0 commit comments