summaryrefslogtreecommitdiff
path: root/tests/test_httpserver.py
diff options
context:
space:
mode:
authorLekinho <mctreasure@gmail.com>2020-02-12 06:29:31 -0400
committerGitHub <noreply@github.com>2020-02-12 10:29:31 +0000
commitc8de203b0dec88c65a32e2d1edb2480644dfbc84 (patch)
treec07900c15cfab46be6177092480c827f390afd61 /tests/test_httpserver.py
parent177f22e80b2ecde710a5423ab12db5280bdff3eb (diff)
downloadpaste-git-c8de203b0dec88c65a32e2d1edb2480644dfbc84.tar.gz
add ipv6 support by setting address family (#50)
* add ipv6 support by setting address family
Diffstat (limited to 'tests/test_httpserver.py')
-rw-r--r--tests/test_httpserver.py61
1 files changed, 60 insertions, 1 deletions
diff --git a/tests/test_httpserver.py b/tests/test_httpserver.py
index 512f06d..7b64a45 100644
--- a/tests/test_httpserver.py
+++ b/tests/test_httpserver.py
@@ -4,7 +4,7 @@ import socket
import six
-from paste.httpserver import LimitedLengthFile, WSGIHandler
+from paste.httpserver import LimitedLengthFile, WSGIHandler, serve
from six.moves import StringIO
@@ -72,3 +72,62 @@ def test_limited_length_file_tell_on_socket():
assert f.read() == b'123456789'
assert f.tell() == 10
backing_read.close()
+
+
+def test_address_family_v4():
+ #ipv4
+ app = None
+ host = '127.0.0.1'
+ port = '9090'
+
+ svr = serve(app, host=host, port=port, start_loop=False, use_threadpool=False)
+
+ af = svr.address_family
+ addr = svr.server_address
+ p = svr.server_port
+
+ svr.server_close()
+
+ assert (af == socket.AF_INET)
+ assert (addr[0] == '127.0.0.1')
+ assert (str(p) == port)
+
+
+def test_address_family_v4_host_and_port():
+ #ipv4
+ app = None
+ host = '127.0.0.1:9091'
+
+ svr = serve(app, host=host, start_loop=False, use_threadpool=False)
+
+ af = svr.address_family
+ addr = svr.server_address
+ p = svr.server_port
+
+ svr.server_close()
+
+ assert (af == socket.AF_INET)
+ assert (addr[0] == '127.0.0.1')
+ assert (str(p) == '9091')
+
+def test_address_family_v6():
+ #ipv6
+ app = None
+ host = '[::1]'
+ port = '9090'
+
+ try:
+ svr = serve(app, host=host, port=port, start_loop=False, use_threadpool=False)
+
+ af = svr.address_family
+ addr = svr.server_address
+ p = svr.server_port
+
+ svr.server_close()
+
+ assert (af == socket.AF_INET6)
+ assert (addr[0] == '::1')
+ assert (str(p) == port)
+ except (socket.error, OSError) as err:
+ # v6 support not available in this OS, pass the test
+ assert True \ No newline at end of file