From d381914aef50e04ca44b9d7bb9274c8351f5b9bf Mon Sep 17 00:00:00 2001 From: michaldabski Date: Thu, 15 Jun 2017 21:44:20 +0100 Subject: Fixed #28313 -- Added model name max length check of 100 characters in contrib.contentttypes. --- tests/contenttypes_tests/test_checks.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tests/contenttypes_tests') diff --git a/tests/contenttypes_tests/test_checks.py b/tests/contenttypes_tests/test_checks.py index 6b33107de2..44cd3c2758 100644 --- a/tests/contenttypes_tests/test_checks.py +++ b/tests/contenttypes_tests/test_checks.py @@ -1,5 +1,6 @@ from unittest import mock +from django.contrib.contenttypes.checks import check_model_name_lengths from django.contrib.contenttypes.fields import ( GenericForeignKey, GenericRelation, ) @@ -216,3 +217,20 @@ class GenericRelationTests(SimpleTestCase): id='fields.E001', ) ]) + + +@isolate_apps('contenttypes_tests', attr_name='apps') +class ModelCheckTests(SimpleTestCase): + def test_model_name_too_long(self): + model = type('A' * 101, (models.Model,), {'__module__': self.__module__}) + self.assertEqual(check_model_name_lengths(self.apps.get_app_configs()), [ + checks.Error( + 'Model names must be at most 100 characters (got 101).', + obj=model, + id='contenttypes.E005', + ) + ]) + + def test_model_name_max_length(self): + type('A' * 100, (models.Model,), {'__module__': self.__module__}) + self.assertEqual(check_model_name_lengths(self.apps.get_app_configs()), []) -- cgit v1.3