MCPcopy Create free account
hub / github.com/EasyIME/PIME / test_host_matching

Method test_host_matching

python/python3/tornado/test/web_test.py:1522–1550  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1520 return [("/foo", HostMatchingTest.Handler, {"reply": "wildcard"})]
1521
1522 def test_host_matching(self):
1523 self.app.add_handlers(
1524 "www.example.com", [("/foo", HostMatchingTest.Handler, {"reply": "[0]"})]
1525 )
1526 self.app.add_handlers(
1527 r"www\.example\.com", [("/bar", HostMatchingTest.Handler, {"reply": "[1]"})]
1528 )
1529 self.app.add_handlers(
1530 "www.example.com", [("/baz", HostMatchingTest.Handler, {"reply": "[2]"})]
1531 )
1532 self.app.add_handlers(
1533 "www.e.*e.com", [("/baz", HostMatchingTest.Handler, {"reply": "[3]"})]
1534 )
1535
1536 response = self.fetch("/foo")
1537 self.assertEqual(response.body, b"wildcard")
1538 response = self.fetch("/bar")
1539 self.assertEqual(response.code, 404)
1540 response = self.fetch("/baz")
1541 self.assertEqual(response.code, 404)
1542
1543 response = self.fetch("/foo", headers={"Host": "www.example.com"})
1544 self.assertEqual(response.body, b"[0]")
1545 response = self.fetch("/bar", headers={"Host": "www.example.com"})
1546 self.assertEqual(response.body, b"[1]")
1547 response = self.fetch("/baz", headers={"Host": "www.example.com"})
1548 self.assertEqual(response.body, b"[2]")
1549 response = self.fetch("/baz", headers={"Host": "www.exe.com"})
1550 self.assertEqual(response.body, b"[3]")
1551
1552
1553class DefaultHostMatchingTest(WebTestCase):

Callers

nothing calls this directly

Calls 2

add_handlersMethod · 0.80
fetchMethod · 0.45

Tested by

no test coverage detected