Example #1
0
    def setUp(self):
        super(HandlerTest, self).setUp()

        os.environ['APPLICATION_ID'] = 'app_id'
        self.current_user_id = '123'
        self.current_user_email = '*****@*****.**'

        self.testbed = testbed.Testbed()
        self.testbed.setup_env(user_id=self.current_user_id,
                               user_email=self.current_user_email)
        self.testbed.activate()

        hrd_policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(
            probability=.5)
        self.testbed.init_datastore_v3_stub(consistency_policy=hrd_policy)
        self.testbed.init_taskqueue_stub(root_path='.')
        self.testbed.init_user_stub()
        self.testbed.init_mail_stub()
        self.testbed.init_memcache_stub()
        self.testbed.init_logservice_stub()

        self.mox.StubOutWithMock(urllib2, 'urlopen')

        # unofficial API, whee! this is so we can call
        # TaskQueueServiceStub.GetTasks() in tests. see
        # google/appengine/api/taskqueue/taskqueue_stub.py
        self.taskqueue_stub = self.testbed.get_stub('taskqueue')

        self.request = webapp2.Request.blank('/')
        self.response = webapp2.Response()
        self.handler = webapp2.RequestHandler(self.request, self.response)

        # set time zone to UTC so that tests don't depend on local time zone
        os.environ['TZ'] = 'UTC'
Example #2
0
    def test_escaping(self):
        request = webapp2.Request.blank('http://localhost:80/')
        request.app = app
        app.request = request
        handler = webapp2.RequestHandler(request, None)
        handler.app = app

        for func in (app.url_for, handler.url_for):
            url = func('escape', name='with space')
            req = webapp2.Request.blank(url)
            rsp = req.get_response(app)
            self.assertEqual(rsp.status, '200 OK')
            self.assertEqual(rsp.body, 'with space')

            url = func('escape', name='with+plus')
            req = webapp2.Request.blank(url)
            rsp = req.get_response(app)
            self.assertEqual(rsp.status, '200 OK')
            self.assertEqual(rsp.body, 'with+plus')

            url = func('escape', name='with/slash')
            req = webapp2.Request.blank(url)
            rsp = req.get_response(app)
            self.assertEqual(rsp.status, '200 OK')
            self.assertEqual(rsp.body, 'with/slash')
Example #3
0
 def test_get_required_param(self):
   handler = webapp2.RequestHandler(webapp2.Request.blank('/?a=b'), None)
   self.assertEqual('b', util.get_required_param(handler, 'a'))
   try:
     util.get_required_param(handler, 'c')
     self.fail('Expected HTTPException')
   except exc.HTTPException, e:
     self.assertEqual(400, e.status_int)
Example #4
0
 def get_req(uri):
     req = webapp2.Request.blank(uri)
     app.set_globals(app=app, request=req)
     handler = webapp2.RequestHandler(req, None)
     handler.app = req.app = app
     return req, handler