本文整理汇总了Python中shiji.testutil.DummyRequest.getHeader方法的典型用法代码示例。如果您正苦于以下问题:Python DummyRequest.getHeader方法的具体用法?Python DummyRequest.getHeader怎么用?Python DummyRequest.getHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shiji.testutil.DummyRequest
的用法示例。
在下文中一共展示了DummyRequest.getHeader方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_no_header
# 需要导入模块: from shiji.testutil import DummyRequest [as 别名]
# 或者: from shiji.testutil.DummyRequest import getHeader [as 别名]
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,
"")))
示例2: test_post
# 需要导入模块: from shiji.testutil import DummyRequest [as 别名]
# 或者: from shiji.testutil.DummyRequest import getHeader [as 别名]
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,
"")))
示例3: test_options_request_no_acrh
# 需要导入模块: from shiji.testutil import DummyRequest [as 别名]
# 或者: from shiji.testutil.DummyRequest import getHeader [as 别名]
def test_options_request_no_acrh(self):
"Test an OPTIONS request w/ no supplied Access-Control-Request-Headers header."
route_map = [(r"^/example/", dummy_api)]
api_config = {"arg1" : True, "arg2" : 42}
router = urldispatch.APIRouter(route_map, config=api_config, cross_origin_domains="*")
request = DummyRequest(api_mode="", api_version="", api_name="")
resource = urldispatch.CORSInterrogation(request, api_router=router)
body = resource.render_OPTIONS(request)
self.assertEquals(request.response_code, 200)
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"),
"Access-Control-Allow-Origin,Content-Type")
self.assertEquals(request.getHeader("Access-Control-Allow-Methods"),
"PUT,GET,DELETE,POST,HEAD,TRACE,CONNECT,PROPFIND,PROPPATCH,MKCOL,COPY,MOVE,LOCK,UNLOCK")
self.assertEquals(body, "")
示例4: test_invalid_credentials
# 需要导入模块: from shiji.testutil import DummyRequest [as 别名]
# 或者: from shiji.testutil.DummyRequest import getHeader [as 别名]
def test_invalid_credentials(self):
"Invalid HTTP BasicAuth credentials."
test_request = DummyRequest(user="baduser", password="badpass")
outer_wrap = webapi.auth_http_basic(auth_test)
inner_wrap = outer_wrap(self.dummy_render_func)
inner_wrap(self, test_request)
self.assertEqual(test_request.response_code, 401)
self.assertEqual(test_request.getHeader("WWW-Authenticate"),
'Basic realm="Shiji"')
self.assertEqual(str(webapi.AccessDeniedError(test_request)),
test_request.content.getvalue())
示例5: test_get_options
# 需要导入模块: from shiji.testutil import DummyRequest [as 别名]
# 或者: from shiji.testutil.DummyRequest import getHeader [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")
示例6: URLMatchJSONResourceTestCase
# 需要导入模块: from shiji.testutil import DummyRequest [as 别名]
# 或者: from shiji.testutil.DummyRequest import getHeader [as 别名]
class URLMatchJSONResourceTestCase(unittest.TestCase):
def setUp(self):
self.request = DummyRequest(api_mode="", api_version="", api_name="")
self.route_map = [("^/test/me/(?P<group1>.+)", object())]
def test_init_resource(self):
"Verify URLMatchJSONResource is correctly initialized."
phony_call_router = object()
res = urldispatch.URLMatchJSONResource(self.request,
url_matches=self.route_map,
call_router=phony_call_router)
self.assertEquals(self.route_map,
res.url_matches)
self.assertEquals(phony_call_router,
res.call_router)
def test_render_no_deferred(self):
"Render function w/ non-deferred return."
def render_GET(request):
return "test123"
phony_call_router = object()
res = urldispatch.URLMatchJSONResource(self.request,
url_matches=self.route_map,
call_router=phony_call_router)
res.render_GET = render_GET
ret_res = res.render(self.request)
self.assertEqual("test123", ret_res)
def test_render_no_deferred_failed(self):
"Render function w/ failed non-deferred return."
def render_GET(request):
raise Exception("Unexpected catastrophe!")
return "test123"
phony_call_router = object()
res = urldispatch.URLMatchJSONResource(self.request,
url_matches=self.route_map,
call_router=phony_call_router)
res.render_GET = render_GET
ret_res = res.render(self.request)
actual_response = json.loads(ret_res)
self.assertEqual(actual_response["error"]["exception_class"], "UnexpectedServerError")
self.assertEqual(actual_response["error"]["error_code"], 505)
self.assertTrue("Unexpected catastrophe!" in actual_response["error"]["exception_text"])
def test_render_cors(self):
"Render function w/ non-deferred return & Access-Request-Allow-Origin header."
def render_GET(request):
return "test123"
phony_call_router = object()
self.request.method = "GET"
res = urldispatch.URLMatchJSONResource(self.request,
url_matches=self.route_map,
call_router=phony_call_router)
res.render_GET = render_GET
ret_res = res.render(self.request)
self.assertEqual("test123", ret_res)
def test_render_nonnull_deferred_success(self):
"Non-null render function w/ successful deferred return."
d = defer.Deferred()
def render_GET(request):
return d
phony_api_router = type('obj', (object,), {'cross_origin_domains' : '*', 'inhibit_http_caching' : True})
phony_version_router = type('obj', (object,), {'api_router' : phony_api_router})
phony_call_router = type('obj', (object,), {'version_router' : phony_version_router})
res = urldispatch.URLMatchJSONResource(self.request,
url_matches=self.route_map,
call_router=phony_call_router)
res.render_GET = render_GET
ret_res = res.render(self.request)
self.assertEqual(NOT_DONE_YET, ret_res)
d.callback("heya")
self.assertEqual("*", self.request.getHeader("Access-Control-Allow-Origin"))
self.assertEquals("true", self.request.getHeader("Access-Control-Allow-Credentials"))
self.assertEquals("no-cache", self.request.getHeader("Cache-Control"))
self.assertEquals("no-cache", self.request.getHeader("Pragma"))
self.assertEqual("heya",
self.request.content.getvalue())
def test_render_null_deferred_success(self):
"Null render function w/ successful deferred return."
d = defer.Deferred()
def render_GET(request):
return d
phony_call_router = object()
res = urldispatch.URLMatchJSONResource(self.request,
url_matches=self.route_map,
#.........这里部分代码省略.........