diff options
| author | Alasdair Nicol <alasdair@thenicols.net> | 2013-08-11 21:19:09 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2013-08-15 19:47:26 -0400 |
| commit | 22c6497f990fd12359b759a71abfcbf3f52b2d52 (patch) | |
| tree | c04062583cf2cffabc193e635542fa91d99e163e /tests/check/tests.py | |
| parent | 55339a76691724109770092976e660ac62358bc5 (diff) | |
Fixed #20895 -- Made check management command warn if a BooleanField does not have a default value
Thanks to Collin Anderson for the suggestion and Tim Graham for
reviewing the patch.
Diffstat (limited to 'tests/check/tests.py')
| -rw-r--r-- | tests/check/tests.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/check/tests.py b/tests/check/tests.py index 98495e38ae..3faf086557 100644 --- a/tests/check/tests.py +++ b/tests/check/tests.py @@ -2,8 +2,10 @@ from django.core.checks.compatibility import base from django.core.checks.compatibility import django_1_6_0 from django.core.management.commands import check from django.core.management import call_command +from django.db.models.fields import NOT_PROVIDED from django.test import TestCase +from .models import Book class StubCheckModule(object): # Has no ``run_checks`` attribute & will trigger a warning. @@ -53,6 +55,24 @@ class CompatChecksTestCase(TestCase): with self.settings(TEST_RUNNER='myapp.test.CustomRunnner'): self.assertEqual(len(django_1_6_0.run_checks()), 0) + def test_boolean_field_default_value(self): + with self.settings(TEST_RUNNER='myapp.test.CustomRunnner'): + # We patch the field's default value to trigger the warning + boolean_field = Book._meta.get_field('is_published') + old_default = boolean_field.default + try: + boolean_field.default = NOT_PROVIDED + result = django_1_6_0.run_checks() + self.assertEqual(len(result), 1) + self.assertTrue("You have not set a default value for one or more BooleanFields" in result[0]) + self.assertTrue('check.Book: "is_published"' in result[0]) + # We did not patch the BlogPost.is_published field so + # there should not be a warning about it + self.assertFalse('check.BlogPost' in result[0]) + finally: + # Restore the ``default`` + boolean_field.default = old_default + def test_check_compatibility(self): with self.settings(TEST_RUNNER='django.test.runner.DiscoverRunner'): result = base.check_compatibility() |
