allow using a list of hosts on a route

This commit is contained in:
Raphael Deem
2017-01-18 19:40:20 -08:00
parent e218a59911
commit 2c1ff5bf5d
3 changed files with 32 additions and 2 deletions

View File

@@ -4,7 +4,7 @@ from sanic.utils import sanic_endpoint_test
def test_vhosts():
app = Sanic('test_text')
app = Sanic('test_vhosts')
@app.route('/', host="example.com")
async def handler(request):
@@ -21,3 +21,19 @@ def test_vhosts():
headers = {"Host": "subdomain.example.com"}
request, response = sanic_endpoint_test(app, headers=headers)
assert response.text == "You're at subdomain.example.com!"
def test_vhosts_with_list():
app = Sanic('test_vhosts')
@app.route('/', host=["hello.com", "world.com"])
async def handler(request):
return text("Hello, world!")
headers = {"Host": "hello.com"}
request, response = sanic_endpoint_test(app, headers=headers)
assert response.text == "Hello, world!"
headers = {"Host": "world.com"}
request, response = sanic_endpoint_test(app, headers=headers)
assert response.text == "Hello, world!"