def test_process_input_of_json_object(self): json = dumps( { "1": u"哈哈哈", u"a": { "b": { "二": u"我", }, }, "c": [u"我", u"你", u"c"], }, ensure_ascii=True) req = HTTPJSONRequest(StringIO(json), self.fake_environ) req.process_inputs() self.assertEqual(req.json, { "1": "哈哈哈", "a": { "b": { "二": "我", }, }, "c": ["我", "你", "c"], }) self.assertEqual(req.json, req.form)
def test_process_input_of_json_array(self): json = dumps([ u"哈哈哈", u"a", u"我", u"你", u"c", ], ensure_ascii=True) req = HTTPJSONRequest(StringIO(json), self.fake_environ) req.process_inputs() self.assertEqual(req.json, [ "哈哈哈", "a", "我", "你", "c", ])
def create_request(self, stdin, env): ctype = get_content_type(env) if ctype == "multipart/form-data" and ( # workaround for safari bug, see ticket #1556 env.get('REQUEST_METHOD') != 'GET' or env.get('CONTENT_LENGTH', '0') != '0'): req = HTTPUploadRequest(stdin, env, content_type=ctype) req.set_upload_dir(self.config.upload_dir, self.config.upload_dir_mode) return req elif self.config.support_application_json and ctype == "application/json": return HTTPJSONRequest(stdin, env, content_type=ctype) else: return HTTPRequest(stdin, env, content_type=ctype)
def test_process_input_of_json_object(self): json = dumps({ "1": u"哈哈哈", u"a": { "b": { "二": u"我", }, }, "c": [u"我", u"你", u"c"], }, ensure_ascii=True) req = HTTPJSONRequest(StringIO(json), self.fake_environ) req.process_inputs() self.assertEqual(req.json, { "1": "哈哈哈", "a": { "b": { "二": "我", }, }, "c": ["我", "你", "c"], }) self.assertEqual(req.json, req.form)
def test_query_error(self): req = HTTPJSONRequest(StringIO(''), self.fake_environ) self.assertRaises(QueryError, req.process_inputs)