Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #12304 -- regression tests to make sure the validation messages…

… for unique violations are sane, Thanks ramiro!

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14198 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 52716ddd1b0541b9cd86fd361a9f8b9894927211 1 parent b7ed25a
Honza Král authored October 13, 2010
9  tests/regressiontests/model_forms_regress/models.py
@@ -60,3 +60,12 @@ class Homepage(models.Model):
60 60
 
61 61
 class Document(models.Model):
62 62
     myfile = models.FileField(upload_to='unused', blank=True)
  63
+
  64
+class Edition(models.Model):
  65
+    author = models.ForeignKey(Person)
  66
+    publication = models.ForeignKey(Publication)
  67
+    edition = models.IntegerField()
  68
+    isbn = models.CharField(max_length=13, unique=True)
  69
+
  70
+    class Meta:
  71
+        unique_together = (('author', 'publication'), ('publication', 'edition'),)
30  tests/regressiontests/model_forms_regress/tests.py
@@ -8,7 +8,7 @@
8 8
 from django.core.files.uploadedfile import SimpleUploadedFile
9 9
 
10 10
 from models import Person, RealPerson, Triple, FilePathModel, Article, \
11  
-    Publication, CustomFF, Author, Author1, Homepage, Document
  11
+    Publication, CustomFF, Author, Author1, Homepage, Document, Edition
12 12
 
13 13
 
14 14
 class ModelMultipleChoiceFieldTests(TestCase):
@@ -389,3 +389,31 @@ def test_clear_and_file_contradiction(self):
389 389
         rendered = unicode(form)
390 390
         self.assert_('something.txt' in rendered)
391 391
         self.assert_('myfile-clear' in rendered)
  392
+
  393
+class EditionForm(forms.ModelForm):
  394
+    author = forms.ModelChoiceField(queryset=Person.objects.all())
  395
+    publication = forms.ModelChoiceField(queryset=Publication.objects.all())
  396
+    edition = forms.IntegerField()
  397
+    isbn = forms.CharField(max_length=13)
  398
+
  399
+    class Meta:
  400
+        model = Edition
  401
+
  402
+class UniqueErrorsTests(TestCase):
  403
+    def setUp(self):
  404
+        self.author1 = Person.objects.create(name=u'Author #1')
  405
+        self.author2 = Person.objects.create(name=u'Author #2')
  406
+        self.pub1 = Publication.objects.create(title='Pub #1', date_published=date(2000, 10, 31))
  407
+        self.pub2 = Publication.objects.create(title='Pub #2', date_published=date(2004, 1, 5))
  408
+        form = EditionForm(data={'author': self.author1.pk, 'publication': self.pub1.pk, 'edition': 1, 'isbn': '9783161484100'})
  409
+        form.save()
  410
+
  411
+    def test_unique_error_message(self):
  412
+        form = EditionForm(data={'author': self.author1.pk, 'publication': self.pub2.pk, 'edition': 1, 'isbn': '9783161484100'})
  413
+        self.assertEquals(form.errors, {'isbn': [u'Edition with this Isbn already exists.']})
  414
+
  415
+    def test_unique_together_error_message(self):
  416
+        form = EditionForm(data={'author': self.author1.pk, 'publication': self.pub1.pk, 'edition': 2, 'isbn': '9783161489999'})
  417
+        self.assertEquals(form.errors, {'__all__': [u'Edition with this Author and Publication already exists.']})
  418
+        form = EditionForm(data={'author': self.author2.pk, 'publication': self.pub1.pk, 'edition': 1, 'isbn': '9783161487777'})
  419
+        self.assertEquals(form.errors, {'__all__': [u'Edition with this Publication and Edition already exists.']})

0 notes on commit 52716dd

Please sign in to comment.
Something went wrong with that request. Please try again.