diff options
| author | Daniel Pyrathon <pirosb3@gmail.com> | 2014-03-13 11:32:20 +0000 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-05-16 05:57:19 -0400 |
| commit | cb15231888df2545356ad307eaea07f36aa0e8e0 (patch) | |
| tree | 74a83620630234fbb739eabf2546bfb82cbedd64 /tests/invalid_models_tests/test_ordinary_fields.py | |
| parent | 8a9d54aa694b45f82c039912d417e2a391198852 (diff) | |
Fixed #21798 -- Added check for DateTime mutually exclusive options
Added DateTimeCheckMixin to avoid the use of default, auto_now, and
auto_now_add options together. Added the fields.E151 Error that is raised
if one or more of these options are used together.
Diffstat (limited to 'tests/invalid_models_tests/test_ordinary_fields.py')
| -rw-r--r-- | tests/invalid_models_tests/test_ordinary_fields.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/invalid_models_tests/test_ordinary_fields.py b/tests/invalid_models_tests/test_ordinary_fields.py index 3ad7e250b0..e42f9bcaaa 100644 --- a/tests/invalid_models_tests/test_ordinary_fields.py +++ b/tests/invalid_models_tests/test_ordinary_fields.py @@ -1,6 +1,7 @@ # -*- encoding: utf-8 -*- from __future__ import unicode_literals +from datetime import datetime import unittest from django.core.checks import Error @@ -399,3 +400,30 @@ class ImageFieldTests(IsolatedModelsTestCase): ), ] self.assertEqual(errors, expected) + + +class DateFieldTests(IsolatedModelsTestCase): + + def test_auto_now_and_auto_now_add_raise_error(self): + dn = datetime.now + mutually_exclusive_combinations = ( + (True, True, dn), + (True, False, dn), + (False, True, dn), + (True, True, None) + ) + + for auto_now, auto_now_add, default in mutually_exclusive_combinations: + field = models.DateTimeField(name="field", auto_now=auto_now, + auto_now_add=auto_now_add, + default=default) + expected = [Error( + "The options auto_now, auto_now_add, and default " + "are mutually exclusive. Only one of these options " + "may be present.", + hint=None, + obj=field, + id='fields.E151', + )] + checks = field.check() + self.assertEqual(checks, expected) |
