def test_json_empty(self): """ Environ: Request.json property with empty body. """ self.assertEqual(BaseRequest({}).json, None)
def test_route_property(self): e = {'bottle.route': 5} r = BaseRequest(e) self.assertEqual(r.route, 5)
def test_url_for_property(self): e = {} r = BaseRequest(e) self.assertRaises(RuntimeError, lambda: r.url_args) e.update({'route.url_args': {'a': 5}}) self.assertEqual(r.url_args, {'a': 5})
def test_app_property(self): e = {} r = BaseRequest(e) self.assertRaises(RuntimeError, lambda: r.app) e.update({'bottle.app': 5}) self.assertEqual(r.app, 5)
def test_shift(s, p, c): request = BaseRequest({'SCRIPT_NAME': s, 'PATH_INFO': p}) request.path_shift(c) return [request['SCRIPT_NAME'], request.path]
def test_isajax(self): e = {} wsgiref.util.setup_testing_defaults(e) self.assertFalse(BaseRequest(e.copy()).is_ajax) e['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest' self.assertTrue(BaseRequest(e.copy()).is_ajax)
def test_app(self): e = {} r = BaseRequest(e) self.assertRaises(AttributeError, lambda: r.app) e.update({'bottle.app': 5}) self.assertEqual(r.app, 5)
def test_readonly_environ(self): request = BaseRequest({'bottle.request.readonly':True}) def test(): request['x']='y' self.assertRaises(KeyError, test)