Implement straightforward GET test.
authorEmil Mikulic <emikulic@gmail.com>
Sun, 1 May 2011 08:13:41 +0000 (18:13 +1000)
committerEmil Mikulic <emikulic@gmail.com>
Sun, 28 Apr 2013 10:56:37 +0000 (20:56 +1000)
devel/test.py

index 8aedb4d..58007fa 100755 (executable)
@@ -4,6 +4,7 @@ import socket
 import signal
 import re
 import os
 import signal
 import re
 import os
+import random
 
 WWWROOT = "tmp.httpd.tests"
 
 
 WWWROOT = "tmp.httpd.tests"
 
@@ -150,6 +151,26 @@ def setUpModule():
         ]:
         makeSimpleCases(*args)
 
         ]:
         makeSimpleCases(*args)
 
+class TestFileGet(TestHelper):
+    def setUp(self):
+        self.datalen = 2345
+        self.data = "".join(
+            [chr(random.randint(0,255)) for _ in xrange(self.datalen)])
+        self.url = "/data.jpeg"
+        self.fn = WWWROOT + self.url
+        open(self.fn, "w").write(self.data)
+
+    def tearDown(self):
+        os.unlink(self.fn)
+
+    def test_file_get(self):
+        resp = Conn().get(self.url)
+        status, hdrs, body = parse(resp)
+        self.assertContains(status, "200 OK")
+        self.assertEquals(hdrs["Content-Length"], str(self.datalen))
+        self.assertEquals(hdrs["Content-Type"], "image/jpeg")
+        self.assertEquals(body, self.data)
+
 if __name__ == '__main__':
     setUpModule()
     unittest.main()
 if __name__ == '__main__':
     setUpModule()
     unittest.main()