summaryrefslogtreecommitdiff
path: root/tests/modeltests/validation
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2011-06-09 15:05:13 +0000
committerAndrew Godwin <andrew@aeracode.org>2011-06-09 15:05:13 +0000
commit865d684a8af8e3ef7a11c43df861e1a69b0d8cd4 (patch)
tree4948fd03776625e51e507ee46f288536b7e66ed1 /tests/modeltests/validation
parent7f6675a5fb5a11b00ecf61f1fceaa914d42daa01 (diff)
Fixed #8913 - Make "must be unique" error messages customisable. Thanks to Leah Culver.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16345 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/modeltests/validation')
-rw-r--r--tests/modeltests/validation/models.py4
-rw-r--r--tests/modeltests/validation/test_unique.py21
2 files changed, 24 insertions, 1 deletions
diff --git a/tests/modeltests/validation/models.py b/tests/modeltests/validation/models.py
index 861d1440fe..923e5a88c5 100644
--- a/tests/modeltests/validation/models.py
+++ b/tests/modeltests/validation/models.py
@@ -78,3 +78,7 @@ class FlexibleDatePost(models.Model):
slug = models.CharField(max_length=50, unique_for_year='posted', blank=True)
subtitle = models.CharField(max_length=50, unique_for_month='posted', blank=True)
posted = models.DateField(blank=True, null=True)
+
+class UniqueErrorsModel(models.Model):
+ name = models.CharField(max_length=100, unique=True, error_messages={'unique': u'Custom unique name message.'})
+ number = models.IntegerField(unique=True, error_messages={'unique': u'Custom unique number message.'}) \ No newline at end of file
diff --git a/tests/modeltests/validation/test_unique.py b/tests/modeltests/validation/test_unique.py
index 223aa021e4..90616126a5 100644
--- a/tests/modeltests/validation/test_unique.py
+++ b/tests/modeltests/validation/test_unique.py
@@ -7,7 +7,7 @@ from django.test import TestCase
from django.utils import unittest
from models import (CustomPKModel, UniqueTogetherModel, UniqueFieldsModel,
- UniqueForDateModel, ModelToValidate, Post, FlexibleDatePost)
+ UniqueForDateModel, ModelToValidate, Post, FlexibleDatePost, UniqueErrorsModel)
class GetUniqueCheckTests(unittest.TestCase):
@@ -149,3 +149,22 @@ class PerformUniqueChecksTest(TestCase):
self.fail("unique_for_month checks shouldn't trigger when the associated DateField is None.")
except:
self.fail("unique_for_month checks shouldn't explode when the associated DateField is None.")
+
+ def test_unique_errors(self):
+ m1 = UniqueErrorsModel.objects.create(name='Some Name', number=10)
+ m = UniqueErrorsModel(name='Some Name', number=11)
+ try:
+ m.full_clean()
+ except ValidationError, e:
+ self.assertEqual(e.message_dict, {'name': [u'Custom unique name message.']})
+ except:
+ self.fail('unique checks should catch this.')
+
+ m = UniqueErrorsModel(name='Some Other Name', number=10)
+ try:
+ m.full_clean()
+ except ValidationError, e:
+ self.assertEqual(e.message_dict, {'number': [u'Custom unique number message.']})
+ except:
+ self.fail('unique checks should catch this.')
+ \ No newline at end of file