summaryrefslogtreecommitdiff
path: root/tests/check
diff options
context:
space:
mode:
authorAlasdair Nicol <alasdair@thenicols.net>2013-08-11 21:19:09 +0100
committerTim Graham <timograham@gmail.com>2013-08-15 19:47:26 -0400
commit22c6497f990fd12359b759a71abfcbf3f52b2d52 (patch)
treec04062583cf2cffabc193e635542fa91d99e163e /tests/check
parent55339a76691724109770092976e660ac62358bc5 (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')
-rw-r--r--tests/check/models.py10
-rw-r--r--tests/check/tests.py20
2 files changed, 29 insertions, 1 deletions
diff --git a/tests/check/models.py b/tests/check/models.py
index 78a10abba6..212b01bdd2 100644
--- a/tests/check/models.py
+++ b/tests/check/models.py
@@ -1 +1,9 @@
-# Stubby.
+from django.db import models
+
+class Book(models.Model):
+ title = models.CharField(max_length=250)
+ is_published = models.BooleanField(default=False)
+
+class BlogPost(models.Model):
+ title = models.CharField(max_length=250)
+ is_published = models.BooleanField(default=False)
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()