Commit 2688462f authored by Unai Zalakain's avatar Unai Zalakain Committed by Tim Graham
Browse files

Refs #21230 -- removed direct settings manipulation from template tests

parent 2080bce6
Loading
Loading
Loading
Loading
+32 −41
Original line number Diff line number Diff line
@@ -544,7 +544,11 @@ class TemplateRegressionTests(TestCase):
            t.render(Context({}))


@override_settings(MEDIA_URL="/media/", STATIC_URL="/static/")
# Set ALLOWED_INCLUDE_ROOTS so that ssi works.
@override_settings(MEDIA_URL="/media/", STATIC_URL="/static/",
                   TEMPLATE_DEBUG=False, ALLOWED_INCLUDE_ROOTS=(
                       os.path.dirname(os.path.abspath(upath(__file__))),),
                   )
class TemplateTests(TransRealMixin, TestCase):
    def test_templates(self):
        template_tests = self.get_template_tests()
@@ -565,19 +569,9 @@ class TemplateTests(TransRealMixin, TestCase):
        failures = []
        tests = sorted(template_tests.items())

        # Turn TEMPLATE_DEBUG off, because tests assume that.
        old_td, settings.TEMPLATE_DEBUG = settings.TEMPLATE_DEBUG, False

        # Set TEMPLATE_STRING_IF_INVALID to a known string.
        old_invalid = settings.TEMPLATE_STRING_IF_INVALID
        expected_invalid_str = 'INVALID'

        # Set ALLOWED_INCLUDE_ROOTS so that ssi works.
        old_allowed_include_roots = settings.ALLOWED_INCLUDE_ROOTS
        settings.ALLOWED_INCLUDE_ROOTS = (
            os.path.dirname(os.path.abspath(upath(__file__))),
        )

        # Warm the URL reversing cache. This ensures we don't pay the cost
        # warming the cache during one of the tests.
        urlresolvers.reverse('template_tests.views.client_action',
@@ -613,8 +607,8 @@ class TemplateTests(TransRealMixin, TestCase):
                    (expected_invalid_str, False, invalid_string_result),
                    ('', True, template_debug_result)
            ]:
                settings.TEMPLATE_STRING_IF_INVALID = invalid_str
                settings.TEMPLATE_DEBUG = template_debug
                with override_settings(TEMPLATE_STRING_IF_INVALID=invalid_str,
                                       TEMPLATE_DEBUG=template_debug):
                    for is_cached in (False, True):
                        try:
                            try:
@@ -651,9 +645,6 @@ class TemplateTests(TransRealMixin, TestCase):

        restore_template_loaders()
        deactivate()
        settings.TEMPLATE_DEBUG = old_td
        settings.TEMPLATE_STRING_IF_INVALID = old_invalid
        settings.ALLOWED_INCLUDE_ROOTS = old_allowed_include_roots

        self.assertEqual(failures, [], "Tests failed:\n%s\n%s" %
            ('-' * 70, ("\n%s\n" % ('-' * 70)).join(failures)))