當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。