diff options
author | Nick Pope <nick.pope@flightdataservices.com> | 2019-04-07 21:01:47 +0100 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-02-17 09:50:50 +0100 |
commit | 8eef22dfed2d53df0da10c0090d9cb04f66efb15 (patch) | |
tree | b6c8154c346f456bb0b68eeb40746cc8ab2044bd /tests/view_tests | |
parent | bae053d497ba8a8de7e4f725973924bfb1885fd2 (diff) | |
download | django-8eef22dfed2d53df0da10c0090d9cb04f66efb15.tar.gz |
Fixed #34343 -- Moved built-in templates to filesystem.
Diffstat (limited to 'tests/view_tests')
-rw-r--r-- | tests/view_tests/tests/test_csrf.py | 14 | ||||
-rw-r--r-- | tests/view_tests/tests/test_i18n.py | 15 | ||||
-rw-r--r-- | tests/view_tests/tests/test_static.py | 15 |
3 files changed, 43 insertions, 1 deletions
diff --git a/tests/view_tests/tests/test_csrf.py b/tests/view_tests/tests/test_csrf.py index 68198672ed..ef4a50dd45 100644 --- a/tests/view_tests/tests/test_csrf.py +++ b/tests/view_tests/tests/test_csrf.py @@ -1,3 +1,5 @@ +from unittest import mock + from django.template import TemplateDoesNotExist from django.test import Client, RequestFactory, SimpleTestCase, override_settings from django.utils.translation import override @@ -117,3 +119,15 @@ class CsrfViewTests(SimpleTestCase): request = factory.post("/") with self.assertRaises(TemplateDoesNotExist): csrf_failure(request, template_name="nonexistent.html") + + def test_template_encoding(self): + """ + The template is loaded directly, not via a template loader, and should + be opened as utf-8 charset as is the default specified on template + engines. + """ + from django.views.csrf import Path + + with mock.patch.object(Path, "open") as m: + csrf_failure(mock.MagicMock(), mock.Mock()) + m.assert_called_once_with(encoding="utf-8") diff --git a/tests/view_tests/tests/test_i18n.py b/tests/view_tests/tests/test_i18n.py index e9f3e984b5..93e91bcc83 100644 --- a/tests/view_tests/tests/test_i18n.py +++ b/tests/view_tests/tests/test_i18n.py @@ -1,6 +1,7 @@ import gettext import json from os import path +from unittest import mock from django.conf import settings from django.test import ( @@ -507,6 +508,20 @@ class I18NViewTests(SimpleTestCase): with self.assertRaisesMessage(ValueError, msg): view(request, packages="unknown_package+unknown_package2") + def test_template_encoding(self): + """ + The template is loaded directly, not via a template loader, and should + be opened as utf-8 charset as is the default specified on template + engines. + """ + from django.views.i18n import Path + + view = JavaScriptCatalog.as_view() + request = RequestFactory().get("/") + with mock.patch.object(Path, "open") as m: + view(request) + m.assert_called_once_with(encoding="utf-8") + @override_settings(ROOT_URLCONF="view_tests.urls") class I18nSeleniumTests(SeleniumTestCase): diff --git a/tests/view_tests/tests/test_static.py b/tests/view_tests/tests/test_static.py index 309b81f8fa..3fa382749b 100644 --- a/tests/view_tests/tests/test_static.py +++ b/tests/view_tests/tests/test_static.py @@ -1,6 +1,7 @@ import mimetypes import unittest from os import path +from unittest import mock from urllib.parse import quote from django.conf.urls.static import static @@ -8,7 +9,7 @@ from django.core.exceptions import ImproperlyConfigured from django.http import FileResponse, HttpResponseNotModified from django.test import SimpleTestCase, override_settings from django.utils.http import http_date -from django.views.static import was_modified_since +from django.views.static import directory_index, was_modified_since from .. import urls from ..urls import media_dir @@ -152,6 +153,18 @@ class StaticTests(SimpleTestCase): response = self.client.get("/%s/" % self.prefix) self.assertEqual(response.content, b"Test index") + def test_template_encoding(self): + """ + The template is loaded directly, not via a template loader, and should + be opened as utf-8 charset as is the default specified on template + engines. + """ + from django.views.static import Path + + with mock.patch.object(Path, "open") as m: + directory_index(mock.MagicMock(), mock.MagicMock()) + m.assert_called_once_with(encoding="utf-8") + class StaticHelperTest(StaticTests): """ |