Test for HEAD method.
authorEmil Mikulic <emikulic@gmail.com>
Sun, 1 May 2011 08:15:56 +0000 (18:15 +1000)
committerEmil Mikulic <emikulic@gmail.com>
Sun, 28 Apr 2013 10:56:46 +0000 (20:56 +1000)
devel/test.py

index 58007fa..169f225 100755 (executable)
@@ -15,8 +15,8 @@ class Conn:
         self.s.connect(("0.0.0.0", self.port))
         # connect throws socket.error on connection refused
 
-    def get(self, url, http_ver="1.0", endl="\n", req_hdrs={}):
-        req = "GET "+url
+    def get(self, url, http_ver="1.0", endl="\n", req_hdrs={}, method="GET"):
+        req = method+" "+url
         if http_ver is not None:
             req += " HTTP/"+http_ver
         req += endl
@@ -171,6 +171,13 @@ class TestFileGet(TestHelper):
         self.assertEquals(hdrs["Content-Type"], "image/jpeg")
         self.assertEquals(body, self.data)
 
+    def test_file_head(self):
+        resp = Conn().get(self.url, method="HEAD")
+        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")
+
 if __name__ == '__main__':
     setUpModule()
     unittest.main()