mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2026-09-12 19:50:57 +05:00
Some checks are pending
CI / Linters (push) Waiting to run
CI / Install and CLI platform compatibility (push) Waiting to run
CI / Discovered test matrix (push) Waiting to run
CI / Documentation and root tests (push) Waiting to run
CI / CodeQL (push) Waiting to run
CI / Tested Python artifacts (push) Waiting to run
CI / Tested Docker images (push) Waiting to run
CI / All required CI lanes (push) Blocked by required conditions
Deploy Publicsite to GitHub Pages / deploy (push) Waiting to run
59 lines
1.8 KiB
Python
59 lines
1.8 KiB
Python
from pathlib import Path
|
|
|
|
from django.test import RequestFactory
|
|
|
|
from archivebox.misc.serve_static import serve_static_with_byterange_support
|
|
|
|
|
|
def test_archive_file_response_uses_async_iterator_under_asgi(tmp_path: Path):
|
|
output = tmp_path / "screenshot" / "output.png"
|
|
output.parent.mkdir()
|
|
output.write_bytes(b"0123456789")
|
|
|
|
request = RequestFactory().get("/screenshot/output.png", HTTP_RANGE="bytes=2-5")
|
|
request.scope = {"type": "http"}
|
|
|
|
response = serve_static_with_byterange_support(
|
|
request,
|
|
"screenshot/output.png",
|
|
document_root=tmp_path,
|
|
)
|
|
|
|
assert response.is_async is True
|
|
assert response.status_code == 206
|
|
assert response["Content-Range"] == "bytes 2-5/10"
|
|
assert response["Content-Length"] == "4"
|
|
|
|
|
|
def test_path_routed_directory_index_keeps_file_browsing_context(tmp_path: Path):
|
|
plugin_dir = tmp_path / "archivewebpage"
|
|
plugin_dir.mkdir()
|
|
(plugin_dir / "archivewebpage.wacz").write_bytes(b"wacz")
|
|
|
|
request = RequestFactory().get("/snapshot/snapshot-id/?files=1")
|
|
response = serve_static_with_byterange_support(
|
|
request,
|
|
"",
|
|
document_root=tmp_path,
|
|
show_indexes=True,
|
|
is_archive_replay=True,
|
|
)
|
|
|
|
html = response.content.decode()
|
|
assert 'href="archivewebpage/?files=1"' in html
|
|
assert 'href="/snapshot/snapshot-id/"' in html
|
|
|
|
nested_request = RequestFactory().get("/snapshot/snapshot-id/archivewebpage/?files=1")
|
|
nested_response = serve_static_with_byterange_support(
|
|
nested_request,
|
|
"archivewebpage",
|
|
document_root=tmp_path,
|
|
show_indexes=True,
|
|
is_archive_replay=True,
|
|
)
|
|
|
|
nested_html = nested_response.content.decode()
|
|
assert 'href="../?files=1"' in nested_html
|
|
assert 'href="/snapshot/snapshot-id/"' in nested_html
|
|
assert 'href="archivewebpage.wacz"' in nested_html
|