|
6 | 6 |
|
7 | 7 | class HeadersTests(unittest.TestCase):
|
8 | 8 | def test_build_host(self):
|
9 |
| - for (host, port, secure), result in [ |
10 |
| - (("localhost", 80, False), "localhost"), |
11 |
| - (("localhost", 8000, False), "localhost:8000"), |
12 |
| - (("localhost", 443, True), "localhost"), |
13 |
| - (("localhost", 8443, True), "localhost:8443"), |
14 |
| - (("example.com", 80, False), "example.com"), |
15 |
| - (("example.com", 8000, False), "example.com:8000"), |
16 |
| - (("example.com", 443, True), "example.com"), |
17 |
| - (("example.com", 8443, True), "example.com:8443"), |
18 |
| - (("127.0.0.1", 80, False), "127.0.0.1"), |
19 |
| - (("127.0.0.1", 8000, False), "127.0.0.1:8000"), |
20 |
| - (("127.0.0.1", 443, True), "127.0.0.1"), |
21 |
| - (("127.0.0.1", 8443, True), "127.0.0.1:8443"), |
22 |
| - (("::1", 80, False), "[::1]"), |
23 |
| - (("::1", 8000, False), "[::1]:8000"), |
24 |
| - (("::1", 443, True), "[::1]"), |
25 |
| - (("::1", 8443, True), "[::1]:8443"), |
| 9 | + for (host, port, secure), (result, result_with_port) in [ |
| 10 | + (("localhost", 80, False), ("localhost", "localhost:80")), |
| 11 | + (("localhost", 8000, False), ("localhost:8000", "localhost:8000")), |
| 12 | + (("localhost", 443, True), ("localhost", "localhost:443")), |
| 13 | + (("localhost", 8443, True), ("localhost:8443", "localhost:8443")), |
| 14 | + (("example.com", 80, False), ("example.com", "example.com:80")), |
| 15 | + (("example.com", 8000, False), ("example.com:8000", "example.com:8000")), |
| 16 | + (("example.com", 443, True), ("example.com", "example.com:443")), |
| 17 | + (("example.com", 8443, True), ("example.com:8443", "example.com:8443")), |
| 18 | + (("127.0.0.1", 80, False), ("127.0.0.1", "127.0.0.1:80")), |
| 19 | + (("127.0.0.1", 8000, False), ("127.0.0.1:8000", "127.0.0.1:8000")), |
| 20 | + (("127.0.0.1", 443, True), ("127.0.0.1", "127.0.0.1:443")), |
| 21 | + (("127.0.0.1", 8443, True), ("127.0.0.1:8443", "127.0.0.1:8443")), |
| 22 | + (("::1", 80, False), ("[::1]", "[::1]:80")), |
| 23 | + (("::1", 8000, False), ("[::1]:8000", "[::1]:8000")), |
| 24 | + (("::1", 443, True), ("[::1]", "[::1]:443")), |
| 25 | + (("::1", 8443, True), ("[::1]:8443", "[::1]:8443")), |
26 | 26 | ]:
|
27 | 27 | with self.subTest(host=host, port=port, secure=secure):
|
28 |
| - self.assertEqual(build_host(host, port, secure), result) |
| 28 | + self.assertEqual( |
| 29 | + build_host(host, port, secure), |
| 30 | + result, |
| 31 | + ) |
| 32 | + self.assertEqual( |
| 33 | + build_host(host, port, secure, always_include_port=True), |
| 34 | + result_with_port, |
| 35 | + ) |
29 | 36 |
|
30 | 37 | def test_parse_connection(self):
|
31 | 38 | for header, parsed in [
|
|
0 commit comments