當前位置: 首頁>>代碼示例>>Python>>正文


Python DummyRequest.getHeader方法代碼示例

本文整理匯總了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,
                                                               "")))
開發者ID:notoriousno,項目名稱:shiji,代碼行數:11,代碼來源:test_urldispatch.py

示例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,
                                                               "")))
開發者ID:notoriousno,項目名稱:shiji,代碼行數:12,代碼來源:test_urldispatch.py

示例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, "")
開發者ID:notoriousno,項目名稱:shiji,代碼行數:22,代碼來源:test_urldispatch.py

示例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())
開發者ID:notoriousno,項目名稱:shiji,代碼行數:13,代碼來源:test_webapi.py

示例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")
開發者ID:notoriousno,項目名稱:shiji,代碼行數:23,代碼來源:test_urldispatch.py

示例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,
#.........這裏部分代碼省略.........
開發者ID:notoriousno,項目名稱:shiji,代碼行數:103,代碼來源:test_urldispatch.py


注:本文中的shiji.testutil.DummyRequest.getHeader方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。