diff options
-rwxr-xr-x | test.py | 41 |
1 files changed, 41 insertions, 0 deletions
@@ -204,6 +204,46 @@ class AuthDigestMiddlewareTest(unittest.TestCase): def test401authfail(self): self.doauth(password="spam", status=401) +from wsgitools import middlewares + +class StupidIO: + """file-like without tell method, so StaticFile is not able to + determine the content-length.""" + def __init__(self, content): + self.content = content + self.position = 0 + + def seek(self, pos): + assert pos == 0 + self.position = 0 + + def read(self, length): + oldpos = self.position + self.position += length + return self.content[oldpos:self.position] + +class ContentLengthMiddlewareTest(unittest.TestCase): + def setUp(self): + self.staticapp = applications.StaticFile(StupidIO("success"), + "200 Found", [("Content-Type", "text/plain")]) + self.app = middlewares.ContentLengthMiddleware(self.staticapp, + maxstore=10) + self.req = Request(self) + + def testWithout(self): + res = self.req(self.staticapp) + res.status("200 Found") + try: + res.getheader("Content-length") + self.fail("Content-length header found, test is useless") + except KeyError: + pass + + def testGet(self): + res = self.req(self.app) + res.status("200 Found") + res.header("Content-length", "7") + def alltests(case): return unittest.TestLoader().loadTestsFromTestCase(case) @@ -212,6 +252,7 @@ fullsuite.addTest(doctest.DocTestSuite("wsgitools.digest")) fullsuite.addTest(alltests(StaticContentTest)) fullsuite.addTest(alltests(StaticFileTest)) fullsuite.addTest(alltests(AuthDigestMiddlewareTest)) +fullsuite.addTest(alltests(ContentLengthMiddlewareTest)) if __name__ == "__main__": runner = unittest.TextTestRunner(verbosity=2) |