diff options
| author | Tim Graham <timograham@gmail.com> | 2015-08-06 17:43:55 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-08-07 07:44:59 -0400 |
| commit | f2b665f88610b208196b5753b09b4a5cfb322417 (patch) | |
| tree | ed5cf7a32d6197e38ffabb97ded1deb456bd999c /tests/model_forms | |
| parent | 3e1bb5cfb8f9676e0c045f0d101a094437133b54 (diff) | |
Fixed #25241 -- Corrected ModelForm.save() error message when saving invalid form with UUIDField pk.
Diffstat (limited to 'tests/model_forms')
| -rw-r--r-- | tests/model_forms/models.py | 6 | ||||
| -rw-r--r-- | tests/model_forms/test_uuid.py | 29 | ||||
| -rw-r--r-- | tests/model_forms/tests.py | 2 |
3 files changed, 36 insertions, 1 deletions
diff --git a/tests/model_forms/models.py b/tests/model_forms/models.py index f7dca5bb77..b68714af4c 100644 --- a/tests/model_forms/models.py +++ b/tests/model_forms/models.py @@ -11,6 +11,7 @@ from __future__ import unicode_literals import datetime import os import tempfile +import uuid from django.core import validators from django.core.exceptions import ValidationError @@ -447,3 +448,8 @@ class Photo(models.Model): def save(self, force_insert=False, force_update=False): super(Photo, self).save(force_insert, force_update) self._savecount += 1 + + +class UUIDPK(models.Model): + uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) + name = models.CharField(max_length=30) diff --git a/tests/model_forms/test_uuid.py b/tests/model_forms/test_uuid.py new file mode 100644 index 0000000000..4dc7d511d7 --- /dev/null +++ b/tests/model_forms/test_uuid.py @@ -0,0 +1,29 @@ +from __future__ import unicode_literals + +from django import forms +from django.test import TestCase + +from .models import UUIDPK + + +class UUIDPKForm(forms.ModelForm): + class Meta: + model = UUIDPK + fields = '__all__' + + +class ModelFormBaseTest(TestCase): + def test_create_save_error(self): + form = UUIDPKForm({}) + self.assertFalse(form.is_valid()) + msg = "The UUIDPK could not be created because the data didn't validate." + with self.assertRaisesMessage(ValueError, msg): + form.save() + + def test_update_save_error(self): + obj = UUIDPK.objects.create(name='foo') + form = UUIDPKForm({}, instance=obj) + self.assertFalse(form.is_valid()) + msg = "The UUIDPK could not be changed because the data didn't validate." + with self.assertRaisesMessage(ValueError, msg): + form.save() diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py index 7de74e4343..d118785bd4 100644 --- a/tests/model_forms/tests.py +++ b/tests/model_forms/tests.py @@ -1978,7 +1978,7 @@ class FileAndImageFieldTests(TestCase): form = FPForm() names = [p[1] for p in form['path'].field.choices] names.sort() - self.assertEqual(names, ['---------', '__init__.py', 'models.py', 'tests.py']) + self.assertEqual(names, ['---------', '__init__.py', 'models.py', 'test_uuid.py', 'tests.py']) @skipUnless(test_images, "Pillow not installed") def test_image_field(self): |
