Skip to content

Commit

Permalink
GoogleCloudPlatform#140: Replace webapp1 tests by webapp2 tests
Browse files Browse the repository at this point in the history
It seems that somewhere between 1.9.54 and 1.9.66, App Engine SDK
removed support of webapp1, probably because support of Python 2.5 also
had been removed from App Engine Python standard environment. As a
result, the behavior with using old style request handlers changed, and
so two tests in webapp1_test.py would fail.

Resolution: Replace tests regarding old WSGIApplication and/or old
RequestHandler. All gaesdk tests use WSGIApplication and RequestHandler
of webapp2. Asserts reflect behavior of webapp2 app and handler.
  • Loading branch information
AniX committed Nov 6, 2018
1 parent 561edd5 commit 8922317
Showing 1 changed file with 21 additions and 38 deletions.
59 changes: 21 additions & 38 deletions tests/gae/webapp1_test.py → tests/gae/webapp2_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from google.appengine.ext import webapp

import test_base
import webapp2


# Old WSGIApplication, new RequestHandler.
# WSGIApplication and RequestHandler of webapp2
# webapp1 is not supported anymore
class NewStyleHandler(webapp2.RequestHandler):
def get(self, text):
self.response.out.write(text)


app = webapp.WSGIApplication([
(r'/test/(.*)', NewStyleHandler),
])


# New WSGIApplication, old RequestHandler.
class OldStyleHandler(webapp.RequestHandler):
def get(self, text):
self.response.out.write(text)


class OldStyleHandler2(webapp.RequestHandler):
def get(self, text=None):
self.response.out.write(text)


class OldStyleHandlerWithError(webapp.RequestHandler):
class NewStyleHandlerWithError(webapp2.RequestHandler):
def get(self, text):
raise ValueError()

Expand All @@ -51,27 +34,27 @@ def handle_exception(self, e, debug):


app2 = webapp2.WSGIApplication([
(r'/test/error', OldStyleHandlerWithError),
(r'/test/(.*)', OldStyleHandler),
webapp2.Route(r'/test2/<text>', OldStyleHandler2),
(r'/test/error', NewStyleHandlerWithError),
(r'/test/(.*)', NewStyleHandler),
webapp2.Route(r'/test2/<text>', NewStyleHandler),
])


class TestWebapp1(test_base.BaseTestCase):
def test_old_app_new_handler(self):
class TestWebapp2(test_base.BaseTestCase):
def test_app_handler(self):
req = webapp2.Request.blank('/test/foo')
rsp = req.get_response(app)
rsp = req.get_response(app2)
self.assertEqual(rsp.status_int, 200)
self.assertEqual(rsp.body, 'foo')

req = webapp2.Request.blank('/test/bar')
rsp = req.get_response(app)
rsp = req.get_response(app2)
self.assertEqual(rsp.status_int, 200)
self.assertEqual(rsp.body, 'bar')

self.assertTrue(issubclass(OldStyleHandler, webapp.RequestHandler))
self.assertTrue(issubclass(NewStyleHandler, webapp2.RequestHandler))

def test_new_app_old_handler(self):
def test_handler_200(self):
req = webapp2.Request.blank('/test/foo')
rsp = req.get_response(app2)
self.assertEqual(rsp.status_int, 200)
Expand All @@ -82,33 +65,33 @@ def test_new_app_old_handler(self):
self.assertEqual(rsp.status_int, 200)
self.assertEqual(rsp.body, 'bar')

def test_new_app_old_handler_405(self):
def test_handler_405(self):
req = webapp2.Request.blank('/test/foo')
req.method = 'POST'
rsp = req.get_response(app2)
self.assertEqual(rsp.status_int, 405)
self.assertEqual(rsp.headers.get('Allow'), None)
self.assertEqual(rsp.headers.get('Allow'), 'GET')

def test_new_app_old_handler_501(self):
def test_handler_405_new_method(self):
app2.allowed_methods = list(app2.allowed_methods) + ['NEW_METHOD']
req = webapp2.Request.blank('/test/foo')
req.method = 'NEW_METHOD'
rsp = req.get_response(app2)
self.assertEqual(rsp.status_int, 501)
self.assertEqual(rsp.status_int, 405)

def test_new_app_old_handler_501_2(self):
def test_handler_501(self):
req = webapp2.Request.blank('/test/foo')
req.method = 'WHATMETHODISTHIS'
rsp = req.get_response(app2)
self.assertEqual(rsp.status_int, 501)

def test_new_app_old_handler_with_error(self):
def test_handler_with_error(self):
req = webapp2.Request.blank('/test/error')
rsp = req.get_response(app2)
self.assertEqual(rsp.status_int, 500)
self.assertEqual(rsp.body, 'ValueError!')

def test_new_app_old_kwargs(self):
def test_kwargs(self):
req = webapp2.Request.blank('/test2/foo')
rsp = req.get_response(app2)
self.assertEqual(rsp.status_int, 200)
Expand All @@ -126,11 +109,11 @@ def test_unicode_cookie(self):
# So we have to do it.
quoted_value = urllib.quote(initial_value.encode('utf-8'))

rsp = webapp.Response()
rsp = webapp2.Response()
rsp.headers['Set-Cookie'] = 'app=%s; Path=/' % quoted_value

cookie = rsp.headers.get('Set-Cookie')
req = webapp.Request.blank('/', headers=[('Cookie', cookie)])
req = webapp2.Request.blank('/', headers=[('Cookie', cookie)])

# The stored value is the same quoted value from before.
stored_value = req.cookies.get('app')
Expand Down

0 comments on commit 8922317

Please sign in to comment.