• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python testutil.DummyRequest类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: test_content_invalid_json

 def test_content_invalid_json(self):
     "Request content not valid JSON."
     test_request = DummyRequest()
     test_request.setHeader("Content-Type", "application/json; charset=utf-8")
     test_request.write("boingo! bad json!")
     outer_wrap = webapi.json_arguments([("arg1", unicode)])
     inner_wrap = outer_wrap(self.dummy_render_func)
     self.assertEqual(str(webapi.JSONDecodeError(test_request)),
                      inner_wrap(self, test_request))
开发者ID:notoriousno,项目名称:shiji,代码行数:9,代码来源:test_webapi.py


示例17: test_get_no_header

 def test_get_no_header(self):
     request = DummyRequest(api_mode="", api_version="", api_name="")
     resource = urldispatch.UnknownVersion()
     body = resource.render_GET(request)
     self.assertEquals(request.response_code, 406)
     self.assertEquals(request.getHeader("Content-Type"),
                       "application/json; charset=utf-8")
     self.assertEquals(body, str(webapi.UnknownAPIVersionError(request,
                                                               "")))
开发者ID:notoriousno,项目名称:shiji,代码行数:9,代码来源:test_urldispatch.py


示例18: test_get_child_no_route_match

 def test_get_child_no_route_match(self):
     "Test no route match"
     route_map = [(r"^/example/", dummy_api)]
     api_config = {"arg1" : True, "arg2" : 42}
     request = DummyRequest(api_mode="prod", api_version="1.0", api_name="dummy_api")
     request.setHeader("X-DigiTar-API-Version", "dummy_api-1.0+prod")
     router = urldispatch.APIRouter(route_map, config=api_config)
     resource = router.getChild("/badmojo/", request)
     self.assertTrue(isinstance(resource, urldispatch.UnknownAPI))
开发者ID:notoriousno,项目名称:shiji,代码行数:9,代码来源:test_urldispatch.py


示例19: test_get_child_route_match_api_match

 def test_get_child_route_match_api_match(self):
     "Test route match with good API name match in version header"
     route_map = [(r"^/example/", dummy_api)]
     api_config = {"arg1" : True, "arg2" : 42}
     request = DummyRequest(api_mode="prod", api_version="1.0", api_name="dummy_api")
     request.setHeader("X-DigiTar-API-Version", "dummy_api-1.0+prod")
     router = urldispatch.APIRouter(route_map, config=api_config)
     resource = router.getChild("/example/", request)
     self.assertTrue(isinstance(resource, urldispatch.VersionRouter))
     self.assertEquals(resource.api_router, router)
开发者ID:notoriousno,项目名称:shiji,代码行数:10,代码来源:test_urldispatch.py


示例20: test_post

 def test_post(self):
     "Test unknown version return error code & message via POST"
     request = DummyRequest(api_mode="", api_version="", api_name="")
     resource = urldispatch.UnknownVersion()
     body = resource.render_POST(request)
     self.assertEquals(request.response_code, 406)
     self.assertEquals(request.getHeader("Content-Type"),
                       "application/json; charset=utf-8")
     self.assertEquals(body, str(webapi.UnknownAPIVersionError(request,
                                                               "")))
开发者ID:notoriousno,项目名称:shiji,代码行数:10,代码来源:test_urldispatch.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python configuration.ConfigManager类代码示例发布时间:2022-05-27
下一篇:
Python utils.create_job_with_details函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap