Commits

Benoît Bryon committed 522003a

Removed duplicate form layouts in tests. Tests now override settings.TEMPLATE_DIRS

  • Participants
  • Parent commits 1afa832
  • Branches as_ul

Comments (0)

Files changed (13)

djc/formrenderingtools/templates/tests/formrenderingtools/form_layouts/as_ul/field/default.html

-{% if field.is_hidden %}
-{{ field }}
-{% else %}
-{% load form_layouts %}
-<li>{% field_errors %}{% label %}{{ field }} {% help_text %}</li>
-{% endif %}

djc/formrenderingtools/templates/tests/formrenderingtools/form_layouts/as_ul/form_errors/default.html

-{% if form.non_field_errors %}
-<li>
-  {{ form.non_field_errors }}
-</li>
-{% endif %}

djc/formrenderingtools/templates/tests/formrenderingtools/form_layouts/as_ul/help_text/default.html

-{{ field.help_text|safe }}

djc/formrenderingtools/templates/tests/formrenderingtools/form_layouts/as_ul/label/default.html

-<label for="{{ field_id }}">{{ field.label }}:</label>

djc/formrenderingtools/templates/tests/formrenderingtools/form_layouts/default/field/default.html

-{% if field.is_hidden %}
-{{ field }}
-{% else %}
-{% load form_layouts %}
-<div class="formItem{% if field.errors %} hasErrors{% endif %}{% if field.field.required %} required{% endif %} {{ field.html_name }}">
-  {% field_errors %}
-  {% label %}
-  {{ field }}
-  {% help_text %}
-</div>
-{% endif %}

djc/formrenderingtools/templates/tests/formrenderingtools/form_layouts/default/field_errors/default.html

-{% if field.errors %}
-<ul class="errorlist">
-  {% for error in field.errors %}
-  <li>{{ error }}</li>
-  {% endfor %}
-</ul>
-{% endif %}

djc/formrenderingtools/templates/tests/formrenderingtools/form_layouts/default/field_list/default.html

-{% load form_layouts %}
-{% for field in fields %}
-  {% field field=field %}
-{% endfor %}

djc/formrenderingtools/templates/tests/formrenderingtools/form_layouts/default/form/default.html

-{% load form_layouts %}
-{{ test_text|safe }}
-{% form_errors %}
-{% field_list %}

djc/formrenderingtools/templates/tests/formrenderingtools/form_layouts/default/form_errors/default.html

-{% if form.non_field_errors %}
-<div class="nonFieldErrors">
-  {{ form.non_field_errors }}
-</div>
-{% endif %}

djc/formrenderingtools/templates/tests/formrenderingtools/form_layouts/default/help_text/default.html

-{% if field.help_text %}<p class="help">{{ field.help_text|safe }}</p>{% endif %}

djc/formrenderingtools/templates/tests/formrenderingtools/form_layouts/default/label/default.html

-<label for="{{ field_id }}" class="{% if field.field.required %} required{% endif %}">{{ field.label }}</label>

djc/formrenderingtools/templatetags/form_layouts.py

     def render(self, context):
         top_level_element = ('_form_layouts' not in context)
         if top_level_element:
-            if not self.form:
-                self.form = 'form'
+            if not self.field:
+                self.form = 'field'
             if not self.layout:
                 self.layout = '"%s"' % settings.FORMRENDERINGTOOLS_DEFAULT_LAYOUT
             if not self.template_name:

djc/formrenderingtools/tests.py

     """
     Tests the "form_layouts" template tag library.
     
-    Alters settings.FORMRENDERINGTOOLS_TEMPLATE_DIR so that only the "test"
+    Alters settings.TEMPLATE_DIRS so that only the original formrendering tools
     templates are available. Otherwise, the project's templates could interfere
     with test results.
     """
     def setUp(self):
         # Template directory: contains test templates
-        self.template_dir = 'tests/formrenderingtools'
         # Form layouts template directory: contains test layouts
-        template_setting = 'FORMRENDERINGTOOLS_TEMPLATE_DIR'
-        default_template_dir = DEFAULT_SETTINGS[template_setting]
-        self.form_layouts_template_dir = os.path.join(self.template_dir, 
-                                                      default_template_dir)
+        #template_setting = ''
+        #default_template_dir = DEFAULT_SETTINGS[template_setting]
+        #self.form_layouts_template_dir = os.path.join(self.template_dir, 
+        #                                              default_template_dir)
         self._change_settings()
     
     def tearDown(self):
         Loads default settings, so that the project configuration does not
         affects the test process.
         """
+        template_dirs = (
+          os.path.join(os.path.dirname(__file__), 'templates'),
+          os.path.join(os.path.dirname(__file__), 'templates/tests/formrenderingtools'),
+        )
         self.previous_settings = {}
         for key, value in DEFAULT_SETTINGS.iteritems():
             self.previous_settings[key] = getattr(settings, key) 
             setattr(settings, key, value)
-        template_setting = 'FORMRENDERINGTOOLS_TEMPLATE_DIR'
-        setattr(settings, template_setting, self.form_layouts_template_dir)
+        #template_setting = 'FORMRENDERINGTOOLS_TEMPLATE_DIR'
+        setattr(settings, 'TEMPLATE_DIRS', template_dirs)
     
     def _restore_settings(self):
         """
         context and validates that it matches the content of the
         /form_layouts/<code>_output.html file.
         """
-        theory = render_to_string('%s/%s_output.html' % 
-                                  (self.template_dir, code), context)
+        theory = render_to_string('%s_output.html' % code, context)
         theory = strip_spaces_between_tags(theory).strip()
-        reality = render_to_string('%s/%s_source.html' % 
-                                   (self.template_dir, code), context)
+        reality = render_to_string('%s_source.html' % code, context)
         reality = strip_spaces_between_tags(reality).strip()
         self.assertEquals(reality, theory)
     
         
         # Setting FORMRENDERINGTOOLS_TEMPLATE_DIR to something which does not
         # exist must raise an exception
-        setattr(settings, 'FORMRENDERINGTOOLS_TEMPLATE_DIR', 
-                '%s/wrong_directory' % self.template_dir)
+        setattr(settings, 'FORMRENDERINGTOOLS_TEMPLATE_DIR', 'wrong_directory')
         try:
             self._render_string_to_string(
                 '{% load form_layouts %}{% form %}',
         # which is not in the "default production form layout". This text
         # is used to make sure that the test templates are used rather than the
         # default ones.
-        setattr(settings, 'FORMRENDERINGTOOLS_TEMPLATE_DIR',
-                self.form_layouts_template_dir)
+        setattr(settings, 'FORMRENDERINGTOOLS_TEMPLATE_DIR', 'form_layouts')
         test_text = u'<p>This is a test template for ' \
                     u'djc.formrenderingtools</p>'
         output = self._render_string_to_string(