本文整理汇总了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")
示例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)
示例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)
示例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')
示例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)
示例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)
示例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)
示例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])
示例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)
示例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)
示例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]')
示例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)
示例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)
示例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')
示例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]')