Skip to content

Commit

Permalink
Django 5.0 test compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Archmonger committed Nov 15, 2024
1 parent 3903ddf commit 7bcdfae
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions tests/test_django_servestatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ async def executor():
assert dict(response["headers"])[b"Content-Range"] == b"bytes */%d" % len(static_files.js_content)


@pytest.mark.skipif(django.VERSION >= (5, 0), reason="Django <5.0 only")
@pytest.mark.usefixtures("_collect_static")
def test_large_static_file(asgi_application, static_files):
url = storage.staticfiles_storage.url(static_files.txt_path)
Expand All @@ -435,3 +436,27 @@ def test_large_static_file(asgi_application, static_files):
assert send.body == static_files.txt_content
assert send.headers[b"Content-Length"] == str(len(static_files.txt_content)).encode()
assert b"text/plain" in send.headers[b"Content-Type"]


@pytest.mark.skipif(django.VERSION < (5, 0), reason="Django 5.0+ only")
@pytest.mark.usefixtures("_collect_static")
def test_large_static_file_2(asgi_application, static_files):
url = storage.staticfiles_storage.url(static_files.txt_path)
scope = AsgiScopeEmulator({"path": url, "headers": []})

async def executor():
communicator = ApplicationCommunicator(asgi_application, scope)
await communicator.send_input(scope)
response_start = await communicator.receive_output()
response_body = await communicator.receive_output()
assert response_body["more_body"] is True
response_body_2 = await communicator.receive_output()
response_body["body"] = response_body["body"] + response_body_2["body"]
return response_start | response_body

response = asyncio.run(executor())
headers = dict(response["headers"])

assert response["body"] == static_files.txt_content
assert headers[b"Content-Length"] == str(len(static_files.txt_content)).encode()
assert b"text/plain" in headers[b"Content-Type"]
2 changes: 1 addition & 1 deletion tests/test_files/static/large-file.txt

Large diffs are not rendered by default.

0 comments on commit 7bcdfae

Please sign in to comment.