當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。