diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-03-18 13:27:23 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-03-18 18:41:40 +0100 |
| commit | 5c8441a0b8787c14b45fb761550571baea48604e (patch) | |
| tree | 54e3fd3029dd5c01758d5773e63b644bff6c440e /tests/invalid_models_tests/test_models.py | |
| parent | ba4389a36b5fb1afce0cddb4e28233138b6612b7 (diff) | |
Refs #31055 -- Made long column names checks support databases aware.
Diffstat (limited to 'tests/invalid_models_tests/test_models.py')
| -rw-r--r-- | tests/invalid_models_tests/test_models.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/tests/invalid_models_tests/test_models.py b/tests/invalid_models_tests/test_models.py index 438c327003..9fd7058b20 100644 --- a/tests/invalid_models_tests/test_models.py +++ b/tests/invalid_models_tests/test_models.py @@ -1,6 +1,5 @@ import unittest -from django.conf import settings from django.core.checks import Error, Warning from django.core.checks.model_checks import _check_lazy_references from django.db import connection, connections, models @@ -18,7 +17,7 @@ def get_max_column_name_length(): allowed_len = None db_alias = None - for db in settings.DATABASES: + for db in ('default', 'other'): connection = connections[db] max_name_length = connection.ops.max_name_length() if max_name_length is not None and not connection.features.truncates_names: @@ -408,7 +407,7 @@ class FieldNamesTests(SimpleTestCase): db_column=long_field_name ).contribute_to_class(m2mcomplex, long_field_name) - errors = ModelWithLongField.check() + errors = ModelWithLongField.check(databases=('default', 'other')) # First error because of M2M field set on the model with long name. m2m_long_name = "verylongmodelnamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz_id" @@ -446,6 +445,9 @@ class FieldNamesTests(SimpleTestCase): ) self.assertEqual(errors, expected) + # Check for long column names is called only for specified database + # aliases. + self.assertEqual(ModelWithLongField.check(databases=None), []) @unittest.skipIf(max_column_name_length is None, "The database doesn't have a column name length limit.") def test_local_field_long_column_name(self): @@ -462,7 +464,7 @@ class FieldNamesTests(SimpleTestCase): long_field_name2 = 'b' * (self.max_column_name_length + 1) models.CharField(max_length=11).contribute_to_class(ModelWithLongField, long_field_name) models.CharField(max_length=11, db_column='vlmn').contribute_to_class(ModelWithLongField, long_field_name2) - self.assertEqual(ModelWithLongField.check(), [ + self.assertEqual(ModelWithLongField.check(databases=('default', 'other')), [ Error( 'Autogenerated column name too long for field "%s". ' 'Maximum length is "%s" for database "%s".' @@ -472,6 +474,9 @@ class FieldNamesTests(SimpleTestCase): id='models.E018', ) ]) + # Check for long column names is called only for specified database + # aliases. + self.assertEqual(ModelWithLongField.check(databases=None), []) def test_including_separator(self): class Model(models.Model): |
