diff --git a/tests/validation/models.py b/tests/validation/models.py
index db08329..6944293 100644
a
|
b
|
def validate_answer_to_universe(value):
|
11 | 11 | if value != 42: |
12 | 12 | raise ValidationError('This is not the answer to life, universe and everything!', code='not42') |
13 | 13 | |
| 14 | def validate_m2m_fied(value): |
| 15 | raise ValidationError('Many to many validator called') |
| 16 | |
| 17 | |
14 | 18 | class ModelToValidate(models.Model): |
15 | 19 | name = models.CharField(max_length=100) |
16 | 20 | created = models.DateTimeField(default=datetime.now) |
… |
… |
class GenericIPAddressTestModel(models.Model):
|
97 | 101 | class GenericIPAddrUnpackUniqueTest(models.Model): |
98 | 102 | generic_v4unpack_ip = models.GenericIPAddressField(blank=True, unique=True, unpack_ipv4=True) |
99 | 103 | |
| 104 | class M2mModel(models.Model): |
| 105 | authors = models.ManyToManyField(Author, validators=[validate_m2m_fied]) |
| 106 | |
100 | 107 | |
101 | 108 | # A model can't have multiple AutoFields |
102 | 109 | # Refs #12467. |
diff --git a/tests/validation/tests.py b/tests/validation/tests.py
index 58b7b94..65678b9 100644
a
|
b
|
from django.test import TestCase
|
6 | 6 | |
7 | 7 | from . import ValidationTestCase |
8 | 8 | from .models import (Author, Article, ModelToValidate, |
9 | | GenericIPAddressTestModel, GenericIPAddrUnpackUniqueTest) |
| 9 | GenericIPAddressTestModel, GenericIPAddrUnpackUniqueTest, M2mModel) |
10 | 10 | |
11 | 11 | # Import other tests for this package. |
12 | 12 | from .test_custom_messages import CustomMessagesTest |
… |
… |
class ArticleForm(forms.ModelForm):
|
67 | 67 | model = Article |
68 | 68 | exclude = ['author'] |
69 | 69 | |
| 70 | |
| 71 | class M2mForm(forms.ModelForm): |
| 72 | class Meta: |
| 73 | model = M2mModel |
| 74 | |
| 75 | |
70 | 76 | class ModelFormsTests(TestCase): |
71 | 77 | def setUp(self): |
72 | 78 | self.author = Author.objects.create(name='Joseph Kocherhans') |
… |
… |
class ModelFormsTests(TestCase):
|
110 | 116 | form = ArticleForm(data, instance=article) |
111 | 117 | self.assertEqual(list(form.errors), ['pub_date']) |
112 | 118 | |
| 119 | def test_m2m_validator_gets_called(self): |
| 120 | # checks if the custom validator on the m2m field authors gets called |
| 121 | form = M2mForm({'authors': [self.author.pk]}) |
| 122 | self.assertEqual(list(form.errors), ['authors']) |
| 123 | |
113 | 124 | |
114 | 125 | class GenericIPAddressFieldTests(ValidationTestCase): |
115 | 126 | |