darkhttpd/devel/test_mimemap.py

43 lines
1.4 KiB
Python
Raw Normal View History

2021-01-17 09:29:23 +03:00
#!/usr/bin/env python3
2016-01-23 12:05:02 +03:00
# This is run by the "run-tests" script.
2013-06-10 14:41:46 +04:00
import unittest
import os
from test import WWWROOT, TestHelper, Conn, parse
class TestMimemap(TestHelper):
def setUp(self):
2021-01-17 09:29:23 +03:00
self.data = b'hello\n'
2013-06-10 14:41:46 +04:00
self.datalen = len(self.data)
self.files = [ ("test-file.a1", "test/type1"),
("test-file.ap2", "test/type2"),
("test-file.app3", "test/type3"),
2015-05-19 14:40:26 +03:00
("test-file.appp4", "test/default") ]
2013-06-10 14:41:46 +04:00
for fn, _ in self.files:
2021-01-17 09:29:23 +03:00
with open(WWWROOT + "/" + fn, 'wb') as f:
f.write(self.data)
2013-06-10 14:41:46 +04:00
def tearDown(self):
for fn, _ in self.files:
os.unlink(WWWROOT + "/" + fn)
def get_helper(self, idx):
fn, content_type = self.files[idx]
2021-01-17 09:29:23 +03:00
resp = self.get("/" + fn)
2013-06-10 14:41:46 +04:00
status, hdrs, body = parse(resp)
self.assertContains(status, "200 OK")
2021-01-17 09:29:23 +03:00
self.assertEqual(hdrs["Accept-Ranges"], "bytes")
self.assertEqual(hdrs["Content-Length"], str(self.datalen))
self.assertEqual(hdrs["Content-Type"], content_type)
2013-06-10 14:41:46 +04:00
self.assertContains(hdrs["Server"], "darkhttpd/")
2021-01-17 09:29:23 +03:00
self.assertEqual(body, self.data)
2013-06-10 14:41:46 +04:00
def test_get_1(self): self.get_helper(0)
def test_get_2(self): self.get_helper(1)
def test_get_3(self): self.get_helper(2)
def test_get_4(self): self.get_helper(3)
if __name__ == '__main__':
unittest.main()
# vim:set ts=4 sw=4 et: