diff options
| author | Preston Timmons <prestontimmons@gmail.com> | 2014-12-03 20:21:11 -0600 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-12-06 10:57:46 -0500 |
| commit | 5c68870169deec9eff392c53a8e74e3482f02ade (patch) | |
| tree | d42a3780d57a429329bd4329be6790d57c255230 /tests/template_tests/syntax_tests | |
| parent | 34a06d99e0fc96a0f0648bfde141d342e963e971 (diff) | |
Fixed #23958 -- Rewrote filter tests as unit tests.
Diffstat (limited to 'tests/template_tests/syntax_tests')
37 files changed, 36 insertions, 242 deletions
diff --git a/tests/template_tests/syntax_tests/test_autoescape.py b/tests/template_tests/syntax_tests/test_autoescape.py index a908daca20..589265082c 100644 --- a/tests/template_tests/syntax_tests/test_autoescape.py +++ b/tests/template_tests/syntax_tests/test_autoescape.py @@ -2,7 +2,7 @@ from django.template.base import TemplateSyntaxError from django.test import SimpleTestCase from django.utils.safestring import mark_safe -from .utils import render, setup, SafeClass, UnsafeClass +from ..utils import render, setup, SafeClass, UnsafeClass class AutoescapeTagTests(SimpleTestCase): diff --git a/tests/template_tests/syntax_tests/test_basic.py b/tests/template_tests/syntax_tests/test_basic.py index 5678b935ba..72b0b7486d 100644 --- a/tests/template_tests/syntax_tests/test_basic.py +++ b/tests/template_tests/syntax_tests/test_basic.py @@ -3,7 +3,7 @@ from django.template.base import Context, TemplateSyntaxError from django.template.loader import get_template from django.test import SimpleTestCase -from .utils import render, setup, SilentGetItemClass, SilentAttrClass, SomeClass +from ..utils import render, setup, SilentGetItemClass, SilentAttrClass, SomeClass basic_templates = { diff --git a/tests/template_tests/syntax_tests/test_builtins.py b/tests/template_tests/syntax_tests/test_builtins.py index ecd428154c..a45b1567f1 100644 --- a/tests/template_tests/syntax_tests/test_builtins.py +++ b/tests/template_tests/syntax_tests/test_builtins.py @@ -1,6 +1,6 @@ from django.test import SimpleTestCase -from .utils import render, setup +from ..utils import render, setup class BuiltinsTests(SimpleTestCase): diff --git a/tests/template_tests/syntax_tests/test_cache.py b/tests/template_tests/syntax_tests/test_cache.py index 3e304eb1a4..a702fc05e4 100644 --- a/tests/template_tests/syntax_tests/test_cache.py +++ b/tests/template_tests/syntax_tests/test_cache.py @@ -3,7 +3,7 @@ from django.template.base import TemplateSyntaxError from django.template.loader import get_template from django.test import SimpleTestCase -from .utils import render, setup +from ..utils import render, setup class CacheTagTests(SimpleTestCase): diff --git a/tests/template_tests/syntax_tests/test_comment.py b/tests/template_tests/syntax_tests/test_comment.py index 35c720efd7..73099e963b 100644 --- a/tests/template_tests/syntax_tests/test_comment.py +++ b/tests/template_tests/syntax_tests/test_comment.py @@ -1,6 +1,6 @@ from django.test import SimpleTestCase -from .utils import render, setup +from ..utils import render, setup class CommentSyntaxTests(SimpleTestCase): diff --git a/tests/template_tests/syntax_tests/test_cycle.py b/tests/template_tests/syntax_tests/test_cycle.py index bab3418e84..0c18ccba90 100644 --- a/tests/template_tests/syntax_tests/test_cycle.py +++ b/tests/template_tests/syntax_tests/test_cycle.py @@ -5,7 +5,7 @@ from django.template.loader import get_template from django.test import SimpleTestCase from django.utils.deprecation import RemovedInDjango20Warning -from .utils import render, setup +from ..utils import render, setup class CycleTagTests(SimpleTestCase): diff --git a/tests/template_tests/syntax_tests/test_exceptions.py b/tests/template_tests/syntax_tests/test_exceptions.py index 78c9df35e9..be313d8e76 100644 --- a/tests/template_tests/syntax_tests/test_exceptions.py +++ b/tests/template_tests/syntax_tests/test_exceptions.py @@ -4,7 +4,7 @@ from django.template.loader import get_template from django.test import SimpleTestCase from .test_extends import inheritance_templates -from .utils import render, setup +from ..utils import render, setup class ExceptionsTests(SimpleTestCase): diff --git a/tests/template_tests/syntax_tests/test_extends.py b/tests/template_tests/syntax_tests/test_extends.py index f4b2465616..8d546633ab 100644 --- a/tests/template_tests/syntax_tests/test_extends.py +++ b/tests/template_tests/syntax_tests/test_extends.py @@ -1,7 +1,7 @@ from django.template.base import Template from django.test import SimpleTestCase -from .utils import render, setup +from ..utils import render, setup inheritance_templates = { diff --git a/tests/template_tests/syntax_tests/test_filter_syntax.py b/tests/template_tests/syntax_tests/test_filter_syntax.py index bdf800b9c1..dda222ddc7 100644 --- a/tests/template_tests/syntax_tests/test_filter_syntax.py +++ b/tests/template_tests/syntax_tests/test_filter_syntax.py @@ -8,7 +8,7 @@ from django.template.loader import get_template from django.test import SimpleTestCase from django.utils.deprecation import RemovedInDjango20Warning -from .utils import render, setup, SomeClass, SomeOtherException, UTF8Class +from ..utils import render, setup, SomeClass, SomeOtherException, UTF8Class class FilterSyntaxTests(SimpleTestCase): diff --git a/tests/template_tests/syntax_tests/test_filter_tag.py b/tests/template_tests/syntax_tests/test_filter_tag.py index 4a54efd924..8d2e67c692 100644 --- a/tests/template_tests/syntax_tests/test_filter_tag.py +++ b/tests/template_tests/syntax_tests/test_filter_tag.py @@ -2,7 +2,7 @@ from django.template.base import TemplateSyntaxError from django.template.loader import get_template from django.test import SimpleTestCase -from .utils import render, setup +from ..utils import render, setup class FilterTagTests(SimpleTestCase): diff --git a/tests/template_tests/syntax_tests/test_firstof.py b/tests/template_tests/syntax_tests/test_firstof.py index 7f44818171..3c8291849b 100644 --- a/tests/template_tests/syntax_tests/test_firstof.py +++ b/tests/template_tests/syntax_tests/test_firstof.py @@ -5,7 +5,7 @@ from django.template.loader import get_template from django.test import SimpleTestCase from django.utils.deprecation import RemovedInDjango20Warning -from .utils import render, setup +from ..utils import render, setup class FirstOfTagTests(SimpleTestCase): diff --git a/tests/template_tests/syntax_tests/test_for.py b/tests/template_tests/syntax_tests/test_for.py index 0c55c43585..674ca6015b 100644 --- a/tests/template_tests/syntax_tests/test_for.py +++ b/tests/template_tests/syntax_tests/test_for.py @@ -5,7 +5,7 @@ from django.template.base import TemplateSyntaxError from django.test import SimpleTestCase from django.utils.deprecation import RemovedInDjango20Warning -from .utils import render, setup +from ..utils import render, setup class ForTagTests(SimpleTestCase): diff --git a/tests/template_tests/syntax_tests/test_i18n.py b/tests/template_tests/syntax_tests/test_i18n.py index d2b7d5992d..da54b68d84 100644 --- a/tests/template_tests/syntax_tests/test_i18n.py +++ b/tests/template_tests/syntax_tests/test_i18n.py @@ -5,7 +5,7 @@ from django.conf import settings from django.test import SimpleTestCase from django.utils.safestring import mark_safe -from .utils import render, setup +from ..utils import render, setup class I18nTagTests(SimpleTestCase): diff --git a/tests/template_tests/syntax_tests/test_if.py b/tests/template_tests/syntax_tests/test_if.py index f54bfec033..76135c7308 100644 --- a/tests/template_tests/syntax_tests/test_if.py +++ b/tests/template_tests/syntax_tests/test_if.py @@ -2,7 +2,7 @@ from django.template.base import TemplateSyntaxError from django.template.loader import get_template from django.test import SimpleTestCase -from .utils import render, setup, TestObj +from ..utils import render, setup, TestObj class IfTagTests(SimpleTestCase): diff --git a/tests/template_tests/syntax_tests/test_if_changed.py b/tests/template_tests/syntax_tests/test_if_changed.py index baad615e30..705530d39f 100644 --- a/tests/template_tests/syntax_tests/test_if_changed.py +++ b/tests/template_tests/syntax_tests/test_if_changed.py @@ -1,6 +1,6 @@ from django.test import SimpleTestCase -from .utils import render, setup +from ..utils import render, setup class IfChangedTagTests(SimpleTestCase): diff --git a/tests/template_tests/syntax_tests/test_if_equal.py b/tests/template_tests/syntax_tests/test_if_equal.py index f20a5db350..6aca815e8f 100644 --- a/tests/template_tests/syntax_tests/test_if_equal.py +++ b/tests/template_tests/syntax_tests/test_if_equal.py @@ -1,6 +1,6 @@ from django.test import SimpleTestCase -from .utils import render, setup +from ..utils import render, setup class IfEqualTagTests(SimpleTestCase): diff --git a/tests/template_tests/syntax_tests/test_include.py b/tests/template_tests/syntax_tests/test_include.py index 2e881ade1d..5b4c3ee8f8 100644 --- a/tests/template_tests/syntax_tests/test_include.py +++ b/tests/template_tests/syntax_tests/test_include.py @@ -4,7 +4,7 @@ from django.template.loader import get_template from django.test import SimpleTestCase from .test_basic import basic_templates -from .utils import render, setup +from ..utils import render, setup include_fail_templates = { diff --git a/tests/template_tests/syntax_tests/test_invalid_string.py b/tests/template_tests/syntax_tests/test_invalid_string.py index a2893dc467..f56b091389 100644 --- a/tests/template_tests/syntax_tests/test_invalid_string.py +++ b/tests/template_tests/syntax_tests/test_invalid_string.py @@ -1,7 +1,7 @@ from django.conf import settings from django.test import SimpleTestCase -from .utils import render, setup +from ..utils import render, setup class InvalidStringTests(SimpleTestCase): diff --git a/tests/template_tests/syntax_tests/test_list_index.py b/tests/template_tests/syntax_tests/test_list_index.py index 0b0bb3837d..5d7319651b 100644 --- a/tests/template_tests/syntax_tests/test_list_index.py +++ b/tests/template_tests/syntax_tests/test_list_index.py @@ -1,7 +1,7 @@ from django.conf import settings from django.test import SimpleTestCase -from .utils import render, setup +from ..utils import render, setup class ListIndexTests(SimpleTestCase): diff --git a/tests/template_tests/syntax_tests/test_load.py b/tests/template_tests/syntax_tests/test_load.py index 9342abb09d..96c657582b 100644 --- a/tests/template_tests/syntax_tests/test_load.py +++ b/tests/template_tests/syntax_tests/test_load.py @@ -2,7 +2,7 @@ from django.template.base import TemplateSyntaxError from django.template.loader import get_template from django.test import SimpleTestCase -from .utils import render, setup +from ..utils import render, setup class LoadTagTests(SimpleTestCase): diff --git a/tests/template_tests/syntax_tests/test_lorem.py b/tests/template_tests/syntax_tests/test_lorem.py index 8692201dce..339163ea8d 100644 --- a/tests/template_tests/syntax_tests/test_lorem.py +++ b/tests/template_tests/syntax_tests/test_lorem.py @@ -1,6 +1,6 @@ from django.test import SimpleTestCase -from .utils import render, setup +from ..utils import render, setup class LoremTagTests(SimpleTestCase): diff --git a/tests/template_tests/syntax_tests/test_multiline.py b/tests/template_tests/syntax_tests/test_multiline.py index 6ae3ee0f83..23a0a2f253 100644 --- a/tests/template_tests/syntax_tests/test_multiline.py +++ b/tests/template_tests/syntax_tests/test_multiline.py @@ -1,6 +1,6 @@ from django.test import SimpleTestCase -from .utils import render, setup +from ..utils import render, setup multiline_string = """ diff --git a/tests/template_tests/syntax_tests/test_named_endblock.py b/tests/template_tests/syntax_tests/test_named_endblock.py index 7a06498d6b..a83ea390f7 100644 --- a/tests/template_tests/syntax_tests/test_named_endblock.py +++ b/tests/template_tests/syntax_tests/test_named_endblock.py @@ -2,7 +2,7 @@ from django.template.base import TemplateSyntaxError from django.template.loader import get_template from django.test import SimpleTestCase -from .utils import render, setup +from ..utils import render, setup class NamedEndblockTests(SimpleTestCase): diff --git a/tests/template_tests/syntax_tests/test_now.py b/tests/template_tests/syntax_tests/test_now.py index c8dde4bf0c..82c4bc1c4d 100644 --- a/tests/template_tests/syntax_tests/test_now.py +++ b/tests/template_tests/syntax_tests/test_now.py @@ -3,7 +3,7 @@ from datetime import datetime from django.test import SimpleTestCase from django.utils.formats import date_format -from .utils import render, setup +from ..utils import render, setup class NowTagTests(SimpleTestCase): diff --git a/tests/template_tests/syntax_tests/test_numpy.py b/tests/template_tests/syntax_tests/test_numpy.py index aa40bdc7c1..fe60939586 100644 --- a/tests/template_tests/syntax_tests/test_numpy.py +++ b/tests/template_tests/syntax_tests/test_numpy.py @@ -3,7 +3,7 @@ from unittest import skipIf from django.conf import settings from django.test import SimpleTestCase -from .utils import render, setup +from ..utils import render, setup try: import numpy diff --git a/tests/template_tests/syntax_tests/test_regroup.py b/tests/template_tests/syntax_tests/test_regroup.py index 09313dcefc..cd06420c50 100644 --- a/tests/template_tests/syntax_tests/test_regroup.py +++ b/tests/template_tests/syntax_tests/test_regroup.py @@ -4,7 +4,7 @@ from django.template.base import TemplateSyntaxError from django.template.loader import get_template from django.test import SimpleTestCase -from .utils import render, setup +from ..utils import render, setup class RegroupTagTests(SimpleTestCase): diff --git a/tests/template_tests/syntax_tests/test_setup.py b/tests/template_tests/syntax_tests/test_setup.py index ea37698ee9..fd7355a738 100644 --- a/tests/template_tests/syntax_tests/test_setup.py +++ b/tests/template_tests/syntax_tests/test_setup.py @@ -1,7 +1,7 @@ from django.conf import settings from django.test import SimpleTestCase -from .utils import setup +from ..utils import setup class SetupTests(SimpleTestCase): diff --git a/tests/template_tests/syntax_tests/test_simple_tag.py b/tests/template_tests/syntax_tests/test_simple_tag.py index 7529da014c..79c43f88c9 100644 --- a/tests/template_tests/syntax_tests/test_simple_tag.py +++ b/tests/template_tests/syntax_tests/test_simple_tag.py @@ -2,7 +2,7 @@ from django.template.base import TemplateSyntaxError from django.template.loader import get_template from django.test import SimpleTestCase -from .utils import render, setup +from ..utils import render, setup class SimpleTagTests(SimpleTestCase): diff --git a/tests/template_tests/syntax_tests/test_spaceless.py b/tests/template_tests/syntax_tests/test_spaceless.py index 1f5cb54e29..18bda09c83 100644 --- a/tests/template_tests/syntax_tests/test_spaceless.py +++ b/tests/template_tests/syntax_tests/test_spaceless.py @@ -1,6 +1,6 @@ from django.test import SimpleTestCase -from .utils import render, setup +from ..utils import render, setup class SpacelessTagTests(SimpleTestCase): diff --git a/tests/template_tests/syntax_tests/test_ssi.py b/tests/template_tests/syntax_tests/test_ssi.py index d6945bdf60..caa1901943 100644 --- a/tests/template_tests/syntax_tests/test_ssi.py +++ b/tests/template_tests/syntax_tests/test_ssi.py @@ -5,7 +5,7 @@ from django.test import override_settings, SimpleTestCase from django.utils._os import upath from django.utils.deprecation import RemovedInDjango19Warning -from .utils import render, setup +from ..utils import render, setup cwd = os.path.dirname(os.path.abspath(upath(__file__))) diff --git a/tests/template_tests/syntax_tests/test_static.py b/tests/template_tests/syntax_tests/test_static.py index 460dbd7077..95ddb196af 100644 --- a/tests/template_tests/syntax_tests/test_static.py +++ b/tests/template_tests/syntax_tests/test_static.py @@ -2,7 +2,7 @@ from django.conf import settings from django.test import override_settings, SimpleTestCase from django.utils.six.moves.urllib.parse import urljoin -from .utils import render, setup +from ..utils import render, setup @override_settings(MEDIA_URL="/media/", STATIC_URL="/static/") diff --git a/tests/template_tests/syntax_tests/test_template_tag.py b/tests/template_tests/syntax_tests/test_template_tag.py index 212c2c1d50..18faafd252 100644 --- a/tests/template_tests/syntax_tests/test_template_tag.py +++ b/tests/template_tests/syntax_tests/test_template_tag.py @@ -2,7 +2,7 @@ from django.template.base import TemplateSyntaxError from django.template.loader import get_template from django.test import SimpleTestCase -from .utils import render, setup +from ..utils import render, setup class TemplateTagTests(SimpleTestCase): diff --git a/tests/template_tests/syntax_tests/test_url.py b/tests/template_tests/syntax_tests/test_url.py index cd684c9c13..56af43d131 100644 --- a/tests/template_tests/syntax_tests/test_url.py +++ b/tests/template_tests/syntax_tests/test_url.py @@ -7,7 +7,7 @@ from django.template.loader import get_template from django.test import override_settings, SimpleTestCase from django.utils.deprecation import RemovedInDjango20Warning -from .utils import render, setup +from ..utils import render, setup @override_settings(ROOT_URLCONF='template_tests.urls') diff --git a/tests/template_tests/syntax_tests/test_verbatim.py b/tests/template_tests/syntax_tests/test_verbatim.py index ef10c12fad..43a6e8546c 100644 --- a/tests/template_tests/syntax_tests/test_verbatim.py +++ b/tests/template_tests/syntax_tests/test_verbatim.py @@ -2,7 +2,7 @@ from django.template.base import TemplateSyntaxError from django.template.loader import get_template from django.test import SimpleTestCase -from .utils import render, setup +from ..utils import render, setup class VerbatimTagTests(SimpleTestCase): diff --git a/tests/template_tests/syntax_tests/test_width_ratio.py b/tests/template_tests/syntax_tests/test_width_ratio.py index fc098b79cf..225cd602fd 100644 --- a/tests/template_tests/syntax_tests/test_width_ratio.py +++ b/tests/template_tests/syntax_tests/test_width_ratio.py @@ -3,7 +3,7 @@ from django.template.loader import get_template from django.test import SimpleTestCase from django.utils import six -from .utils import render, setup +from ..utils import render, setup class WidthRatioTagTests(SimpleTestCase): diff --git a/tests/template_tests/syntax_tests/test_with.py b/tests/template_tests/syntax_tests/test_with.py index 11e8ef217f..571ea7f1c1 100644 --- a/tests/template_tests/syntax_tests/test_with.py +++ b/tests/template_tests/syntax_tests/test_with.py @@ -2,7 +2,7 @@ from django.conf import settings from django.template.base import TemplateSyntaxError from django.test import SimpleTestCase -from .utils import render, setup +from ..utils import render, setup class WithTagTests(SimpleTestCase): diff --git a/tests/template_tests/syntax_tests/utils.py b/tests/template_tests/syntax_tests/utils.py deleted file mode 100644 index 168eca73f8..0000000000 --- a/tests/template_tests/syntax_tests/utils.py +++ /dev/null @@ -1,206 +0,0 @@ -# coding: utf-8 - -from __future__ import unicode_literals - -import functools - -from django import template -from django.template import Library -from django.template.base import Context -from django.template.engine import Engine -from django.template.loader import get_template -from django.test.utils import override_settings -from django.utils import translation -from django.utils.encoding import python_2_unicode_compatible -from django.utils.safestring import mark_safe - - -def render(template_name, context=None): - if context is None: - context = {} - - t = get_template(template_name) - with translation.override(context.get('LANGUAGE_CODE', 'en-us')): - return t.render(Context(context)) - - -def setup(templates, *args): - """ - Runs test method multiple times in the following order: - - TEMPLATE_DEBUG CACHED TEMPLATE_STRING_IF_INVALID - -------------- ------ -------------------------- - False False - False True - False False INVALID - False True INVALID - True False - True True - """ - - for arg in args: - templates.update(arg) - - # numerous tests make use of an inclusion tag - # add this in here for simplicity - templates["inclusion.html"] = "{{ result }}" - - def decorator(func): - @register_test_tags - @override_settings(TEMPLATE_LOADERS=[ - ('django.template.loaders.cached.Loader', [ - ('django.template.loaders.locmem.Loader', templates), - ]), - ]) - @functools.wraps(func) - def inner(self): - loader = Engine.get_default().template_loaders[0] - - func(self) - func(self) - loader.reset() - - with override_settings(TEMPLATE_STRING_IF_INVALID='INVALID'): - func(self) - func(self) - loader.reset() - - with override_settings(TEMPLATE_DEBUG=True): - func(self) - func(self) - loader.reset() - return inner - return decorator - - -# Custom template tag for tests - -register = Library() - - -class EchoNode(template.Node): - def __init__(self, contents): - self.contents = contents - - def render(self, context): - return ' '.join(self.contents) - - -@register.tag -def echo(parser, token): - return EchoNode(token.contents.split()[1:]) -register.tag('other_echo', echo) - - -@register.filter -def upper(value): - return value.upper() - - -def register_test_tags(func): - @functools.wraps(func) - def inner(self): - template.libraries['testtags'] = register - func(self) - del template.libraries['testtags'] - return inner - - -# Helper objects - -class SomeException(Exception): - silent_variable_failure = True - - -class SomeOtherException(Exception): - pass - - -class ShouldNotExecuteException(Exception): - pass - - -class SomeClass: - def __init__(self): - self.otherclass = OtherClass() - - def method(self): - return 'SomeClass.method' - - def method2(self, o): - return o - - def method3(self): - raise SomeException - - def method4(self): - raise SomeOtherException - - def method5(self): - raise TypeError - - def __getitem__(self, key): - if key == 'silent_fail_key': - raise SomeException - elif key == 'noisy_fail_key': - raise SomeOtherException - raise KeyError - - @property - def silent_fail_attribute(self): - raise SomeException - - @property - def noisy_fail_attribute(self): - raise SomeOtherException - - @property - def attribute_error_attribute(self): - raise AttributeError - - -class OtherClass: - def method(self): - return 'OtherClass.method' - - -class TestObj(object): - def is_true(self): - return True - - def is_false(self): - return False - - def is_bad(self): - raise ShouldNotExecuteException() - - -class SilentGetItemClass(object): - def __getitem__(self, key): - raise SomeException - - -class SilentAttrClass(object): - def b(self): - raise SomeException - b = property(b) - - -@python_2_unicode_compatible -class UTF8Class: - "Class whose __str__ returns non-ASCII data on Python 2" - def __str__(self): - return 'ŠĐĆŽćžšđ' - - -# These two classes are used to test auto-escaping of unicode output. -@python_2_unicode_compatible -class UnsafeClass: - def __str__(self): - return 'you & me' - - -@python_2_unicode_compatible -class SafeClass: - def __str__(self): - return mark_safe('you > me') |
