Use aiofiles for static, refs #272

This commit is contained in:
Simon Willison 2019-06-22 22:07:41 -07:00
commit 8a1a15d725
4 changed files with 50 additions and 12 deletions

View file

@ -52,7 +52,9 @@ class TestClient:
)
await instance.send_input({"type": "http.request"})
# First message back should be response.start with headers and status
messages = []
start = await instance.receive_output(2)
messages.append(start)
assert start["type"] == "http.response.start"
headers = dict(
[(k.decode("utf8"), v.decode("utf8")) for k, v in start["headers"]]
@ -62,6 +64,7 @@ class TestClient:
body = b""
while True:
message = await instance.receive_output(2)
messages.append(message)
assert message["type"] == "http.response.body"
body += message["body"]
if not message.get("more_body"):

View file

@ -44,6 +44,14 @@ def test_homepage(app_client_two_attached_databases):
] == table_links
def test_static(app_client):
response = app_client.get("/-/static/app2.css")
assert response.status == 404
response = app_client.get("/-/static/app.css")
assert response.status == 200
assert "text/css" == response.headers["content-type"]
def test_memory_database_page():
for client in make_app_client(memory=True):
response = client.get("/:memory:")