mirror of
https://github.com/emikulic/darkhttpd.git
synced 2023-08-10 21:13:08 +03:00
More Python 3 updates.
This commit is contained in:
parent
d39cc3849a
commit
b57eb17d47
@ -37,7 +37,7 @@ runtests() {
|
|||||||
>>test.out.stdout 2>>test.out.stderr &
|
>>test.out.stdout 2>>test.out.stderr &
|
||||||
PID=$!
|
PID=$!
|
||||||
kill -0 $PID || exit 1
|
kill -0 $PID || exit 1
|
||||||
python test.py
|
python3 test.py
|
||||||
kill $PID
|
kill $PID
|
||||||
wait $PID
|
wait $PID
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ runtests() {
|
|||||||
>>test.out.stdout 2>>test.out.stderr &
|
>>test.out.stdout 2>>test.out.stderr &
|
||||||
PID=$!
|
PID=$!
|
||||||
kill -0 $PID || exit 1
|
kill -0 $PID || exit 1
|
||||||
python test_forward.py
|
python3 test_forward.py
|
||||||
kill $PID
|
kill $PID
|
||||||
wait $PID
|
wait $PID
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ runtests() {
|
|||||||
>>test.out.stdout 2>>test.out.stderr &
|
>>test.out.stdout 2>>test.out.stderr &
|
||||||
PID=$!
|
PID=$!
|
||||||
kill -0 $PID || exit 1
|
kill -0 $PID || exit 1
|
||||||
python test_forward_all.py
|
python3 test_forward_all.py
|
||||||
kill $PID
|
kill $PID
|
||||||
wait $PID
|
wait $PID
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ runtests() {
|
|||||||
>>test.out.stdout 2>>test.out.stderr &
|
>>test.out.stdout 2>>test.out.stderr &
|
||||||
PID=$!
|
PID=$!
|
||||||
kill -0 $PID || exit 1
|
kill -0 $PID || exit 1
|
||||||
python test_server_id.py
|
python3 test_server_id.py
|
||||||
kill $PID
|
kill $PID
|
||||||
wait $PID
|
wait $PID
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ runtests() {
|
|||||||
>>test.out.stdout 2>>test.out.stderr &
|
>>test.out.stdout 2>>test.out.stderr &
|
||||||
PID=$!
|
PID=$!
|
||||||
kill -0 $PID || exit 1
|
kill -0 $PID || exit 1
|
||||||
python test_mimemap.py
|
python3 test_mimemap.py
|
||||||
kill $PID
|
kill $PID
|
||||||
wait $PID
|
wait $PID
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ runtests() {
|
|||||||
>>test.out.stdout 2>>test.out.stderr &
|
>>test.out.stdout 2>>test.out.stderr &
|
||||||
PID=$!
|
PID=$!
|
||||||
kill -0 $PID || exit 1
|
kill -0 $PID || exit 1
|
||||||
python test_no_listing.py
|
python3 test_no_listing.py
|
||||||
kill $PID
|
kill $PID
|
||||||
wait $PID
|
wait $PID
|
||||||
|
|
||||||
@ -102,7 +102,7 @@ runtests() {
|
|||||||
>>test.out.stdout 2>>test.out.stderr &
|
>>test.out.stdout 2>>test.out.stderr &
|
||||||
PID=$!
|
PID=$!
|
||||||
kill -0 $PID || exit 1
|
kill -0 $PID || exit 1
|
||||||
python test_timeout.py
|
python3 test_timeout.py
|
||||||
kill $PID
|
kill $PID
|
||||||
wait $PID
|
wait $PID
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ runtests() {
|
|||||||
>>test.out.stdout 2>>test.out.stderr &
|
>>test.out.stdout 2>>test.out.stderr &
|
||||||
PID=$!
|
PID=$!
|
||||||
kill -0 $PID || exit 1
|
kill -0 $PID || exit 1
|
||||||
python test_auth.py
|
python3 test_auth.py
|
||||||
kill $PID
|
kill $PID
|
||||||
wait $PID
|
wait $PID
|
||||||
|
|
||||||
|
@ -1,24 +1,23 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
# This is run by the "run-tests" script.
|
# This is run by the "run-tests" script.
|
||||||
import unittest
|
import unittest
|
||||||
from test import TestHelper, Conn, parse
|
from test import TestHelper, Conn, parse
|
||||||
|
|
||||||
class TestForward(TestHelper):
|
class TestForward(TestHelper):
|
||||||
def test_forward_root(self):
|
def test_forward_root(self):
|
||||||
resp = Conn().get("/", req_hdrs = { "Host": "example.com" })
|
resp = self.get('/', req_hdrs={'Host': 'example.com'})
|
||||||
status, hdrs, body = parse(resp)
|
status, hdrs, body = parse(resp)
|
||||||
self.assertContains(status, "301 Moved Permanently")
|
self.assertContains(status, "301 Moved Permanently")
|
||||||
expect = "http://www.example.com/"
|
expect = "http://www.example.com/"
|
||||||
self.assertEquals(hdrs["Location"], expect)
|
self.assertEqual(hdrs["Location"], expect)
|
||||||
self.assertContains(body, expect)
|
self.assertContains(body, expect)
|
||||||
|
|
||||||
def test_forward_relative(self):
|
def test_forward_relative(self):
|
||||||
resp = Conn().get("/foo/bar",
|
resp = self.get('/foo/bar', req_hdrs={'Host': 'secure.example.com'})
|
||||||
req_hdrs = { "Host": "secure.example.com" })
|
|
||||||
status, hdrs, body = parse(resp)
|
status, hdrs, body = parse(resp)
|
||||||
self.assertContains(status, "301 Moved Permanently")
|
self.assertContains(status, "301 Moved Permanently")
|
||||||
expect = "https://www.example.com/secure/foo/bar"
|
expect = "https://www.example.com/secure/foo/bar"
|
||||||
self.assertEquals(hdrs["Location"], expect)
|
self.assertEqual(hdrs["Location"], expect)
|
||||||
self.assertContains(body, expect)
|
self.assertContains(body, expect)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
# This is run by the "run-tests" script.
|
# This is run by the "run-tests" script.
|
||||||
import unittest
|
import unittest
|
||||||
from test import TestHelper, Conn, parse
|
from test import TestHelper, Conn, parse
|
||||||
|
|
||||||
class TestForwardAll(TestHelper):
|
class TestForwardAll(TestHelper):
|
||||||
def test_forward_root(self):
|
def test_forward_root(self):
|
||||||
resp = Conn().get("/", req_hdrs = { "Host": "not-example.com" })
|
resp = self.get('/', req_hdrs={'Host': 'not-example.com'})
|
||||||
status, hdrs, body = parse(resp)
|
status, hdrs, body = parse(resp)
|
||||||
self.assertContains(status, "301 Moved Permanently")
|
self.assertContains(status, "301 Moved Permanently")
|
||||||
expect = "http://catchall.example.com/"
|
expect = "http://catchall.example.com/"
|
||||||
self.assertEquals(hdrs["Location"], expect)
|
self.assertEqual(hdrs["Location"], expect)
|
||||||
self.assertContains(body, expect)
|
self.assertContains(body, expect)
|
||||||
|
|
||||||
def test_forward_relative(self):
|
def test_forward_relative(self):
|
||||||
resp = Conn().get("/foo/bar",
|
resp = self.get('/foo/bar',
|
||||||
req_hdrs = { "Host": "still-not.example.com" })
|
req_hdrs={'Host': 'still-not.example.com'})
|
||||||
status, hdrs, body = parse(resp)
|
status, hdrs, body = parse(resp)
|
||||||
self.assertContains(status, "301 Moved Permanently")
|
self.assertContains(status, "301 Moved Permanently")
|
||||||
expect = "http://catchall.example.com/foo/bar"
|
expect = "http://catchall.example.com/foo/bar"
|
||||||
self.assertEquals(hdrs["Location"], expect)
|
self.assertEqual(hdrs["Location"], expect)
|
||||||
self.assertContains(body, expect)
|
self.assertContains(body, expect)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
# This is run by the "run-tests" script.
|
# This is run by the "run-tests" script.
|
||||||
import unittest
|
import unittest
|
||||||
import os
|
import os
|
||||||
@ -6,14 +6,15 @@ from test import WWWROOT, TestHelper, Conn, parse
|
|||||||
|
|
||||||
class TestMimemap(TestHelper):
|
class TestMimemap(TestHelper):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.data = "hello\n"
|
self.data = b'hello\n'
|
||||||
self.datalen = len(self.data)
|
self.datalen = len(self.data)
|
||||||
self.files = [ ("test-file.a1", "test/type1"),
|
self.files = [ ("test-file.a1", "test/type1"),
|
||||||
("test-file.ap2", "test/type2"),
|
("test-file.ap2", "test/type2"),
|
||||||
("test-file.app3", "test/type3"),
|
("test-file.app3", "test/type3"),
|
||||||
("test-file.appp4", "test/default") ]
|
("test-file.appp4", "test/default") ]
|
||||||
for fn, _ in self.files:
|
for fn, _ in self.files:
|
||||||
open(WWWROOT + "/" + fn, "w").write(self.data)
|
with open(WWWROOT + "/" + fn, 'wb') as f:
|
||||||
|
f.write(self.data)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
for fn, _ in self.files:
|
for fn, _ in self.files:
|
||||||
@ -21,14 +22,14 @@ class TestMimemap(TestHelper):
|
|||||||
|
|
||||||
def get_helper(self, idx):
|
def get_helper(self, idx):
|
||||||
fn, content_type = self.files[idx]
|
fn, content_type = self.files[idx]
|
||||||
resp = Conn().get("/" + fn)
|
resp = self.get("/" + fn)
|
||||||
status, hdrs, body = parse(resp)
|
status, hdrs, body = parse(resp)
|
||||||
self.assertContains(status, "200 OK")
|
self.assertContains(status, "200 OK")
|
||||||
self.assertEquals(hdrs["Accept-Ranges"], "bytes")
|
self.assertEqual(hdrs["Accept-Ranges"], "bytes")
|
||||||
self.assertEquals(hdrs["Content-Length"], str(self.datalen))
|
self.assertEqual(hdrs["Content-Length"], str(self.datalen))
|
||||||
self.assertEquals(hdrs["Content-Type"], content_type)
|
self.assertEqual(hdrs["Content-Type"], content_type)
|
||||||
self.assertContains(hdrs["Server"], "darkhttpd/")
|
self.assertContains(hdrs["Server"], "darkhttpd/")
|
||||||
self.assertEquals(body, self.data)
|
self.assertEqual(body, self.data)
|
||||||
|
|
||||||
def test_get_1(self): self.get_helper(0)
|
def test_get_1(self): self.get_helper(0)
|
||||||
def test_get_2(self): self.get_helper(1)
|
def test_get_2(self): self.get_helper(1)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
# This is run by the "run-tests" script.
|
# This is run by the "run-tests" script.
|
||||||
import unittest
|
import unittest
|
||||||
from test import TestHelper, Conn, parse
|
from test import TestHelper, Conn, parse
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
# This is run by the "run-tests" script.
|
# This is run by the "run-tests" script.
|
||||||
import unittest
|
import unittest
|
||||||
from test import TestHelper, Conn, parse
|
from test import TestHelper, Conn, parse
|
||||||
|
|
||||||
class TestForward(TestHelper):
|
class TestForward(TestHelper):
|
||||||
def test_no_server_id(self):
|
def test_no_server_id(self):
|
||||||
resp = Conn().get("/", method = 'BOGUS')
|
resp = self.get('/', method = 'BOGUS')
|
||||||
status, hdrs, body = parse(resp)
|
status, hdrs, body = parse(resp)
|
||||||
self.assertContains(status, "400 Bad Request")
|
self.assertContains(status, "400 Bad Request")
|
||||||
self.assertFalse(hdrs.has_key("Server"))
|
self.assertFalse('Server' in hdrs)
|
||||||
self.assertFalse("Generated by darkhttpd/" in body)
|
self.assertFalse(b'Generated by darkhttpd/' in body)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
# This is run by the "run-tests" script.
|
# This is run by the "run-tests" script.
|
||||||
import unittest
|
import unittest
|
||||||
import signal
|
import signal
|
||||||
@ -14,7 +14,8 @@ class TestTimeout(unittest.TestCase):
|
|||||||
# Expect to get EOF before the alarm fires.
|
# Expect to get EOF before the alarm fires.
|
||||||
ret = s.recv(1024)
|
ret = s.recv(1024)
|
||||||
signal.alarm(0)
|
signal.alarm(0)
|
||||||
self.assertEquals(ret, '')
|
s.close()
|
||||||
|
self.assertEqual(ret, b'')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user