• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python testutil.FakeRequest类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: test_savorSessionCookie

    def test_savorSessionCookie(self):
        """
        L{PersistentSessionWrapper.savorSessionCookie} adds a cookie with a
        large maximum age and a request-appropriate domain to the request.
        """
        request = FakeRequest(headers={"host": "example.com"})
        resource = PersistentSessionWrapper(None, None, domains=["example.org", "example.com"])

        resource.savorSessionCookie(request)
        self.assertEqual(request.cookies, {resource.cookieKey: request.getSession().uid})
开发者ID:fusionapp,项目名称:mantissa,代码行数:10,代码来源:test_websession.py


示例17: test_getRootURL

 def test_getRootURL(self):
     """
     L{FakeRequest.getRootURL} returns C{None} when
     L{FakeRequest.rememberRootURL} has not yet been called.  After
     L{FakeRequest.rememberRootURL} has been called,
     L{FakeRequest.getRootURL} returns the value which was passed to it.
     """
     request = FakeRequest()
     self.assertIdentical(request.getRootURL(), None)
     request.rememberRootURL("foo/bar")
     self.assertEqual(request.getRootURL(), "foo/bar")
开发者ID:UstadMobile,项目名称:exelearning-ustadmobile-work,代码行数:11,代码来源:test_testutil.py


示例18: test_rendering

 def test_rendering(self):
     """
     L{AddBlogPostDialogFragment} can be rendered as part of a Mantissa
     public Athena page.
     """
     page = PublicAthenaLivePage(self.store, self.fragment, None, None)
     request = FakeRequest()
     request.args = {'title': ['foo'],
                     'body': ['bar'],
                     'url': ['baz']}
     return renderLivePage(page, reqFactory=lambda: request)
开发者ID:pombredanne,项目名称:hyperbola,代码行数:11,代码来源:test_view.py


示例19: test_headerSeparation

    def test_headerSeparation(self):
        """
        Request headers and response headers are different things.

        Test that they are handled separately.
        """
        req = FakeRequest()
        req.setHeader("foo", "bar")
        self.assertFalse(req.requestHeaders.hasHeader("foo"))
        self.assertEqual(req.getHeader("foo"), None)
        req.requestHeaders.setRawHeaders("foo", ["bar"])
        self.assertEqual(req.getHeader("foo"), "bar")
开发者ID:mithrandi,项目名称:nevow,代码行数:12,代码来源:test_testutil.py


示例20: render1

 def render1(self, page, **kwargs):
     # use this to exercise an overridden renderHTTP, usually for
     # output=json or render_GET. It always returns a Deferred.
     req = FakeRequest(**kwargs)
     req.fields = None
     ctx = self.make_context(req)
     d = defer.maybeDeferred(page.renderHTTP, ctx)
     def _done(res):
         if isinstance(res, str):
             return res + req.v
         return req.v
     d.addCallback(_done)
     return d
开发者ID:ArtRichards,项目名称:tahoe-lafs,代码行数:13,代码来源:common_web.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python url.URL类代码示例发布时间:2022-05-27
下一篇:
Python tags.xml函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap