diff options
| author | Nick Pope <nick.pope@flightdataservices.com> | 2017-12-11 15:36:33 +0000 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-08-20 09:22:25 +0200 |
| commit | 21e559495b8255bba1e8a4429cd083246ab90457 (patch) | |
| tree | 7c28928a42b896f05be9282461dcc0e1db08c03e /tests/invalid_models_tests/test_ordinary_fields.py | |
| parent | b10d322c41f66dc7c77c36f90a3532269b25ea93 (diff) | |
Fixed #29979, Refs #17337 -- Extracted AutoField field logic into a mixin and refactored AutoFields.
This reduces duplication by allowing AutoField, BigAutoField and
SmallAutoField to inherit from IntegerField, BigIntegerField and
SmallIntegerField respectively. Doing so also allows for enabling the
max_length warning check and minimum/maximum value validation for auto
fields, as well as providing a mixin that can be used for other possible
future auto field types such as a theoretical UUIDAutoField.
Diffstat (limited to 'tests/invalid_models_tests/test_ordinary_fields.py')
| -rw-r--r-- | tests/invalid_models_tests/test_ordinary_fields.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/invalid_models_tests/test_ordinary_fields.py b/tests/invalid_models_tests/test_ordinary_fields.py index a3231ee36a..5bb1847a70 100644 --- a/tests/invalid_models_tests/test_ordinary_fields.py +++ b/tests/invalid_models_tests/test_ordinary_fields.py @@ -38,6 +38,21 @@ class AutoFieldTests(SimpleTestCase): ), ]) + def test_max_length_warning(self): + class Model(models.Model): + auto = models.AutoField(primary_key=True, max_length=2) + + field = Model._meta.get_field('auto') + self.assertEqual(field.check(), [ + DjangoWarning( + "'max_length' is ignored when used with %s." + % field.__class__.__name__, + hint="Remove 'max_length' from field", + obj=field, + id='fields.W122', + ), + ]) + @isolate_apps('invalid_models_tests') class BinaryFieldTests(SimpleTestCase): |
