Ticket #12521: 12521.tests.diff

File 12521.tests.diff, 7.0 KB (added by Ivan Sagalaev, 15 years ago)

Correct tests failing on current trunk

  • django/contrib/auth/admin.py

    === modified file 'django/contrib/auth/admin.py'
     
    4141        if url.endswith('password'):
    4242            return self.user_change_password(request, url.split('/')[0])
    4343        return super(UserAdmin, self).__call__(request, url)
    44    
     44
    4545    def get_urls(self):
    4646        from django.conf.urls.defaults import patterns
    4747        return patterns('',
     
    9494            'save_as': False,
    9595            'username_help_text': self.model._meta.get_field('username').help_text,
    9696            'root_path': self.admin_site.root_path,
    97             'app_label': self.model._meta.app_label,           
     97            'app_label': self.model._meta.app_label,
    9898        }, context_instance=template.RequestContext(request))
    9999
    100100    def user_change_password(self, request, id):
  • django/contrib/auth/forms.py

    === modified file 'django/contrib/auth/forms.py'
     
    1 from django.contrib.auth.models import User, UNUSABLE_PASSWORD
     1from django.contrib.auth.models import User
    22from django.contrib.auth import authenticate
    33from django.contrib.auth.tokens import default_token_generator
    44from django.contrib.sites.models import Site
     
    2121        model = User
    2222        fields = ("username",)
    2323
    24     def clean(self):
    25         # Fill the password field so model validation won't complain about it
    26         # being blank. We'll set it with the real value below.
    27         self.instance.password = UNUSABLE_PASSWORD
    28         super(UserCreationForm, self).clean()
    29 
    3024    def clean_username(self):
    3125        username = self.cleaned_data["username"]
    3226        try:
     
    4034        password2 = self.cleaned_data["password2"]
    4135        if password1 != password2:
    4236            raise forms.ValidationError(_("The two password fields didn't match."))
    43         self.instance.set_password(password1)
    4437        return password2
    4538
     39    def save(self, *args, **kwargs):
     40        self.instance.set_password(self.cleaned_data["password1"])
     41        return super(UserCreationForm, self).save(*args, **kwargs)
     42
    4643class UserChangeForm(forms.ModelForm):
    4744    username = forms.RegexField(label=_("Username"), max_length=30, regex=r'^\w+$',
    4845        help_text = _("Required. 30 characters or fewer. Alphanumeric characters only (letters, digits and underscores)."),
    4946        error_message = _("This value must contain only letters, numbers and underscores."))
    50    
     47
    5148    class Meta:
    5249        model = User
    5350
  • tests/modeltests/model_forms/models.py

    === modified file 'tests/modeltests/model_forms/models.py'
     
    11521152>>> class BigIntForm(forms.ModelForm):
    11531153...     class Meta:
    11541154...         model = BigInt
    1155 ... 
     1155...
    11561156>>> bif = BigIntForm({'biggie': '-9223372036854775808'})
    11571157>>> bif.is_valid()
    11581158True
     
    14251425>>> form._errors
    14261426{'__all__': [u'Price with this Price and Quantity already exists.']}
    14271427
    1428 # This form is never valid because quantity is blank=False.
     1428This Price instance generated by this form is not valid because the quantity
     1429field is required, but the form is valid because the field is excluded from
     1430the form. This is for backwards compatibility.
     1431
    14291432>>> class PriceForm(ModelForm):
    14301433...     class Meta:
    14311434...         model = Price
    14321435...         exclude = ('quantity',)
    14331436>>> form = PriceForm({'price': '6.00'})
    14341437>>> form.is_valid()
     1438True
     1439>>> price = form.save(commit=False)
     1440>>> price.full_validate()
    14351441Traceback (most recent call last):
    14361442  ...
    1437 UnresolvableValidationError: {'quantity': [u'This field cannot be null.']}
     1443ValidationError: {'quantity': [u'This field cannot be null.']}
     1444
     1445The form should not validate fields that it doesn't contain even if they are
     1446specified using 'fields', not 'exclude'.
     1447
     1448>>> class PriceForm(ModelForm):
     1449...     class Meta:
     1450...         model = Price
     1451...         fields = ('price',)
     1452>>> form = PriceForm({'price': '6.00'})
     1453>>> form.is_valid()
     1454True
     1455
     1456The form should still have an instance of a model that is not complete and
     1457not saved into a DB yet.
     1458
     1459>>> form.instance.price
     1460Decimal('6.00')
     1461>>> form.instance.quantity is None
     1462True
     1463>>> form.instance.pk is None
     1464True
    14381465
    14391466# Unique & unique together with null values
    14401467>>> class BookForm(ModelForm):
  • tests/regressiontests/admin_views/tests.py

    === modified file 'tests/regressiontests/admin_views/tests.py'
     
    44import datetime
    55from django.core.files import temp as tempfile
    66from django.test import TestCase
    7 from django.contrib.auth.models import User, Permission
     7from django.contrib.auth.models import User, Permission, UNUSABLE_PASSWORD
     8from django.contrib.auth import admin
    89from django.contrib.contenttypes.models import ContentType
    910from django.contrib.admin.models import LogEntry, DELETION
    1011from django.contrib.admin.sites import LOGIN_FORM_KEY
     
    622623        response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/history/' % quote(self.pk))
    623624        self.assertContains(response, escape(self.pk))
    624625        self.failUnlessEqual(response.status_code, 200)
    625  
     626
    626627    def test_get_change_view(self):
    627628        "Retrieving the object using urlencoded form of primary key should work"
    628629        response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/' % quote(self.pk))
     
    17531754        self.assertEqual(Post.objects.count(), 2)
    17541755        p = Post.objects.order_by('-id')[0]
    17551756        self.assertEqual(p.posted, datetime.date.today())
     1757
     1758class IncompleteFormTest(TestCase):
     1759    """
     1760    Tests validation of a ModelForm that doesn't explicitly have all data
     1761    corresponding to model fields. Model validation shouldn't fail
     1762    such a forms.
     1763    """
     1764    fixtures = ['admin-views-users.xml']
     1765
     1766    def setUp(self):
     1767        self.client.login(username='super', password='secret')
     1768
     1769    def tearDown(self):
     1770        self.client.logout()
     1771
     1772    def test_user_creation(self):
     1773        response = self.client.post('/test_admin/admin/auth/user/add/', {
     1774            'username': 'newuser',
     1775            'password1': 'newpassword',
     1776            'password2': 'newpassword',
     1777        })
     1778        new_user = User.objects.order_by('-id')[0]
     1779        self.assertRedirects(response, '/test_admin/admin/auth/user/%s/' % new_user.pk)
     1780        self.assertNotEquals(new_user.password, UNUSABLE_PASSWORD)
     1781
     1782    def test_password_mismatch(self):
     1783        response = self.client.post('/test_admin/admin/auth/user/add/', {
     1784            'username': 'newuser',
     1785            'password1': 'newpassword',
     1786            'password2': 'mismatch',
     1787        })
     1788        self.assertEquals(response.status_code, 200)
     1789        self.assert_('password' not in response.context['form'].errors)
     1790        self.assertFormError(response, 'form', 'password2', ["The two password fields didn't match."])
Back to Top