Ticket #16677: 16677.2.patch

File 16677.2.patch, 7.5 KB (added by Aymeric Augustin, 13 years ago)
  • tests/regressiontests/templates/tests.py

     
    508508    def get_template_tests(self):
    509509        # SYNTAX --
    510510        # 'template_name': ('template contents', 'context dict', 'expected string output' or Exception class)
    511         return {
     511        basedir = os.path.dirname(os.path.abspath(__file__))
     512        tests = {
    512513            ### BASIC SYNTAX ################################################
    513514
    514515            # Plain text should go through the template parser untouched
     
    13501351            ### SSI TAG ########################################################
    13511352
    13521353            # Test normal behavior
    1353             'old-ssi01': ('{%% ssi %s %%}' % os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates', 'ssi_include.html'), {}, 'This is for testing an ssi include. {{ test }}\n'),
    1354             'old-ssi02': ('{%% ssi %s %%}' % os.path.join(os.path.dirname(os.path.abspath(__file__)), 'not_here'), {}, ''),
     1354            'old-ssi01': ('{%% ssi %s %%}' % os.path.join(basedir, 'templates', 'ssi_include.html'), {}, 'This is for testing an ssi include. {{ test }}\n'),
     1355            'old-ssi02': ('{%% ssi %s %%}' % os.path.join(basedir, 'not_here'), {}, ''),
    13551356
    13561357            # Test parsed output
    1357             'old-ssi06': ('{%% ssi %s parsed %%}' % os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates', 'ssi_include.html'), {'test': 'Look ma! It parsed!'}, 'This is for testing an ssi include. Look ma! It parsed!\n'),
    1358             'old-ssi07': ('{%% ssi %s parsed %%}' % os.path.join(os.path.dirname(os.path.abspath(__file__)), 'not_here'), {'test': 'Look ma! It parsed!'}, ''),
     1358            'old-ssi06': ('{%% ssi %s parsed %%}' % os.path.join(basedir, 'templates', 'ssi_include.html'), {'test': 'Look ma! It parsed!'}, 'This is for testing an ssi include. Look ma! It parsed!\n'),
     1359            'old-ssi07': ('{%% ssi %s parsed %%}' % os.path.join(basedir, 'not_here'), {'test': 'Look ma! It parsed!'}, ''),
    13591360
     1361            # Test space in file name
     1362            'old-ssi08': ('{%% ssi %s %%}' % os.path.join(basedir, 'templates', 'ssi include with spaces.html'), {}, template.TemplateSyntaxError),
     1363            'old-ssi09': ('{%% ssi %s parsed %%}' % os.path.join(basedir, 'templates', 'ssi include with spaces.html'), {'test': 'Look ma! It parsed!'}, template.TemplateSyntaxError),
     1364
    13601365            # Future compatibility
    13611366            # Test normal behavior
    1362             'ssi01': ('{%% load ssi from future %%}{%% ssi "%s" %%}' % os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates', 'ssi_include.html'), {}, 'This is for testing an ssi include. {{ test }}\n'),
    1363             'ssi02': ('{%% load ssi from future %%}{%% ssi "%s" %%}' % os.path.join(os.path.dirname(os.path.abspath(__file__)), 'not_here'), {}, ''),
    1364             'ssi03': ("{%% load ssi from future %%}{%% ssi '%s' %%}" % os.path.join(os.path.dirname(os.path.abspath(__file__)), 'not_here'), {}, ''),
     1367            'ssi01': ('{%% load ssi from future %%}{%% ssi "%s" %%}' % os.path.join(basedir, 'templates', 'ssi_include.html'), {}, 'This is for testing an ssi include. {{ test }}\n'),
     1368            'ssi02': ('{%% load ssi from future %%}{%% ssi "%s" %%}' % os.path.join(basedir, 'not_here'), {}, ''),
     1369            'ssi03': ("{%% load ssi from future %%}{%% ssi '%s' %%}" % os.path.join(basedir, 'not_here'), {}, ''),
    13651370
    13661371            # Test passing as a variable
    1367             'ssi04': ('{% load ssi from future %}{% ssi ssi_file %}', {'ssi_file': os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates', 'ssi_include.html')}, 'This is for testing an ssi include. {{ test }}\n'),
     1372            'ssi04': ('{% load ssi from future %}{% ssi ssi_file %}', {'ssi_file': os.path.join(basedir, 'templates', 'ssi_include.html')}, 'This is for testing an ssi include. {{ test }}\n'),
    13681373            'ssi05': ('{% load ssi from future %}{% ssi ssi_file %}', {'ssi_file': 'no_file'}, ''),
    13691374
    13701375            # Test parsed output
    1371             'ssi06': ('{%% load ssi from future %%}{%% ssi "%s" parsed %%}' % os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates', 'ssi_include.html'), {'test': 'Look ma! It parsed!'}, 'This is for testing an ssi include. Look ma! It parsed!\n'),
    1372             'ssi07': ('{%% load ssi from future %%}{%% ssi "%s" parsed %%}' % os.path.join(os.path.dirname(os.path.abspath(__file__)), 'not_here'), {'test': 'Look ma! It parsed!'}, ''),
     1376            'ssi06': ('{%% load ssi from future %%}{%% ssi "%s" parsed %%}' % os.path.join(basedir, 'templates', 'ssi_include.html'), {'test': 'Look ma! It parsed!'}, 'This is for testing an ssi include. Look ma! It parsed!\n'),
     1377            'ssi07': ('{%% load ssi from future %%}{%% ssi "%s" parsed %%}' % os.path.join(basedir, 'not_here'), {'test': 'Look ma! It parsed!'}, ''),
    13731378
     1379            # Test space in file name
     1380            'ssi08': ('{%% load ssi from future %%}{%% ssi "%s" %%}' % os.path.join(basedir, 'templates', 'ssi include with spaces.html'), {}, 'This is for testing an ssi include with spaces in its name. {{ test }}\n'),
     1381            'ssi09': ('{%% load ssi from future %%}{%% ssi "%s" parsed %%}' % os.path.join(basedir, 'templates', 'ssi include with spaces.html'), {'test': 'Look ma! It parsed!'}, 'This is for testing an ssi include with spaces in its name. Look ma! It parsed!\n'),
    13741382
    13751383            ### TEMPLATETAG TAG #######################################################
    13761384            'templatetag01': ('{% templatetag openblock %}', {}, '{%'),
     
    16121620            'static-statictag01': ('{% load static %}{% static "admin/base.css" %}', {}, urljoin(settings.STATIC_URL, 'admin/base.css')),
    16131621            'static-statictag02': ('{% load static %}{% static base_css %}', {'base_css': 'admin/base.css'}, urljoin(settings.STATIC_URL, 'admin/base.css')),
    16141622        }
     1623        # Until Django 1.5, the ssi tag takes an unquoted constant in argument,
     1624        # and there's no way to escape spaces. As a consequence it's impossible
     1625        # to include a file if its absolute path contains a space, as
     1626        # demonstrated by tests old-ssi08 and old-ssi09.
     1627        # If the patch to the Django chekout contains a space, the following
     1628        # tests will raise an exception too.
     1629        if ' ' in basedir:
     1630            for test_name in 'old-ssi01', 'old-ssi02', 'old-ssi06', 'old-ssi07':
     1631                tests[test_name] = tests[test_name][:-1] + (template.TemplateSyntaxError,)
     1632        return tests
    16151633
    16161634class TemplateTagLoading(unittest.TestCase):
    16171635
  • tests/regressiontests/templates/templates/ssi

     
     1This is for testing an ssi include with spaces in its name. {{ test }}
  • django/templatetags/future.py

     
    1919
    2020        {% ssi "/home/html/ljworld.com/includes/right_generic.html" parsed %}
    2121    """
    22     bits = token.contents.split()
     22    bits = token.split_contents()
    2323    parsed = False
    2424    if len(bits) not in (2, 3):
    2525        raise TemplateSyntaxError("'ssi' tag takes one argument: the path to"
Back to Top