From 5c5d7dc888cd6fbfa692651818492a572cfe7721 Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Wed, 8 Jan 2020 15:30:18 +0100 Subject: [PATCH] Some testing for send_file --- tests/core/test_basic.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/core/test_basic.py b/tests/core/test_basic.py index a7a0bb5a..a5697ba4 100644 --- a/tests/core/test_basic.py +++ b/tests/core/test_basic.py @@ -1,5 +1,9 @@ +import tempfile +from datetime import datetime + from django.test import TestCase from wiki.conf import settings as wiki_settings +from wiki.core.http import send_file from wiki.forms import Group from wiki.models import Article, ArticleRevision, URLPath @@ -36,3 +40,17 @@ class LineEndingsTests(TestCase): article.add_revision(ArticleRevision(title="Root", content="Hello\nworld"), save=True) self.assertEqual("Hello\r\nworld", article.current_revision.content) + + +class HttpTests(TestCase): + def test_send_file(self): + fabricate_request = self.client.get("/").wsgi_request + fobject = tempfile.NamedTemporaryFile("r") + response = send_file(fabricate_request, fobject.name, filename="test.pdf") + assert response.has_header("Content-Disposition") + assert "inline" in response.get("Content-Disposition") + response = send_file(fabricate_request, fobject.name, filename="test.jpeg") + assert response.has_header("Content-Disposition") + response = send_file(fabricate_request, fobject.name, filename="test.jpeg", last_modified=datetime.now()) + assert response.has_header("Content-Disposition") + fobject.close() -- 2.45.2