diff options
Diffstat (limited to 'tests/check')
| -rw-r--r-- | tests/check/models.py | 10 | ||||
| -rw-r--r-- | tests/check/tests.py | 20 |
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() |
