mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #25241 -- Corrected ModelForm.save() error message when saving invalid form with UUIDField pk.
This commit is contained in:
29
tests/model_forms/test_uuid.py
Normal file
29
tests/model_forms/test_uuid.py
Normal file
@@ -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()
|
||||
Reference in New Issue
Block a user