Ticket #26997: diff.txt

File diff.txt, 1.6 KB (added by Сергей, 8 years ago)

bug fix + tests

Line 
1diff --git a/django/contrib/auth/checks.py b/django/contrib/auth/checks.py
2index e7b5815..9f02304 100644
3--- a/django/contrib/auth/checks.py
4+++ b/django/contrib/auth/checks.py
5@@ -111,7 +111,10 @@ def check_models_permissions(app_configs=None, **kwargs):
6 opts = model._meta
7 builtin_permissions = dict(_get_builtin_permissions(opts))
8 # Check builtin permission name length.
9- max_builtin_permission_name_length = max(len(name) for name in builtin_permissions.values())
10+ if builtin_permissions:
11+ max_builtin_permission_name_length = max(len(name) for name in builtin_permissions.values())
12+ else:
13+ max_builtin_permission_name_length = 0
14 if max_builtin_permission_name_length > permission_name_max_length:
15 verbose_name_max_length = (
16 permission_name_max_length - (max_builtin_permission_name_length - len(opts.verbose_name_raw))
17diff --git a/tests/auth_tests/test_checks.py b/tests/auth_tests/test_checks.py
18index 962444f..9855870 100644
19--- a/tests/auth_tests/test_checks.py
20+++ b/tests/auth_tests/test_checks.py
21@@ -195,3 +195,12 @@ class ModelsPermissionsChecksTests(SimpleTestCase):
22 id='auth.E008',
23 ),
24 ])
25+
26+ def test_empty_permission_name_max_length(self):
27+ """should not fail on empty permissions"""
28+ class Checked(models.Model):
29+ class Meta:
30+ permissions = ()
31+ default_permissions = ()
32+ errors = checks.run_checks(self.apps.get_app_configs())
33+ self.assertEqual(errors, [])
Back to Top