当前位置: 首页>>代码示例>>Python>>正文


Python testutil.FakeRequest类代码示例

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


在下文中一共展示了FakeRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_prePathURLHost

 def test_prePathURLHost(self):
     """
     Verify that L{FakeRequest.prePathURL} will turn the C{Host} header of
     the request into the netloc of the returned URL, if it's present.
     """
     req = FakeRequest(currentSegments=["a", "b"], uri="/a/b/c/", headers={"host": "foo.bar"})
     self.assertEqual(req.prePathURL(), "http://foo.bar/a/b")
开发者ID:mithrandi,项目名称:nevow,代码行数:7,代码来源:test_testutil.py

示例2: test_setResponseCode

 def test_setResponseCode(self):
     """
     Test that the response code of a fake request can be set.
     """
     req = FakeRequest()
     req.setResponseCode(BAD_REQUEST)
     self.assertEqual(req.code, BAD_REQUEST)
开发者ID:UstadMobile,项目名称:exelearning-ustadmobile-work,代码行数:7,代码来源:test_testutil.py

示例3: test_missingContentMD5

 def test_missingContentMD5(self):
     """
     Submitting a request with no Content-MD5 header should succeed.
     """
     req = FakeRequest()
     req.content = StringIO('wrongdata')
     return self.creator.handlePUT(req)
开发者ID:fusionapp,项目名称:entropy,代码行数:7,代码来源:test_store.py

示例4: test_prePathURL

 def test_prePathURL(self):
     """
     Verify that L{FakeRequest.prePathURL} returns the prepath of the
     requested URL.
     """
     req = FakeRequest(currentSegments=['a'], uri='/a/b')
     self.assertEqual(req.prePathURL(), 'http://localhost/a')
开发者ID:UstadMobile,项目名称:exelearning-ustadmobile-work,代码行数:7,代码来源:test_testutil.py

示例5: test_smashInitialHeaderCase

 def test_smashInitialHeaderCase(self):
     """
     L{FakeRequest.getHeader} will return the value of a header specified to
     L{FakeRequest.__init__} even if the header names have differing case.
     """
     host = 'example.com'
     request = FakeRequest(headers={'HoSt': host})
     self.assertEqual(request.getHeader('hOsT'), host)
开发者ID:UstadMobile,项目名称:exelearning-ustadmobile-work,代码行数:8,代码来源:test_testutil.py

示例6: test_caseInsensitiveHeaders

 def test_caseInsensitiveHeaders(self):
     """
     L{FakeRequest.getHeader} will return the value of a header regardless
     of casing.
     """
     host = 'example.com'
     request = FakeRequest()
     request.received_headers['host'] = host
     self.assertEqual(request.getHeader('hOsT'), host)
开发者ID:UstadMobile,项目名称:exelearning-ustadmobile-work,代码行数:9,代码来源:test_testutil.py

示例7: test_headers

 def test_headers(self):
     """
     Check that setting a header with L{FakeRequest.setHeader} actually
     places it in the headers dictionary.
     """
     host = 'divmod.com'
     req = FakeRequest()
     req.setHeader('host', host)
     self.assertEqual(req.headers['host'], host)
开发者ID:UstadMobile,项目名称:exelearning-ustadmobile-work,代码行数:9,代码来源:test_testutil.py

示例8: test_headers

 def test_headers(self):
     """
     Check that setting a header with L{FakeRequest.setHeader} actually
     places it in the headers dictionary.
     """
     host = "divmod.com"
     req = FakeRequest()
     req.setHeader("host", host)
     self.assertEqual(req.responseHeaders.getRawHeaders("host"), [host])
开发者ID:mithrandi,项目名称:nevow,代码行数:9,代码来源:test_testutil.py

示例9: test_incorrectContentMD5

 def test_incorrectContentMD5(self):
     """
     Submitting a request with a Content-MD5 header that disagrees with the
     uploaded data should fail.
     """
     req = FakeRequest()
     req.received_headers['content-md5'] = '72VMQKtPF0f8aZkV1PcJAg=='
     req.content = StringIO('wrongdata')
     self.assertRaises(ValueError, self.creator.handlePUT, req)
开发者ID:fusionapp,项目名称:entropy,代码行数:9,代码来源:test_store.py

示例10: test_correctContentMD5

 def test_correctContentMD5(self):
     """
     Submitting a request with a Content-MD5 header that agrees with the
     uploaded data should succeed.
     """
     req = FakeRequest()
     req.received_headers['content-md5'] = '72VMQKtPF0f8aZkV1PcJAg=='
     req.content = StringIO('testdata')
     return self.creator.handlePUT(req)
开发者ID:fusionapp,项目名称:entropy,代码行数:9,代码来源:test_store.py

示例11: test_domainSpecified

 def test_domainSpecified(self):
     """
     Test that L{usernameFromRequest} returns the username in the request
     if that username specifies a domain.
     """
     request = FakeRequest(headers={'host': 'divmod.com'})
     request.args = {'username': ['[email protected]']}
     username = usernameFromRequest(request)
     self.assertEqual(username, '[email protected]')
开发者ID:twisted,项目名称:mantissa,代码行数:9,代码来源:test_websession.py

示例12: render2

 def render2(self, page, **kwargs):
     # use this to exercise the normal Nevow docFactory rendering. It
     # returns a string. If one of the render_* methods returns a
     # Deferred, this will throw an exception. (note that
     # page.renderString is the Deferred-returning equivalent)
     req = FakeRequest(**kwargs)
     req.fields = None
     ctx = self.make_context(req)
     return page.renderSynchronously(ctx)
开发者ID:ArtRichards,项目名称:tahoe-lafs,代码行数:9,代码来源:common_web.py

示例13: test_caseInsensitiveHeaders

 def test_caseInsensitiveHeaders(self):
     """
     L{FakeRequest.getHeader} will return the value of a header regardless
     of casing.
     """
     host = "example.com"
     request = FakeRequest()
     request.requestHeaders.setRawHeaders("host", [host])
     self.assertEqual(request.getHeader("hOsT"), host)
开发者ID:mithrandi,项目名称:nevow,代码行数:9,代码来源:test_testutil.py

示例14: test_prePathURLHost

 def test_prePathURLHost(self):
     """
     Verify that L{FakeRequest.prePathURL} will turn the C{Host} header of
     the request into the netloc of the returned URL, if it's present.
     """
     req = FakeRequest(currentSegments=['a', 'b'],
                       uri='/a/b/c/',
                       headers={'host': 'foo.bar'})
     self.assertEqual(req.prePathURL(), 'http://foo.bar/a/b')
开发者ID:UstadMobile,项目名称:exelearning-ustadmobile-work,代码行数:9,代码来源:test_testutil.py

示例15: test_domainUnspecified

 def test_domainUnspecified(self):
     """
     Test that L{usernameFromRequest} adds the value of host header to the
     username in the request if the username doesn't already specify a
     domain.
     """
     request = FakeRequest(headers={'host': 'divmod.com'})
     request.args = {'username': ['joe']}
     username = usernameFromRequest(request)
     self.assertEqual(username, '[email protected]')
开发者ID:twisted,项目名称:mantissa,代码行数:10,代码来源:test_websession.py


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