2013-11-28 22:02:40 +00:00
|
|
|
import os
|
|
|
|
|
|
2020-01-07 14:18:54 +00:00
|
|
|
from django.core.files.base import ContentFile
|
2020-01-07 14:51:55 +00:00
|
|
|
import django.test
|
2020-09-18 08:23:56 +00:00
|
|
|
from django.urls import reverse
|
2013-11-28 22:02:40 +00:00
|
|
|
|
|
|
|
|
from django_downloadview.lighttpd import assert_x_sendfile
|
|
|
|
|
|
|
|
|
|
from demoproject.lighttpd.views import storage, storage_dir
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def setup_file():
|
|
|
|
|
if not os.path.exists(storage_dir):
|
|
|
|
|
os.makedirs(storage_dir)
|
2020-01-07 14:21:34 +00:00
|
|
|
storage.save("hello-world.txt", ContentFile("Hello world!\n"))
|
2013-11-28 22:02:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class OptimizedByMiddlewareTestCase(django.test.TestCase):
|
|
|
|
|
def test_response(self):
|
|
|
|
|
"""'lighttpd:optimized_by_middleware' returns X-Sendfile response."""
|
|
|
|
|
setup_file()
|
2020-01-07 14:10:42 +00:00
|
|
|
url = reverse("lighttpd:optimized_by_middleware")
|
2013-11-28 22:02:40 +00:00
|
|
|
response = self.client.get(url)
|
|
|
|
|
assert_x_sendfile(
|
|
|
|
|
self,
|
|
|
|
|
response,
|
|
|
|
|
content_type="text/plain; charset=utf-8",
|
|
|
|
|
basename="hello-world.txt",
|
2020-01-07 14:10:42 +00:00
|
|
|
file_path="/lighttpd-optimized-by-middleware/hello-world.txt",
|
|
|
|
|
)
|
2013-11-28 22:02:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class OptimizedByDecoratorTestCase(django.test.TestCase):
|
|
|
|
|
def test_response(self):
|
|
|
|
|
"""'lighttpd:optimized_by_decorator' returns X-Sendfile response."""
|
|
|
|
|
setup_file()
|
2020-01-07 14:10:42 +00:00
|
|
|
url = reverse("lighttpd:optimized_by_decorator")
|
2013-11-28 22:02:40 +00:00
|
|
|
response = self.client.get(url)
|
|
|
|
|
assert_x_sendfile(
|
|
|
|
|
self,
|
|
|
|
|
response,
|
|
|
|
|
content_type="text/plain; charset=utf-8",
|
|
|
|
|
basename="hello-world.txt",
|
2020-01-07 14:10:42 +00:00
|
|
|
file_path="/lighttpd-optimized-by-decorator/hello-world.txt",
|
|
|
|
|
)
|
2024-07-31 15:12:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class ModifiedHeadersTestCase(django.test.TestCase):
|
|
|
|
|
def test_response(self):
|
|
|
|
|
"""'lighttpd:modified_headers' returns X-Sendfile response."""
|
|
|
|
|
setup_file()
|
|
|
|
|
url = reverse("lighttpd:modified_headers")
|
|
|
|
|
response = self.client.get(url)
|
|
|
|
|
assert_x_sendfile(
|
|
|
|
|
self,
|
|
|
|
|
response,
|
|
|
|
|
content_type="text/plain; charset=utf-8",
|
|
|
|
|
basename="hello-world.txt",
|
|
|
|
|
file_path="/lighttpd-modified-headers/hello-world.txt",
|
|
|
|
|
)
|
2024-08-05 08:51:17 +00:00
|
|
|
self.assertEqual(response["X-Test"], "header")
|