Ticket #10643: security_hash.2.diff

File security_hash.2.diff, 2.1 KB (added by Ulrich Petri, 16 years ago)

Fixed stupid diff-of-diff mistake

  • django/contrib/formtools/utils.py

    diff --git a/django/contrib/formtools/utils.py b/django/contrib/formtools/utils.py
    index a357255..d557460 100644
    a b def security_hash(request, form, *args):  
    1515    order, pickles the result with the SECRET_KEY setting, then takes an md5
    1616    hash of that.
    1717    """
    18 
    19     data = [(bf.name, bf.field.clean(bf.data) or '') for bf in form]
     18    if form.empty_permitted and not form.has_changed():
     19        data = [(bf.name, bf.data or '') for bf in form]
     20    else:
     21        data = [(bf.name, bf.field.clean(bf.data) or '') for bf in form]
    2022    data.extend(args)
    2123    data.append(settings.SECRET_KEY)
    2224
  • new file tests/regressiontests/forms/formtools.py

    diff --git a/tests/regressiontests/forms/formtools.py b/tests/regressiontests/forms/formtools.py
    new file mode 100644
    index 0000000..e631b25
    - +  
     1# -*- coding: utf-8 -*-
     2from django.test import TestCase
     3from django import forms
     4
     5__all__ = ('FormToolsUtilsTests', )
     6
     7class BlankForm(forms.Form):
     8    name = forms.CharField(max_length=10, required=False)
     9class NotBlankForm(forms.Form):
     10    name = forms.CharField(max_length=10)
     11
     12class FormToolsUtilsTests(TestCase):
     13    def test_security_hash_empty_permitted_form(self):
     14        """Check that formtools.utils.security_hash handles forms with
     15        empty_permitted=True"""
     16        blank_form = BlankForm({})
     17        not_blank_form = NotBlankForm({}, empty_permitted=True)
     18       
     19        from django.contrib.formtools.utils import security_hash
     20        self.assertEqual(security_hash(None, blank_form), security_hash(None, not_blank_form))
  • tests/regressiontests/forms/tests.py

    diff --git a/tests/regressiontests/forms/tests.py b/tests/regressiontests/forms/tests.py
    index 6d418fa..d931663 100644
    a b from widgets import tests as widgets_tests  
    3232from formsets import tests as formset_tests
    3333from media import media_tests
    3434
     35from regressiontests.forms.formtools import *
     36
    3537__test__ = {
    3638    'extra_tests': extra_tests,
    3739    'fields_tests': fields_tests,
Back to Top