本文整理匯總了Python中shiji.testutil.DummyRequest.setHeader方法的典型用法代碼示例。如果您正苦於以下問題:Python DummyRequest.setHeader方法的具體用法?Python DummyRequest.setHeader怎麽用?Python DummyRequest.setHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類shiji.testutil.DummyRequest
的用法示例。
在下文中一共展示了DummyRequest.setHeader方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_json_validate_success
# 需要導入模塊: from shiji.testutil import DummyRequest [as 別名]
# 或者: from shiji.testutil.DummyRequest import setHeader [as 別名]
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")
示例2: test_get_child_route_no_api_match
# 需要導入模塊: from shiji.testutil import DummyRequest [as 別名]
# 或者: from shiji.testutil.DummyRequest import setHeader [as 別名]
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))
示例3: test_content_type_charset_not_utf8
# 需要導入模塊: from shiji.testutil import DummyRequest [as 別名]
# 或者: from shiji.testutil.DummyRequest import setHeader [as 別名]
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))
示例4: test_content_type_no_charset
# 需要導入模塊: from shiji.testutil import DummyRequest [as 別名]
# 或者: from shiji.testutil.DummyRequest import setHeader [as 別名]
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))
示例5: test_get_child_version_unknown
# 需要導入模塊: from shiji.testutil import DummyRequest [as 別名]
# 或者: from shiji.testutil.DummyRequest import setHeader [as 別名]
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))
示例6: test_content_type_content_type_mismatch
# 需要導入模塊: from shiji.testutil import DummyRequest [as 別名]
# 或者: from shiji.testutil.DummyRequest import setHeader [as 別名]
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))
示例7: test_content_required_arg_missing_optional_flag_false
# 需要導入模塊: from shiji.testutil import DummyRequest [as 別名]
# 或者: from shiji.testutil.DummyRequest import setHeader [as 別名]
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))
示例8: test_content_arg_type_mismatch_optional_arg
# 需要導入模塊: from shiji.testutil import DummyRequest [as 別名]
# 或者: from shiji.testutil.DummyRequest import setHeader [as 別名]
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))
示例9: test_content_not_dict
# 需要導入模塊: from shiji.testutil import DummyRequest [as 別名]
# 或者: from shiji.testutil.DummyRequest import setHeader [as 別名]
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))
示例10: test_content_invalid_json
# 需要導入模塊: from shiji.testutil import DummyRequest [as 別名]
# 或者: from shiji.testutil.DummyRequest import setHeader [as 別名]
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))
示例11: test_get_child_no_route_match
# 需要導入模塊: from shiji.testutil import DummyRequest [as 別名]
# 或者: from shiji.testutil.DummyRequest import setHeader [as 別名]
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))
示例12: test_get_child_route_match_api_match
# 需要導入模塊: from shiji.testutil import DummyRequest [as 別名]
# 或者: from shiji.testutil.DummyRequest import setHeader [as 別名]
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)
示例13: test_get_bad_header
# 需要導入模塊: from shiji.testutil import DummyRequest [as 別名]
# 或者: from shiji.testutil.DummyRequest import setHeader [as 別名]
def test_get_bad_header(self):
"Test unknown version return error code & message via GET"
request = DummyRequest(api_mode="", api_version="", api_name="")
request.setHeader("X-DigiTar-API-Version", "dummyapi")
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,
"dummyapi")))
示例14: test_post
# 需要導入模塊: from shiji.testutil import DummyRequest [as 別名]
# 或者: from shiji.testutil.DummyRequest import setHeader [as 別名]
def test_post(self):
"Test unknown API call return error code & message via POST"
request = DummyRequest(api_mode="", api_version="", api_name="")
request.setHeader("X-DigiTar-API-Version", "dummyapi")
request.uri = "dummy.com/dummyapi/call"
resource = urldispatch.UnknownCall()
body = resource.render_POST(request)
self.assertEquals(request.response_code, 404)
self.assertEquals(request.getHeader("Content-Type"),
"application/json; charset=utf-8")
self.assertEquals(body, str(webapi.UnknownAPICallError(request,
"call")))
示例15: test_get_options
# 需要導入模塊: from shiji.testutil import DummyRequest [as 別名]
# 或者: from shiji.testutil.DummyRequest import setHeader [as 別名]
def test_get_options(self):
"Test OPTIONS request."
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.method = "OPTIONS"
request.setHeader("Access-Control-Request-Headers", "Content-Type")
router = urldispatch.APIRouter(route_map, config=api_config, cross_origin_domains="*")
resource = router.getChild("/example/", request)
self.assertTrue(isinstance(resource, urldispatch.CORSInterrogation))
resource.render_OPTIONS(request)
self.assertEquals(request.getHeader("Content-Type"),
"application/json; charset=utf-8")
self.assertEquals(request.getHeader("Access-Control-Allow-Origin"),
"*")
self.assertEquals(request.getHeader("Access-Control-Allow-Credentials"),
"true")
self.assertEquals(request.getHeader("Access-Control-Allow-Headers"),
"Content-Type")
self.assertEquals(request.getHeader("Access-Control-Allow-Methods"),
"PUT,GET,DELETE,POST,HEAD,TRACE,CONNECT,PROPFIND,PROPPATCH,MKCOL,COPY,MOVE,LOCK,UNLOCK")