/usr/lib/python2.7/dist-packages/nevow/test/test_static.py is in python-nevow 0.14.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | from twisted.trial import unittest
import os
from nevow import static, util, context, testutil
def deferredRender(res, req):
d = util.maybeDeferred(res.renderHTTP,
context.PageContext(
tag=res, parent=context.RequestContext(
tag=req)))
def done(result):
if isinstance(result, str):
req.write(result)
return req
d.addCallback(done)
return d
class Range(unittest.TestCase):
def setUp(self):
self.tmpdir = self.mktemp()
os.mkdir(self.tmpdir)
name = os.path.join(self.tmpdir, 'junk')
f = file(name, 'w')
f.write(800 * '0123456789')
f.close()
self.file = static.File(name)
self.request = testutil.FakeRequest()
def testBodyLength(self):
self.request.requestHeaders.setRawHeaders('range', ['bytes=0-1999'])
return deferredRender(self.file, self.request).addCallback(
lambda r: self.assertEquals(len(r.v), 2000))
def testBodyContent(self):
self.request.requestHeaders.setRawHeaders('range', ['bytes=0-1999'])
return deferredRender(self.file, self.request).addCallback(
lambda r: self.assertEquals(r.v, 200 * '0123456789'))
def testContentLength(self):
"""Content-Length of a request is correct."""
self.request.requestHeaders.setRawHeaders('range', ['bytes=0-1999'])
return deferredRender(self.file, self.request).addCallback(
lambda r: self.assertEquals(
r.responseHeaders.getRawHeaders('content-length'), ['2000']))
def testContentRange(self):
"""Content-Range of a request is correct."""
self.request.requestHeaders.setRawHeaders('range', ['bytes=0-1999'])
return deferredRender(self.file, self.request).addCallback(
lambda r: self.assertEquals(
r.responseHeaders.getRawHeaders('content-range'),
['bytes 0-1999/8000']))
def testBodyLength_offset(self):
self.request.requestHeaders.setRawHeaders('range', ['bytes=3-10'])
return deferredRender(self.file, self.request).addCallback(
lambda r: self.assertEquals(len(r.v), 8))
def testBodyContent_offset(self):
self.request.requestHeaders.setRawHeaders('range', ['bytes=3-10'])
return deferredRender(self.file, self.request).addCallback(
lambda r: self.assertEquals(r.v, '34567890'))
def testContentLength_offset(self):
"""Content-Length of a request is correct."""
self.request.requestHeaders.setRawHeaders('range', ['bytes=3-10'])
return deferredRender(self.file, self.request).addCallback(
lambda r: self.assertEquals(
r.responseHeaders.getRawHeaders('content-length'), ['8']))
def testContentRange_offset(self):
"""Content-Range of a request is correct."""
self.request.requestHeaders.setRawHeaders('range', ['bytes=3-10'])
return deferredRender(self.file, self.request).addCallback(
lambda r: self.assertEquals(
r.responseHeaders.getRawHeaders('content-range'),
['bytes 3-10/8000']))
def testBodyLength_end(self):
self.request.requestHeaders.setRawHeaders('range', ['bytes=7991-7999'])
return deferredRender(self.file, self.request).addCallback(
lambda r: self.assertEquals(len(r.v), 9))
def testBodyContent_end(self):
self.request.requestHeaders.setRawHeaders('range', ['bytes=7991-7999'])
return deferredRender(self.file, self.request).addCallback(
lambda r: self.assertEquals(r.v, '123456789'))
def testContentLength_end(self):
self.request.requestHeaders.setRawHeaders('range', ['bytes=7991-7999'])
return deferredRender(self.file, self.request).addCallback(
lambda r: self.assertEquals(
r.responseHeaders.getRawHeaders('content-length'), ['9']))
def testContentRange_end(self):
self.request.requestHeaders.setRawHeaders('range', ['bytes=7991-7999'])
return deferredRender(self.file, self.request).addCallback(
lambda r: self.assertEquals(
r.responseHeaders.getRawHeaders('content-range'),
['bytes 7991-7999/8000']))
def testBodyLength_openEnd(self):
self.request.requestHeaders.setRawHeaders('range', ['bytes=7991-'])
return deferredRender(self.file, self.request).addCallback(
lambda r: self.assertEquals(len(r.v), 9))
def testBodyContent_openEnd(self):
self.request.requestHeaders.setRawHeaders('range', ['bytes=7991-'])
return deferredRender(self.file, self.request).addCallback(
lambda r: self.assertEquals(r.v, '123456789'))
def testContentLength_openEnd(self):
self.request.requestHeaders.setRawHeaders('range', ['bytes=7991-'])
return deferredRender(self.file, self.request).addCallback(
lambda r: self.assertEquals(
r.responseHeaders.getRawHeaders('content-length'), ['9']))
def testContentRange_openEnd(self):
self.request.requestHeaders.setRawHeaders('range', ['bytes=7991-'])
return deferredRender(self.file, self.request).addCallback(
lambda r: self.assertEquals(
r.responseHeaders.getRawHeaders('content-range'),
['bytes 7991-7999/8000']))
def testBodyLength_fullRange(self):
self.request.requestHeaders.setRawHeaders('range', ['bytes=0-'])
return deferredRender(self.file, self.request).addCallback(
lambda r: self.assertEquals(len(r.v), 8000))
def testBodyContent_fullRange(self):
self.request.requestHeaders.setRawHeaders('range', ['bytes=0-'])
return deferredRender(self.file, self.request).addCallback(
lambda r: self.assertEquals(r.v, 800 * '0123456789'))
def testContentLength_fullRange(self):
self.request.requestHeaders.setRawHeaders('range', ['bytes=0-'])
return deferredRender(self.file, self.request).addCallback(
lambda r: self.assertEquals(
r.responseHeaders.getRawHeaders('content-length'), ['8000']))
def testContentRange_fullRange(self):
self.request.requestHeaders.setRawHeaders('range', ['bytes=0-'])
return deferredRender(self.file, self.request).addCallback(
lambda r: self.assertEquals(
r.responseHeaders.getRawHeaders('content-range'),
['bytes 0-7999/8000']))
|