summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2016-07-25 14:04:39 -0400
committerTim Graham <timograham@gmail.com>2016-07-27 08:36:49 -0400
commit3744fc1666c41aeb4ed44f31605bafdb413b42bc (patch)
treec00a9fb34536160e9ac97e878a1dc35821a866b6 /tests
parentd53e3c1e0743909932f9e35c98bbaa2190910f2a (diff)
[1.10.x] Fixed #26917 -- Fixed crash in disabled ModelChoiceFields.
Partially reverted refs #25532 to fix a regression in Django 1.10. This reintroduces a crash for disabled forms.JSONField (refs #26949), however, that issue is also present on Django 1.9. Thanks Ryan Schave for the test. Backport of a5f85d891b51d7ceb4f9e422e3e4f5c741062288 from master
Diffstat (limited to 'tests')
-rw-r--r--tests/model_forms/tests.py15
-rw-r--r--tests/postgres_tests/test_json.py8
2 files changed, 15 insertions, 8 deletions
diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py
index 2f96fcec30..e18b19dcac 100644
--- a/tests/model_forms/tests.py
+++ b/tests/model_forms/tests.py
@@ -1499,6 +1499,21 @@ class ModelChoiceFieldTests(TestCase):
'<label><input name="foo" type="radio" value="" /> ---------</label>'
)
+ def test_disabled_modelchoicefield(self):
+ class ModelChoiceForm(forms.ModelForm):
+ author = forms.ModelChoiceField(Author.objects.all(), disabled=True)
+
+ class Meta:
+ model = Book
+ fields = ['author']
+
+ book = Book.objects.create(author=Writer.objects.create(name='Test writer'))
+ form = ModelChoiceForm({}, instance=book)
+ self.assertEqual(
+ form.errors['author'],
+ ['Select a valid choice. That choice is not one of the available choices.']
+ )
+
class ModelMultipleChoiceFieldTests(TestCase):
def setUp(self):
diff --git a/tests/postgres_tests/test_json.py b/tests/postgres_tests/test_json.py
index 1978552cf9..d4f0a9bb57 100644
--- a/tests/postgres_tests/test_json.py
+++ b/tests/postgres_tests/test_json.py
@@ -260,14 +260,6 @@ class TestFormField(PostgreSQLTestCase):
form_field = model_field.formfield()
self.assertIsInstance(form_field, forms.JSONField)
- def test_formfield_disabled(self):
- class JsonForm(Form):
- name = CharField()
- jfield = forms.JSONField(disabled=True)
-
- form = JsonForm({'name': 'xyz', 'jfield': '["bar"]'}, initial={'jfield': ['foo']})
- self.assertIn('[&quot;foo&quot;]</textarea>', form.as_p())
-
def test_prepare_value(self):
field = forms.JSONField()
self.assertEqual(field.prepare_value({'a': 'b'}), '{"a": "b"}')