summaryrefslogtreecommitdiff
path: root/tests/model_forms
diff options
context:
space:
mode:
Diffstat (limited to 'tests/model_forms')
-rw-r--r--tests/model_forms/models.py4
-rw-r--r--tests/model_forms/tests.py35
2 files changed, 38 insertions, 1 deletions
diff --git a/tests/model_forms/models.py b/tests/model_forms/models.py
index a79d9b8c5b..9c5e097106 100644
--- a/tests/model_forms/models.py
+++ b/tests/model_forms/models.py
@@ -255,3 +255,7 @@ class Colour(models.Model):
class ColourfulItem(models.Model):
name = models.CharField(max_length=50)
colours = models.ManyToManyField(Colour)
+
+class ArticleStatusNote(models.Model):
+ name = models.CharField(max_length=20)
+ status = models.ManyToManyField(ArticleStatus)
diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py
index db8b6cf0e7..5219804e0c 100644
--- a/tests/model_forms/tests.py
+++ b/tests/model_forms/tests.py
@@ -24,7 +24,7 @@ from .models import (Article, ArticleStatus, BetterAuthor, BigInt,
DerivedPost, ExplicitPK, FlexibleDatePost, ImprovedArticle,
ImprovedArticleWithParentLink, Inventory, Post, Price,
Product, TextFile, AuthorProfile, Colour, ColourfulItem,
- test_images)
+ ArticleStatusNote, test_images)
if test_images:
from .models import ImageFile, OptionalImageFile
@@ -234,6 +234,20 @@ class ColourfulItemForm(forms.ModelForm):
model = ColourfulItem
fields = '__all__'
+# model forms for testing work on #9321:
+
+class StatusNoteForm(forms.ModelForm):
+ class Meta:
+ model = ArticleStatusNote
+ fields = '__all__'
+
+
+class StatusNoteCBM2mForm(forms.ModelForm):
+ class Meta:
+ model = ArticleStatusNote
+ fields = '__all__'
+ widgets = {'status': forms.CheckboxSelectMultiple}
+
class ModelFormBaseTest(TestCase):
def test_base_form(self):
@@ -1677,3 +1691,22 @@ class OldFormForXTests(TestCase):
<option value="%(blue_pk)s">Blue</option>
</select> <span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></p>"""
% {'blue_pk': colour.pk})
+
+
+class M2mHelpTextTest(TestCase):
+ """Tests for ticket #9321."""
+ def test_multiple_widgets(self):
+ """Help text of different widgets for ManyToManyFields model fields"""
+ dreaded_help_text = '<span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span>'
+
+ # Default widget (SelectMultiple):
+ std_form = StatusNoteForm()
+ self.assertInHTML(dreaded_help_text, std_form.as_p())
+
+ # Overridden widget (CheckboxSelectMultiple, a subclass of
+ # SelectMultiple but with a UI that doesn't involve Control/Command
+ # keystrokes to extend selection):
+ form = StatusNoteCBM2mForm()
+ html = form.as_p()
+ self.assertInHTML('<ul id="id_status">', html)
+ self.assertInHTML(dreaded_help_text, html, count=0)