summaryrefslogtreecommitdiff
path: root/tests/template_tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests/template_tests')
-rw-r--r--tests/template_tests/test_loaders.py39
1 files changed, 33 insertions, 6 deletions
diff --git a/tests/template_tests/test_loaders.py b/tests/template_tests/test_loaders.py
index 059e37ed3c..e679624ed3 100644
--- a/tests/template_tests/test_loaders.py
+++ b/tests/template_tests/test_loaders.py
@@ -3,6 +3,7 @@ from __future__ import unicode_literals
import os.path
import sys
+import tempfile
import types
import unittest
from contextlib import contextmanager
@@ -176,7 +177,16 @@ class EggLoaderTests(SimpleTestCase):
class FileSystemLoaderTests(SimpleTestCase):
def setUp(self):
- self.engine = Engine()
+ self.engine = Engine(dirs=[TEMPLATE_DIR])
+
+ @contextmanager
+ def set_dirs(self, dirs):
+ original_dirs = self.engine.dirs
+ self.engine.dirs = dirs
+ try:
+ yield
+ finally:
+ self.engine.dirs = original_dirs
@contextmanager
def source_checker(self, dirs):
@@ -189,12 +199,8 @@ class FileSystemLoaderTests(SimpleTestCase):
expected_sources,
)
- original_dirs = self.engine.dirs
- self.engine.dirs = dirs
- try:
+ with self.set_dirs(dirs):
yield check_sources
- finally:
- self.engine.dirs = original_dirs
def test_directory_security(self):
with self.source_checker(['/dir1', '/dir2']) as check_sources:
@@ -238,6 +244,27 @@ class FileSystemLoaderTests(SimpleTestCase):
check_sources('index.html', ['/dir1/index.html', '/DIR2/index.html'])
check_sources('/DIR1/index.HTML', ['/DIR1/index.HTML'])
+ def test_file_does_not_exist(self):
+ with self.assertRaises(TemplateDoesNotExist):
+ self.engine.get_template('doesnotexist.html')
+
+ @unittest.skipIf(
+ sys.platform == 'win32',
+ "Python on Windows doesn't have working os.chmod().",
+ )
+ def test_permissions_error(self):
+ with tempfile.NamedTemporaryFile() as tmpfile:
+ tmpdir = os.path.dirname(tmpfile.name)
+ tmppath = os.path.join(tmpdir, tmpfile.name)
+ os.chmod(tmppath, 0o0222)
+ with self.set_dirs([tmpdir]):
+ with self.assertRaisesMessage(IOError, 'Permission denied'):
+ self.engine.get_template(tmpfile.name)
+
+ def test_notafile_error(self):
+ with self.assertRaisesMessage(IOError, 'Is a directory'):
+ self.engine.get_template('first')
+
class AppDirectoriesLoaderTest(SimpleTestCase):