diff options
| author | Tim Graham <timograham@gmail.com> | 2016-10-31 15:21:05 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-10-31 15:21:05 -0400 |
| commit | 2f9861d823620da7ecb291a8f005f53da12b1e89 (patch) | |
| tree | 31e882eaf3e99a486bea89fe25c0b246f9b94988 /tests | |
| parent | de91c172cfda624451fab9a87be92cc0d32e1fcf (diff) | |
Fixed #27148 -- Fixed ModelMultipleChoiceField crash with invalid UUID.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/model_fields/test_uuid.py | 8 | ||||
| -rw-r--r-- | tests/model_forms/test_uuid.py | 6 |
2 files changed, 10 insertions, 4 deletions
diff --git a/tests/model_fields/test_uuid.py b/tests/model_fields/test_uuid.py index 1c173e526d..1e032ce9b0 100644 --- a/tests/model_fields/test_uuid.py +++ b/tests/model_fields/test_uuid.py @@ -40,17 +40,17 @@ class TestSaveLoad(TestCase): self.assertIsNone(loaded.field) def test_pk_validated(self): - with self.assertRaisesMessage(TypeError, 'is not a valid UUID'): + with self.assertRaisesMessage(exceptions.ValidationError, 'is not a valid UUID'): PrimaryKeyUUIDModel.objects.get(pk={}) - with self.assertRaisesMessage(TypeError, 'is not a valid UUID'): + with self.assertRaisesMessage(exceptions.ValidationError, 'is not a valid UUID'): PrimaryKeyUUIDModel.objects.get(pk=[]) def test_wrong_value(self): - with self.assertRaisesMessage(ValueError, 'badly formed hexadecimal UUID string'): + with self.assertRaisesMessage(exceptions.ValidationError, 'is not a valid UUID'): UUIDModel.objects.get(field='not-a-uuid') - with self.assertRaisesMessage(ValueError, 'badly formed hexadecimal UUID string'): + with self.assertRaisesMessage(exceptions.ValidationError, 'is not a valid UUID'): UUIDModel.objects.create(field='not-a-uuid') diff --git a/tests/model_forms/test_uuid.py b/tests/model_forms/test_uuid.py index 4dc7d511d7..b30da6d465 100644 --- a/tests/model_forms/test_uuid.py +++ b/tests/model_forms/test_uuid.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals from django import forms +from django.core.exceptions import ValidationError from django.test import TestCase from .models import UUIDPK @@ -27,3 +28,8 @@ class ModelFormBaseTest(TestCase): msg = "The UUIDPK could not be changed because the data didn't validate." with self.assertRaisesMessage(ValueError, msg): form.save() + + def test_model_multiple_choice_field_uuid_pk(self): + f = forms.ModelMultipleChoiceField(UUIDPK.objects.all()) + with self.assertRaisesMessage(ValidationError, "'invalid_uuid' is not a valid UUID."): + f.clean(['invalid_uuid']) |
