Add test for --mimetypes
[darkhttpd] / devel / test_mimemap.py
1 #!/usr/bin/env python
2 # This is run by the "cover" script.
3 import unittest
4 import os
5 from test import WWWROOT, TestHelper, Conn, parse
6
7 class TestMimemap(TestHelper):
8 def setUp(self):
9 self.data = "hello\n"
10 self.datalen = len(self.data)
11 self.files = [ ("test-file.a1", "test/type1"),
12 ("test-file.ap2", "test/type2"),
13 ("test-file.app3", "test/type3"),
14 ("test-file.appp4", "application/octet-stream") ]
15 for fn, _ in self.files:
16 open(WWWROOT + "/" + fn, "w").write(self.data)
17
18 def tearDown(self):
19 for fn, _ in self.files:
20 os.unlink(WWWROOT + "/" + fn)
21
22 def get_helper(self, idx):
23 fn, content_type = self.files[idx]
24 resp = Conn().get("/" + fn)
25 status, hdrs, body = parse(resp)
26 self.assertContains(status, "200 OK")
27 self.assertEquals(hdrs["Accept-Ranges"], "bytes")
28 self.assertEquals(hdrs["Content-Length"], str(self.datalen))
29 self.assertEquals(hdrs["Content-Type"], content_type)
30 self.assertContains(hdrs["Server"], "darkhttpd/")
31 self.assertEquals(body, self.data)
32
33 def test_get_1(self): self.get_helper(0)
34 def test_get_2(self): self.get_helper(1)
35 def test_get_3(self): self.get_helper(2)
36 def test_get_4(self): self.get_helper(3)
37
38 if __name__ == '__main__':
39 unittest.main()
40
41 # vim:set ts=4 sw=4 et: