diff --git a/hamlpy/test/__init__.py b/hamlpy/test/__init__.py index e69de29..3fe04cc 100644 --- a/hamlpy/test/__init__.py +++ b/hamlpy/test/__init__.py @@ -0,0 +1,8 @@ +from __future__ import unicode_literals + +import django +import os + + +os.environ['DJANGO_SETTINGS_MODULE'] = 'hamlpy.test.settings' +django.setup() diff --git a/hamlpy/test/settings.py b/hamlpy/test/settings.py new file mode 100644 index 0000000..129d6e4 --- /dev/null +++ b/hamlpy/test/settings.py @@ -0,0 +1,34 @@ +from __future__ import unicode_literals + +import django + +from distutils.version import StrictVersion + +DEBUG = True + +DATABASES = {} + +INSTALLED_APPS = ('hamlpy',) + +TEMPLATE_DIR = 'hamlpy/test/templates' +TEMPLATE_LOADERS = [ + 'hamlpy.template.loaders.HamlPyFilesystemLoader', + 'hamlpy.template.loaders.HamlPyAppDirectoriesLoader', + 'django.template.loaders.filesystem.Loader', + 'django.template.loaders.app_directories.Loader' +] + +if StrictVersion(django.get_version()) >= StrictVersion('1.8'): + TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [TEMPLATE_DIR], + 'OPTIONS': {'loaders': TEMPLATE_LOADERS, 'debug': True} + } + ] +else: + TEMPLATE_DIRS = [TEMPLATE_DIR] + TEMPLATE_LOADERS = TEMPLATE_LOADERS + TEMPLATE_DEBUG = True + +SECRET_KEY = 'tots top secret' diff --git a/hamlpy/test/test_loader.py b/hamlpy/test/test_loader.py index 61c13ab..6e2c0f2 100644 --- a/hamlpy/test/test_loader.py +++ b/hamlpy/test/test_loader.py @@ -1,58 +1,37 @@ from __future__ import print_function, unicode_literals -import django import mock import pytest -import unittest -from distutils.version import StrictVersion -from django.conf import settings from django.template import TemplateDoesNotExist from django.template.loader import render_to_string +from django.test import SimpleTestCase from django.test.utils import override_settings from six.moves import reload_module from hamlpy.compiler import Compiler +from hamlpy.template import loaders -TEMPLATE_DIR = 'hamlpy/test/templates' -TEMPLATE_LOADERS = [ - 'hamlpy.template.loaders.HamlPyFilesystemLoader', - 'hamlpy.template.loaders.HamlPyAppDirectoriesLoader', - 'django.template.loaders.filesystem.Loader', - 'django.template.loaders.app_directories.Loader' -] - -if StrictVersion(django.get_version()) >= StrictVersion('1.8'): - settings.configure(TEMPLATES=[ - { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [TEMPLATE_DIR], - 'OPTIONS': {'loaders': TEMPLATE_LOADERS, 'debug': True} - } - ]) -else: - settings.configure(TEMPLATE_DIRS=[TEMPLATE_DIR], TEMPLATE_LOADERS=TEMPLATE_LOADERS, TEMPLATE_DEBUG=True) - -django.setup() - +class LoaderTest(SimpleTestCase): + def setUp(self): + super(LoaderTest, self).setUp() -class LoaderTest(unittest.TestCase): - def tearDown(self): - from hamlpy.template import loaders reload_module(loaders) - @mock.patch('hamlpy.compiler.Compiler', wraps=Compiler) - def test_compiler_settings(self, mock_compiler_class): + @mock.patch('hamlpy.template.loaders.Compiler', wraps=Compiler) + def test_compiler_default_settings(self, mock_compiler_class): render_to_string('simple.hamlpy') mock_compiler_class.assert_called_once_with(options={}) mock_compiler_class.reset_mock() - with override_settings(HAMLPY_ATTR_WRAPPER='"', HAMLPY_DJANGO_INLINE_STYLE=False): - from hamlpy.template import loaders - reload_module(loaders) + @override_settings(HAMLPY_ATTR_WRAPPER='"', HAMLPY_DJANGO_INLINE_STYLE=False) + def test_compiler_settings(self): + + reload_module(loaders) + with mock.patch('hamlpy.template.loaders.Compiler', wraps=Compiler) as mock_compiler_class: rendered = render_to_string('simple.hamlpy') mock_compiler_class.assert_called_once_with(options={ diff --git a/hamlpy/test/test_templatize.py b/hamlpy/test/test_templatize.py index 5126544..278a5b2 100644 --- a/hamlpy/test/test_templatize.py +++ b/hamlpy/test/test_templatize.py @@ -1,16 +1,11 @@ from __future__ import unicode_literals -import unittest +from django.test import SimpleTestCase -from hamlpy import Config - -class TemplatizeTest(unittest.TestCase): +class TemplatizeTest(SimpleTestCase): def test_templatize(self): - # patching of Django's templatize happens when our app is loaded - Config.ready(None) - from django.utils.translation import templatize # test regular Django tags