Commits

Carl Meyer committed b2b0df3 Draft

Fix tests for Django 1.5+; drop testing on Django 1.3.

Comments (0)

Files changed (4)

 - Added "error" class to row_attrs for fields with errors. Thanks Aron
   Griffis.
 
-- Dropped explicit support for Django versions prior to 1.3 and Python
+- Dropped explicit support for Django versions prior to 1.4 and Python
   versions prior to 2.6.
 
 0.2.0 (2011.01.28)
 
     pip install django-form-utils
 
-or get the `in-development version`_::
-
-    pip install django-form-utils==dev
-
-.. _in-development version: http://bitbucket.org/carljm/django-form-utils/get/tip.gz#egg=django_form_utils-dev
-
 To use ``django-form-utils`` in your Django project, just include
 ``form_utils`` in your INSTALLED_APPS setting.  ``django-form-utils`` does
 not provide any models, but including it in INSTALLED_APPS makes the
 Dependencies
 ------------
 
-``django-form-utils`` is tested on `Django`_ 1.2 and later and `Python`_ 2.6
+``django-form-utils`` is tested on `Django`_ 1.4 and later and `Python`_ 2.6
 and later.
 
-`ClearableFileField`_ requires `Django`_ 1.1 or later. 
-
 `ImageWidget`_ requires the `Python Imaging Library`_.
 `sorl-thumbnail`_ or `easy-thumbnails`_ is optional, but without it
 full-size images will be displayed instead of thumbnails. The default
+import django
 from django import forms
 from django import template
 from django.core.files.uploadedfile import SimpleUploadedFile
 
         """
         form = HoneypotForm()
-        self.assertEqual(form['honeypot'].row_attrs,
-                          u' style="display: none" class="required"')
+        attrs = form['honeypot'].row_attrs
+        self.assertTrue(u'style="display: none"' in attrs)
+        self.assertTrue(u'class="required"' in attrs)
 
     def test_row_attrs_by_iteration(self):
         """
         """
         form = HoneypotForm()
         honeypot = [field for field in form if field.name=='honeypot'][0]
-        self.assertEqual(honeypot.row_attrs,
-                          u' style="display: none" class="required"')
+        attrs = honeypot.row_attrs
+        self.assertTrue(u'style="display: none"' in attrs)
+        self.assertTrue(u'class="required"' in attrs)
 
     def test_row_attrs_by_fieldset_iteration(self):
         """
         form = HoneypotForm()
         fieldset = [fs for fs in form.fieldsets][0]
         honeypot = [field for field in fieldset if field.name=='honeypot'][0]
-        self.assertEqual(honeypot.row_attrs,
-                          u' style="display: none" class="required"')
+        attrs = honeypot.row_attrs
+        self.assertTrue(u'style="display: none"' in attrs)
+        self.assertTrue(u'class="required"' in attrs)
 
     def test_row_attrs_error_class(self):
         """
         """
         form = HoneypotForm({"honeypot": "something"})
 
-        self.assertEqual(form["honeypot"].row_attrs,
-                         u' style="display: none" class="required error"')
+        attrs = form['honeypot'].row_attrs
+        self.assertTrue(u'style="display: none"' in attrs)
+        self.assertTrue(u'class="required error"' in attrs)
 
     def test_friendly_typo_error(self):
         """
     excitement = forms.IntegerField()
 
 class TemplatetagTests(TestCase):
-    boring_form_html = [
-        u'<fieldset class="fieldset_main">',
-        u'<ul>',
-        u'<li>',
-        u'<label for="id_boredom">Boredom</label>',
-        u'<input type="text" name="boredom" id="id_boredom" />',
-        u'</li>',
-        u'<li>',
-        u'<label for="id_excitement">Excitement</label>',
-        u'<input type="text" name="excitement" id="id_excitement" />',
-        u'</li>',
-        u'</ul>',
-        u'</fieldset>',
-        ]
+    boring_form_html = (
+        u'<fieldset class="fieldset_main">'
+        u'<ul>'
+        u'<li>'
+        u'<label for="id_boredom">Boredom</label>'
+        u'<input type="%(type)s" name="boredom" id="id_boredom" />'
+        u'</li>'
+        u'<li>'
+        u'<label for="id_excitement">Excitement</label>'
+        u'<input type="%(type)s" name="excitement" id="id_excitement" />'
+        u'</li>'
+        u'</ul>'
+        u'</fieldset>'
+        ) % {'type': 'number' if django.VERSION > (1, 6, 0) else 'text'}
 
     def test_render_form(self):
         """
         form = BoringForm()
         tpl = template.Template('{% load form_utils %}{{ form|render }}')
         html = tpl.render(template.Context({'form': form}))
-        self.assertEqual([l.strip() for l in html.splitlines() if l.strip()],
-                          self.boring_form_html)
+        self.assertHTMLEqual(html, self.boring_form_html)
 
-    betterform_html = [
-        u'<fieldset class="">',
-        u'<ul>',
-        u'<li class="required">',
-        u'<label for="id_name">Name</label>',
-        u'<input type="text" name="name" id="id_name" />',
-        u'</li>',
-        u'<li class="required">',
-        u'<label for="id_position">Position</label>',
-        u'<input type="text" name="position" id="id_position" />',
-        u'</li>',
-        u'</ul>',
-        u'</fieldset>',
-        u'<fieldset class="optional">',
-        u'<legend>Optional</legend>',
-        u'<ul>',
-        u'<li class="optional">',
-        u'<label for="id_reference">Reference</label>',
-        u'<input type="text" name="reference" id="id_reference" />',
-        u'</li>',
-        u'</ul>',
+    betterform_html = (
+        u'<fieldset class="">'
+        u'<ul>'
+        u'<li class="required">'
+        u'<label for="id_name">Name</label>'
+        u'<input type="text" name="name" id="id_name" />'
+        u'</li>'
+        u'<li class="required">'
+        u'<label for="id_position">Position</label>'
+        u'<input type="text" name="position" id="id_position" />'
+        u'</li>'
+        u'</ul>'
         u'</fieldset>'
-        ]
+        u'<fieldset class="optional">'
+        u'<legend>Optional</legend>'
+        u'<ul>'
+        u'<li class="optional">'
+        u'<label for="id_reference">Reference</label>'
+        u'<input type="text" name="reference" id="id_reference" />'
+        u'</li>'
+        u'</ul>'
+        u'</fieldset>'
+        )
 
     def test_render_betterform(self):
         """
         form = ApplicationForm()
         tpl = template.Template('{% load form_utils %}{{ form|render }}')
         html = tpl.render(template.Context({'form': form}))
-        self.assertEqual([l.strip() for l in html.splitlines() if l.strip()],
-                          self.betterform_html)
+        self.assertHTMLEqual(html, self.betterform_html)
 
 
 class ImageWidgetTests(TestCase):
         html = widget.render('fieldname', ImageFieldFile(None, ImageField(), 'tiny.png'))
         # test only this much of the html, because the remainder will
         # vary depending on whether we have sorl-thumbnail
-        self.assertTrue(html.startswith(
-                '<input type="file" name="fieldname" value="tiny.png" />'
-                '<br /><img src="/media/tiny'), html)
+        self.assertTrue('<img' in html)
+        self.assertTrue('/media/tiny' in html)
 
     def test_render_nonimage(self):
         """
         """
         widget = ImageWidget()
         html = widget.render('fieldname', FieldFile(None, FileField(), 'something.txt'))
-        self.assertEqual(html, '<input type="file" name="fieldname" value="something.txt" />')
+        self.assertHTMLEqual(html, '<input type="file" name="fieldname" value="something.txt" />')
 
     def test_custom_template(self):
         """
         widget = ImageWidget(template='<div>%(image)s</div>'
                              '<div>%(input)s</div>')
         html = widget.render('fieldname', ImageFieldFile(None, ImageField(), 'tiny.png'))
-        self.assertTrue(html.startswith('<div><img src="/media/tiny'))
+        self.assertTrue(html.startswith('<div><img'))
 
 
 class ClearableFileInputTests(TestCase):
         """
         widget = ClearableFileInput()
         html = widget.render('fieldname', 'tiny.png')
-        self.assertEqual(html,
-                          '<input type="file" name="fieldname_0" />'
-                          ' Clear: '
-                          '<input type="checkbox" name="fieldname_1" />')
+        self.assertHTMLEqual(
+            html,
+            '<input type="file" name="fieldname_0" />'
+            ' Clear: '
+            '<input type="checkbox" name="fieldname_1" />'
+            )
 
     def test_custom_file_widget(self):
         """
         """
         widget = ClearableFileInput(file_widget=ImageWidget())
         html = widget.render('fieldname', ImageFieldFile(None, ImageField(), 'tiny.png'))
-        self.assertTrue(html.startswith(
-                '<input type="file" name="fieldname_0" value="tiny.png" />'
-                '<br /><img src="/media/tiny'))
+        self.assertTrue('<img' in html)
 
     def test_custom_file_widget_via_subclass(self):
         """
             default_file_widget_class = ImageWidget
         widget = ClearableImageWidget()
         html = widget.render('fieldname', ImageFieldFile(None, ImageField(), 'tiny.png'))
-        self.assertTrue(html.startswith(
-                '<input type="file" name="fieldname_0" value="tiny.png" />'
-                '<br /><img src="/media/tiny'))
+        self.assertTrue('<img' in html)
 
     def test_custom_template(self):
         """
         """
         widget = ClearableFileInput(template='Clear: %(checkbox)s %(input)s')
         html = widget.render('fieldname', ImageFieldFile(None, ImageField(), 'tiny.png'))
-        self.assertEqual(html,
-                          'Clear: '
-                          '<input type="checkbox" name="fieldname_1" /> '
-                          '<input type="file" name="fieldname_0" />')
+        self.assertHTMLEqual(
+            html,
+            'Clear: '
+            '<input type="checkbox" name="fieldname_1" /> '
+            '<input type="file" name="fieldname_0" />'
+            )
 
     def test_custom_template_via_subclass(self):
         """
             template = 'Clear: %(checkbox)s %(input)s'
         widget = ReversedClearableFileInput()
         html = widget.render('fieldname', 'tiny.png')
-        self.assertEqual(html,
-                          'Clear: '
-                          '<input type="checkbox" name="fieldname_1" /> '
-                          '<input type="file" name="fieldname_0" />')
+        self.assertHTMLEqual(
+            html,
+            'Clear: '
+            '<input type="checkbox" name="fieldname_1" /> '
+            '<input type="file" name="fieldname_0" />'
+            )
 
 
 class ClearableFileFieldTests(TestCase):
         class TestForm(forms.Form):
             f = ClearableFileField()
         form = TestForm(files={'f_0': self.upload})
-        self.assertEqual(unicode(form['f']),
-                          u'<input type="file" name="f_0" id="id_f_0" />'
-                          u' Clear: <input type="checkbox" name="f_1" id="id_f_1" />')
+        self.assertHTMLEqual(
+            unicode(form['f']),
+            u'<input type="file" name="f_0" id="id_f_0" />'
+            u' Clear: <input type="checkbox" name="f_1" id="id_f_1" />'
+            )
 
     def test_not_cleared(self):
         """
 [tox]
-envlist=py26-1.3,py26,py26-trunk,py27-1.3,py27,py27-trunk
+envlist=py26-1.4,py26,py26-trunk,py27-1.4,py27,py27-trunk
 
 [testenv]
 deps=
-  django==1.4.1
-  South==0.7.6
+  Django==1.5.1
+  South==0.8.1
   PIL==1.1.7
-  mock==1.0b1
+  mock==1.0.1
 commands=python setup.py test
 
-[testenv:py26-1.3]
+[testenv:py26-1.4]
 basepython=python2.6
 deps=
-  django==1.3.3
-  South==0.7.6
+  Django==1.4.5
+  South==0.8.1
   PIL==1.1.7
-  mock==1.0b1
+  mock==1.0.1
 
 [testenv:py26-trunk]
 basepython=python2.6
 deps=
   https://github.com/django/django/tarball/master
-  South==0.7.6
+  South==0.8.1
   PIL==1.1.7
-  mock==1.0b1
+  mock==1.0.1
 
-[testenv:py27-1.3]
+[testenv:py27-1.4]
 basepython=python2.7
 deps=
-  django==1.3.3
-  South==0.7.6
+  Django==1.4.5
+  South==0.8.1
   PIL==1.1.7
-  mock==1.0b1
+  mock==1.0.1
 
 [testenv:py27-trunk]
 basepython=python2.7
 deps=
   https://github.com/django/django/tarball/master
   PIL==1.1.7
-  South==0.7.6
-  mock==1.0b1
+  South==0.8.1
+  mock==1.0.1