当前位置: 首页>>代码示例>>Python>>正文


Python testutil.DummyRequest类代码示例

本文整理汇总了Python中shiji.testutil.DummyRequest的典型用法代码示例。如果您正苦于以下问题:Python DummyRequest类的具体用法?Python DummyRequest怎么用?Python DummyRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DummyRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_good_page_overrides_default

 def test_good_page_overrides_default(self):
     "Valid page argument overrides page from default."
     test_request = DummyRequest()
     test_request.args["arg1"] = ["test"]
     test_request.args["page"] = ["1"]
     res = self.dummy_render_func2(test_request)
     self.assertEqual(res["page"][0], "1")
开发者ID:notoriousno,项目名称:shiji,代码行数:7,代码来源:test_webapi.py

示例2: test_json_validate_success

 def test_json_validate_success(self):
     "Request URL arguments successfully validated."
     test_request = DummyRequest()
     test_request.setHeader("Content-Type", "application/json; charset=utf-8")
     test_request.args["arg1"] = "test"
     res = self.dummy_render_func2(test_request)
     self.assertEqual(res, "okey dokey")
开发者ID:notoriousno,项目名称:shiji,代码行数:7,代码来源:test_webapi.py

示例3: test_content_type_charset_not_utf8

 def test_content_type_charset_not_utf8(self):
     "Request Content-Type characters set is not UTF-8"
     test_request = DummyRequest()
     test_request.setHeader("Content-Type", "application/json; charset=iso-1022-jp")
     outer_wrap = webapi.json_arguments([("arg1", unicode)])
     inner_wrap = outer_wrap(self.dummy_render_func)
     self.assertEqual(str(webapi.CharsetNotUTF8Error(test_request)),
                      inner_wrap(self, test_request))
开发者ID:notoriousno,项目名称:shiji,代码行数:8,代码来源:test_webapi.py

示例4: test_content_type_no_charset

 def test_content_type_no_charset(self):
     "Request Content-Type does not have a character set specified"
     test_request = DummyRequest()
     test_request.setHeader("Content-Type", "application/json")
     outer_wrap = webapi.json_arguments([("arg1", unicode)])
     inner_wrap = outer_wrap(self.dummy_render_func)
     self.assertEqual(str(webapi.CharsetNotUTF8Error(test_request)),
                      inner_wrap(self, test_request))
开发者ID:notoriousno,项目名称:shiji,代码行数:8,代码来源:test_webapi.py

示例5: test_get_child_route_no_api_match

 def test_get_child_route_no_api_match(self):
     "Test route match with no API name match in version header"
     request = DummyRequest(api_mode="", api_version="", api_name="")
     request.setHeader("X-DigiTar-API-Version", "badmojoapi-1.0+prod")
     route_map = [(r"^/example/", dummy_api)]
     router = urldispatch.APIRouter(route_map)
     resource = router.getChild("/example/", request)
     self.assertTrue(isinstance(resource, urldispatch.UnknownVersion))
开发者ID:notoriousno,项目名称:shiji,代码行数:8,代码来源:test_urldispatch.py

示例6: test_page_len_gt_max_page_len_fail

 def test_page_len_gt_max_page_len_fail(self):
     "page_len argument in request is > max_page_len."
     test_request = DummyRequest()
     test_request.args["arg1"] = ["test"]
     test_request.args["page_len"] = ["501"]
     res = self.dummy_render_func2(test_request)
     self.assertEqual(res,
                      str(webapi.ValueError(test_request, "page_len", "Argument must be 500 or less.")))
开发者ID:notoriousno,项目名称:shiji,代码行数:8,代码来源:test_webapi.py

示例7: test_page_lt_zero_fail

 def test_page_lt_zero_fail(self):
     "page argument in request is < 0."
     test_request = DummyRequest()
     test_request.args["arg1"] = ["test"]
     test_request.args["page"] = ["-1"]
     res = self.dummy_render_func2(test_request)
     self.assertEqual(res,
                      str(webapi.ValueError(test_request, "page", "Argument must be 0 or greater.")))
开发者ID:notoriousno,项目名称:shiji,代码行数:8,代码来源:test_webapi.py

示例8: test_page_invalid_int_fail

 def test_page_invalid_int_fail(self):
     "page argument in request is not a valid integer."
     test_request = DummyRequest()
     test_request.args["arg1"] = ["test"]
     test_request.args["page"] = ["xyz"]
     res = self.dummy_render_func2(test_request)
     self.assertEqual(res,
                      str(webapi.ValueError(test_request, "page", "Argument must be an integer.")))
开发者ID:notoriousno,项目名称:shiji,代码行数:8,代码来源:test_webapi.py

示例9: test_get_child_version_unknown

 def test_get_child_version_unknown(self):
     "Test version extraction with bad header"
     request = DummyRequest(api_mode="", api_version="", api_name="")
     request.setHeader("X-DigiTar-API-Version", "dummyapi")
     route_map = [(r"^/example/", dummy_api)]
     router = urldispatch.APIRouter(route_map)
     resource = router.getChild("/example/", request)
     self.assertTrue(isinstance(resource, urldispatch.UnknownVersion))
开发者ID:notoriousno,项目名称:shiji,代码行数:8,代码来源:test_urldispatch.py

示例10: test_write_json

 def test_write_json(self):
     "Validate write_json outputs JSON & sets content length"
 
     test_request = DummyRequest()
     test_obj = {"test_key": "test_value"}
     webapi.write_json(test_request, test_obj)
 
     self.assertEquals(test_request.getAllHeaders()["Content-Length"], len(json.dumps(test_obj)))
     self.assertEquals(test_request.content.getvalue(), json.dumps(test_obj))
开发者ID:notoriousno,项目名称:shiji,代码行数:9,代码来源:test_webapi.py

示例11: test_good_page_and_page_len_overrides_default

 def test_good_page_and_page_len_overrides_default(self):
     "Valid page & page_len arguments override page & page_len from defaults."
     test_request = DummyRequest()
     test_request.args["arg1"] = ["test"]
     test_request.args["page"] = ["1"]
     test_request.args["page_len"] = ["50"]
     res = self.dummy_render_func2(test_request)
     self.assertEqual(res["page"][0], "1")
     self.assertEqual(res["page_len"][0], "50")
开发者ID:notoriousno,项目名称:shiji,代码行数:9,代码来源:test_webapi.py

示例12: test_content_required_arg_missing_optional_flag_false

 def test_content_required_arg_missing_optional_flag_false(self):
     "Request JSON arguments missing required argument."
     test_request = DummyRequest()
     test_request.setHeader("Content-Type", "application/json; charset=utf-8")
     test_request.write(json.dumps({"arg2" : 1}))
     outer_wrap = webapi.json_arguments([("arg1", unicode, False)])
     inner_wrap = outer_wrap(self.dummy_render_func)
     self.assertEqual(str(webapi.ValueError(test_request, "arg1", "Argument is missing.")),
                      inner_wrap(self, test_request))
开发者ID:notoriousno,项目名称:shiji,代码行数:9,代码来源:test_webapi.py

示例13: test_content_arg_type_mismatch_optional_arg

 def test_content_arg_type_mismatch_optional_arg(self):
     "Request JSON optional arguments contain data which doesn't match expected type."
     test_request = DummyRequest()
     test_request.setHeader("Content-Type", "application/json; charset=utf-8")
     test_request.write(json.dumps({"arg1" : 1}))
     outer_wrap = webapi.json_arguments([("arg1", unicode, True)])
     inner_wrap = outer_wrap(self.dummy_render_func)
     self.assertEqual(str(webapi.ValueError(test_request, "arg1", "Must be of type unicode")),
                      inner_wrap(self, test_request))
开发者ID:notoriousno,项目名称:shiji,代码行数:9,代码来源:test_webapi.py

示例14: test_content_not_dict

 def test_content_not_dict(self):
     "Request content contained in a dictionary/hash."
     test_request = DummyRequest()
     test_request.setHeader("Content-Type", "application/json; charset=utf-8")
     test_request.write(json.dumps("not a dict"))
     outer_wrap = webapi.json_arguments([("arg1", unicode)])
     inner_wrap = outer_wrap(self.dummy_render_func)
     self.assertEqual(str(webapi.RequestNotHashError(test_request)),
                      inner_wrap(self, test_request))
开发者ID:notoriousno,项目名称:shiji,代码行数:9,代码来源:test_webapi.py

示例15: test_content_type_content_type_mismatch

 def test_content_type_content_type_mismatch(self):
     "Request Content-Type doesn't match expected type."
     test_request = DummyRequest()
     test_request.setHeader("Content-Type", "image/jpeg; charset=utf-8")
     outer_wrap = webapi.json_arguments([("arg1", unicode)],
                                        content_type="application/json")
     inner_wrap = outer_wrap(self.dummy_render_func)
     self.assertEqual(str(webapi.ContentTypeError(test_request)),
                      inner_wrap(self, test_request))
开发者ID:notoriousno,项目名称:shiji,代码行数:9,代码来源:test_webapi.py


注:本文中的shiji.testutil.DummyRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。