mirror of
https://github.com/django/django.git
synced 2025-09-26 12:09:19 +00:00
Refs #33476 -- Reformatted code with Black.
This commit is contained in:
parent
f68fa8b45d
commit
9c19aff7c7
1992 changed files with 139577 additions and 96284 deletions
|
@ -5,7 +5,10 @@ from django.core.checks import Error, Warning
|
|||
from django.db import models
|
||||
from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature
|
||||
from django.test.utils import (
|
||||
isolate_apps, modify_settings, override_settings, override_system_checks,
|
||||
isolate_apps,
|
||||
modify_settings,
|
||||
override_settings,
|
||||
override_system_checks,
|
||||
)
|
||||
|
||||
|
||||
|
@ -13,117 +16,133 @@ class EmptyRouter:
|
|||
pass
|
||||
|
||||
|
||||
@isolate_apps('check_framework', attr_name='apps')
|
||||
@isolate_apps("check_framework", attr_name="apps")
|
||||
@override_system_checks([checks.model_checks.check_all_models])
|
||||
class DuplicateDBTableTests(SimpleTestCase):
|
||||
def test_collision_in_same_app(self):
|
||||
class Model1(models.Model):
|
||||
class Meta:
|
||||
db_table = 'test_table'
|
||||
db_table = "test_table"
|
||||
|
||||
class Model2(models.Model):
|
||||
class Meta:
|
||||
db_table = 'test_table'
|
||||
db_table = "test_table"
|
||||
|
||||
self.assertEqual(checks.run_checks(app_configs=self.apps.get_app_configs()), [
|
||||
Error(
|
||||
"db_table 'test_table' is used by multiple models: "
|
||||
"check_framework.Model1, check_framework.Model2.",
|
||||
obj='test_table',
|
||||
id='models.E028',
|
||||
)
|
||||
])
|
||||
self.assertEqual(
|
||||
checks.run_checks(app_configs=self.apps.get_app_configs()),
|
||||
[
|
||||
Error(
|
||||
"db_table 'test_table' is used by multiple models: "
|
||||
"check_framework.Model1, check_framework.Model2.",
|
||||
obj="test_table",
|
||||
id="models.E028",
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
@override_settings(DATABASE_ROUTERS=['check_framework.test_model_checks.EmptyRouter'])
|
||||
@override_settings(
|
||||
DATABASE_ROUTERS=["check_framework.test_model_checks.EmptyRouter"]
|
||||
)
|
||||
def test_collision_in_same_app_database_routers_installed(self):
|
||||
class Model1(models.Model):
|
||||
class Meta:
|
||||
db_table = 'test_table'
|
||||
db_table = "test_table"
|
||||
|
||||
class Model2(models.Model):
|
||||
class Meta:
|
||||
db_table = 'test_table'
|
||||
db_table = "test_table"
|
||||
|
||||
self.assertEqual(checks.run_checks(app_configs=self.apps.get_app_configs()), [
|
||||
Warning(
|
||||
"db_table 'test_table' is used by multiple models: "
|
||||
"check_framework.Model1, check_framework.Model2.",
|
||||
hint=(
|
||||
'You have configured settings.DATABASE_ROUTERS. Verify '
|
||||
'that check_framework.Model1, check_framework.Model2 are '
|
||||
'correctly routed to separate databases.'
|
||||
),
|
||||
obj='test_table',
|
||||
id='models.W035',
|
||||
)
|
||||
])
|
||||
self.assertEqual(
|
||||
checks.run_checks(app_configs=self.apps.get_app_configs()),
|
||||
[
|
||||
Warning(
|
||||
"db_table 'test_table' is used by multiple models: "
|
||||
"check_framework.Model1, check_framework.Model2.",
|
||||
hint=(
|
||||
"You have configured settings.DATABASE_ROUTERS. Verify "
|
||||
"that check_framework.Model1, check_framework.Model2 are "
|
||||
"correctly routed to separate databases."
|
||||
),
|
||||
obj="test_table",
|
||||
id="models.W035",
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
@modify_settings(INSTALLED_APPS={'append': 'basic'})
|
||||
@isolate_apps('basic', 'check_framework', kwarg_name='apps')
|
||||
@modify_settings(INSTALLED_APPS={"append": "basic"})
|
||||
@isolate_apps("basic", "check_framework", kwarg_name="apps")
|
||||
def test_collision_across_apps(self, apps):
|
||||
class Model1(models.Model):
|
||||
class Meta:
|
||||
app_label = 'basic'
|
||||
db_table = 'test_table'
|
||||
app_label = "basic"
|
||||
db_table = "test_table"
|
||||
|
||||
class Model2(models.Model):
|
||||
class Meta:
|
||||
app_label = 'check_framework'
|
||||
db_table = 'test_table'
|
||||
app_label = "check_framework"
|
||||
db_table = "test_table"
|
||||
|
||||
self.assertEqual(checks.run_checks(app_configs=apps.get_app_configs()), [
|
||||
Error(
|
||||
"db_table 'test_table' is used by multiple models: "
|
||||
"basic.Model1, check_framework.Model2.",
|
||||
obj='test_table',
|
||||
id='models.E028',
|
||||
)
|
||||
])
|
||||
self.assertEqual(
|
||||
checks.run_checks(app_configs=apps.get_app_configs()),
|
||||
[
|
||||
Error(
|
||||
"db_table 'test_table' is used by multiple models: "
|
||||
"basic.Model1, check_framework.Model2.",
|
||||
obj="test_table",
|
||||
id="models.E028",
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
@modify_settings(INSTALLED_APPS={'append': 'basic'})
|
||||
@override_settings(DATABASE_ROUTERS=['check_framework.test_model_checks.EmptyRouter'])
|
||||
@isolate_apps('basic', 'check_framework', kwarg_name='apps')
|
||||
@modify_settings(INSTALLED_APPS={"append": "basic"})
|
||||
@override_settings(
|
||||
DATABASE_ROUTERS=["check_framework.test_model_checks.EmptyRouter"]
|
||||
)
|
||||
@isolate_apps("basic", "check_framework", kwarg_name="apps")
|
||||
def test_collision_across_apps_database_routers_installed(self, apps):
|
||||
class Model1(models.Model):
|
||||
class Meta:
|
||||
app_label = 'basic'
|
||||
db_table = 'test_table'
|
||||
app_label = "basic"
|
||||
db_table = "test_table"
|
||||
|
||||
class Model2(models.Model):
|
||||
class Meta:
|
||||
app_label = 'check_framework'
|
||||
db_table = 'test_table'
|
||||
app_label = "check_framework"
|
||||
db_table = "test_table"
|
||||
|
||||
self.assertEqual(checks.run_checks(app_configs=apps.get_app_configs()), [
|
||||
Warning(
|
||||
"db_table 'test_table' is used by multiple models: "
|
||||
"basic.Model1, check_framework.Model2.",
|
||||
hint=(
|
||||
'You have configured settings.DATABASE_ROUTERS. Verify '
|
||||
'that basic.Model1, check_framework.Model2 are correctly '
|
||||
'routed to separate databases.'
|
||||
),
|
||||
obj='test_table',
|
||||
id='models.W035',
|
||||
)
|
||||
])
|
||||
self.assertEqual(
|
||||
checks.run_checks(app_configs=apps.get_app_configs()),
|
||||
[
|
||||
Warning(
|
||||
"db_table 'test_table' is used by multiple models: "
|
||||
"basic.Model1, check_framework.Model2.",
|
||||
hint=(
|
||||
"You have configured settings.DATABASE_ROUTERS. Verify "
|
||||
"that basic.Model1, check_framework.Model2 are correctly "
|
||||
"routed to separate databases."
|
||||
),
|
||||
obj="test_table",
|
||||
id="models.W035",
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
def test_no_collision_for_unmanaged_models(self):
|
||||
class Unmanaged(models.Model):
|
||||
class Meta:
|
||||
db_table = 'test_table'
|
||||
db_table = "test_table"
|
||||
managed = False
|
||||
|
||||
class Managed(models.Model):
|
||||
class Meta:
|
||||
db_table = 'test_table'
|
||||
db_table = "test_table"
|
||||
|
||||
self.assertEqual(checks.run_checks(app_configs=self.apps.get_app_configs()), [])
|
||||
|
||||
def test_no_collision_for_proxy_models(self):
|
||||
class Model(models.Model):
|
||||
class Meta:
|
||||
db_table = 'test_table'
|
||||
db_table = "test_table"
|
||||
|
||||
class ProxyModel(Model):
|
||||
class Meta:
|
||||
|
@ -133,25 +152,28 @@ class DuplicateDBTableTests(SimpleTestCase):
|
|||
self.assertEqual(checks.run_checks(app_configs=self.apps.get_app_configs()), [])
|
||||
|
||||
|
||||
@isolate_apps('check_framework', attr_name='apps')
|
||||
@isolate_apps("check_framework", attr_name="apps")
|
||||
@override_system_checks([checks.model_checks.check_all_models])
|
||||
class IndexNameTests(SimpleTestCase):
|
||||
def test_collision_in_same_model(self):
|
||||
index = models.Index(fields=['id'], name='foo')
|
||||
index = models.Index(fields=["id"], name="foo")
|
||||
|
||||
class Model(models.Model):
|
||||
class Meta:
|
||||
indexes = [index, index]
|
||||
|
||||
self.assertEqual(checks.run_checks(app_configs=self.apps.get_app_configs()), [
|
||||
Error(
|
||||
"index name 'foo' is not unique for model check_framework.Model.",
|
||||
id='models.E029',
|
||||
),
|
||||
])
|
||||
self.assertEqual(
|
||||
checks.run_checks(app_configs=self.apps.get_app_configs()),
|
||||
[
|
||||
Error(
|
||||
"index name 'foo' is not unique for model check_framework.Model.",
|
||||
id="models.E029",
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
def test_collision_in_different_models(self):
|
||||
index = models.Index(fields=['id'], name='foo')
|
||||
index = models.Index(fields=["id"], name="foo")
|
||||
|
||||
class Model1(models.Model):
|
||||
class Meta:
|
||||
|
@ -161,18 +183,21 @@ class IndexNameTests(SimpleTestCase):
|
|||
class Meta:
|
||||
indexes = [index]
|
||||
|
||||
self.assertEqual(checks.run_checks(app_configs=self.apps.get_app_configs()), [
|
||||
Error(
|
||||
"index name 'foo' is not unique among models: "
|
||||
"check_framework.Model1, check_framework.Model2.",
|
||||
id='models.E030',
|
||||
),
|
||||
])
|
||||
self.assertEqual(
|
||||
checks.run_checks(app_configs=self.apps.get_app_configs()),
|
||||
[
|
||||
Error(
|
||||
"index name 'foo' is not unique among models: "
|
||||
"check_framework.Model1, check_framework.Model2.",
|
||||
id="models.E030",
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
def test_collision_abstract_model(self):
|
||||
class AbstractModel(models.Model):
|
||||
class Meta:
|
||||
indexes = [models.Index(fields=['id'], name='foo')]
|
||||
indexes = [models.Index(fields=["id"], name="foo")]
|
||||
abstract = True
|
||||
|
||||
class Model1(AbstractModel):
|
||||
|
@ -181,20 +206,25 @@ class IndexNameTests(SimpleTestCase):
|
|||
class Model2(AbstractModel):
|
||||
pass
|
||||
|
||||
self.assertEqual(checks.run_checks(app_configs=self.apps.get_app_configs()), [
|
||||
Error(
|
||||
"index name 'foo' is not unique among models: "
|
||||
"check_framework.Model1, check_framework.Model2.",
|
||||
id='models.E030',
|
||||
),
|
||||
])
|
||||
self.assertEqual(
|
||||
checks.run_checks(app_configs=self.apps.get_app_configs()),
|
||||
[
|
||||
Error(
|
||||
"index name 'foo' is not unique among models: "
|
||||
"check_framework.Model1, check_framework.Model2.",
|
||||
id="models.E030",
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
def test_no_collision_abstract_model_interpolation(self):
|
||||
class AbstractModel(models.Model):
|
||||
name = models.CharField(max_length=20)
|
||||
|
||||
class Meta:
|
||||
indexes = [models.Index(fields=['name'], name='%(app_label)s_%(class)s_foo')]
|
||||
indexes = [
|
||||
models.Index(fields=["name"], name="%(app_label)s_%(class)s_foo")
|
||||
]
|
||||
abstract = True
|
||||
|
||||
class Model1(AbstractModel):
|
||||
|
@ -205,69 +235,75 @@ class IndexNameTests(SimpleTestCase):
|
|||
|
||||
self.assertEqual(checks.run_checks(app_configs=self.apps.get_app_configs()), [])
|
||||
|
||||
@modify_settings(INSTALLED_APPS={'append': 'basic'})
|
||||
@isolate_apps('basic', 'check_framework', kwarg_name='apps')
|
||||
@modify_settings(INSTALLED_APPS={"append": "basic"})
|
||||
@isolate_apps("basic", "check_framework", kwarg_name="apps")
|
||||
def test_collision_across_apps(self, apps):
|
||||
index = models.Index(fields=['id'], name='foo')
|
||||
index = models.Index(fields=["id"], name="foo")
|
||||
|
||||
class Model1(models.Model):
|
||||
class Meta:
|
||||
app_label = 'basic'
|
||||
app_label = "basic"
|
||||
indexes = [index]
|
||||
|
||||
class Model2(models.Model):
|
||||
class Meta:
|
||||
app_label = 'check_framework'
|
||||
app_label = "check_framework"
|
||||
indexes = [index]
|
||||
|
||||
self.assertEqual(checks.run_checks(app_configs=apps.get_app_configs()), [
|
||||
Error(
|
||||
"index name 'foo' is not unique among models: basic.Model1, "
|
||||
"check_framework.Model2.",
|
||||
id='models.E030',
|
||||
),
|
||||
])
|
||||
self.assertEqual(
|
||||
checks.run_checks(app_configs=apps.get_app_configs()),
|
||||
[
|
||||
Error(
|
||||
"index name 'foo' is not unique among models: basic.Model1, "
|
||||
"check_framework.Model2.",
|
||||
id="models.E030",
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
@modify_settings(INSTALLED_APPS={'append': 'basic'})
|
||||
@isolate_apps('basic', 'check_framework', kwarg_name='apps')
|
||||
@modify_settings(INSTALLED_APPS={"append": "basic"})
|
||||
@isolate_apps("basic", "check_framework", kwarg_name="apps")
|
||||
def test_no_collision_across_apps_interpolation(self, apps):
|
||||
index = models.Index(fields=['id'], name='%(app_label)s_%(class)s_foo')
|
||||
index = models.Index(fields=["id"], name="%(app_label)s_%(class)s_foo")
|
||||
|
||||
class Model1(models.Model):
|
||||
class Meta:
|
||||
app_label = 'basic'
|
||||
app_label = "basic"
|
||||
constraints = [index]
|
||||
|
||||
class Model2(models.Model):
|
||||
class Meta:
|
||||
app_label = 'check_framework'
|
||||
app_label = "check_framework"
|
||||
constraints = [index]
|
||||
|
||||
self.assertEqual(checks.run_checks(app_configs=apps.get_app_configs()), [])
|
||||
|
||||
|
||||
@isolate_apps('check_framework', attr_name='apps')
|
||||
@isolate_apps("check_framework", attr_name="apps")
|
||||
@override_system_checks([checks.model_checks.check_all_models])
|
||||
@skipUnlessDBFeature('supports_table_check_constraints')
|
||||
@skipUnlessDBFeature("supports_table_check_constraints")
|
||||
class ConstraintNameTests(TestCase):
|
||||
def test_collision_in_same_model(self):
|
||||
class Model(models.Model):
|
||||
class Meta:
|
||||
constraints = [
|
||||
models.CheckConstraint(check=models.Q(id__gt=0), name='foo'),
|
||||
models.CheckConstraint(check=models.Q(id__lt=100), name='foo'),
|
||||
models.CheckConstraint(check=models.Q(id__gt=0), name="foo"),
|
||||
models.CheckConstraint(check=models.Q(id__lt=100), name="foo"),
|
||||
]
|
||||
|
||||
self.assertEqual(checks.run_checks(app_configs=self.apps.get_app_configs()), [
|
||||
Error(
|
||||
"constraint name 'foo' is not unique for model "
|
||||
"check_framework.Model.",
|
||||
id='models.E031',
|
||||
),
|
||||
])
|
||||
self.assertEqual(
|
||||
checks.run_checks(app_configs=self.apps.get_app_configs()),
|
||||
[
|
||||
Error(
|
||||
"constraint name 'foo' is not unique for model "
|
||||
"check_framework.Model.",
|
||||
id="models.E031",
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
def test_collision_in_different_models(self):
|
||||
constraint = models.CheckConstraint(check=models.Q(id__gt=0), name='foo')
|
||||
constraint = models.CheckConstraint(check=models.Q(id__gt=0), name="foo")
|
||||
|
||||
class Model1(models.Model):
|
||||
class Meta:
|
||||
|
@ -277,18 +313,23 @@ class ConstraintNameTests(TestCase):
|
|||
class Meta:
|
||||
constraints = [constraint]
|
||||
|
||||
self.assertEqual(checks.run_checks(app_configs=self.apps.get_app_configs()), [
|
||||
Error(
|
||||
"constraint name 'foo' is not unique among models: "
|
||||
"check_framework.Model1, check_framework.Model2.",
|
||||
id='models.E032',
|
||||
),
|
||||
])
|
||||
self.assertEqual(
|
||||
checks.run_checks(app_configs=self.apps.get_app_configs()),
|
||||
[
|
||||
Error(
|
||||
"constraint name 'foo' is not unique among models: "
|
||||
"check_framework.Model1, check_framework.Model2.",
|
||||
id="models.E032",
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
def test_collision_abstract_model(self):
|
||||
class AbstractModel(models.Model):
|
||||
class Meta:
|
||||
constraints = [models.CheckConstraint(check=models.Q(id__gt=0), name='foo')]
|
||||
constraints = [
|
||||
models.CheckConstraint(check=models.Q(id__gt=0), name="foo")
|
||||
]
|
||||
abstract = True
|
||||
|
||||
class Model1(AbstractModel):
|
||||
|
@ -297,19 +338,24 @@ class ConstraintNameTests(TestCase):
|
|||
class Model2(AbstractModel):
|
||||
pass
|
||||
|
||||
self.assertEqual(checks.run_checks(app_configs=self.apps.get_app_configs()), [
|
||||
Error(
|
||||
"constraint name 'foo' is not unique among models: "
|
||||
"check_framework.Model1, check_framework.Model2.",
|
||||
id='models.E032',
|
||||
),
|
||||
])
|
||||
self.assertEqual(
|
||||
checks.run_checks(app_configs=self.apps.get_app_configs()),
|
||||
[
|
||||
Error(
|
||||
"constraint name 'foo' is not unique among models: "
|
||||
"check_framework.Model1, check_framework.Model2.",
|
||||
id="models.E032",
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
def test_no_collision_abstract_model_interpolation(self):
|
||||
class AbstractModel(models.Model):
|
||||
class Meta:
|
||||
constraints = [
|
||||
models.CheckConstraint(check=models.Q(id__gt=0), name='%(app_label)s_%(class)s_foo'),
|
||||
models.CheckConstraint(
|
||||
check=models.Q(id__gt=0), name="%(app_label)s_%(class)s_foo"
|
||||
),
|
||||
]
|
||||
abstract = True
|
||||
|
||||
|
@ -321,42 +367,47 @@ class ConstraintNameTests(TestCase):
|
|||
|
||||
self.assertEqual(checks.run_checks(app_configs=self.apps.get_app_configs()), [])
|
||||
|
||||
@modify_settings(INSTALLED_APPS={'append': 'basic'})
|
||||
@isolate_apps('basic', 'check_framework', kwarg_name='apps')
|
||||
@modify_settings(INSTALLED_APPS={"append": "basic"})
|
||||
@isolate_apps("basic", "check_framework", kwarg_name="apps")
|
||||
def test_collision_across_apps(self, apps):
|
||||
constraint = models.CheckConstraint(check=models.Q(id__gt=0), name='foo')
|
||||
constraint = models.CheckConstraint(check=models.Q(id__gt=0), name="foo")
|
||||
|
||||
class Model1(models.Model):
|
||||
class Meta:
|
||||
app_label = 'basic'
|
||||
app_label = "basic"
|
||||
constraints = [constraint]
|
||||
|
||||
class Model2(models.Model):
|
||||
class Meta:
|
||||
app_label = 'check_framework'
|
||||
app_label = "check_framework"
|
||||
constraints = [constraint]
|
||||
|
||||
self.assertEqual(checks.run_checks(app_configs=apps.get_app_configs()), [
|
||||
Error(
|
||||
"constraint name 'foo' is not unique among models: "
|
||||
"basic.Model1, check_framework.Model2.",
|
||||
id='models.E032',
|
||||
),
|
||||
])
|
||||
self.assertEqual(
|
||||
checks.run_checks(app_configs=apps.get_app_configs()),
|
||||
[
|
||||
Error(
|
||||
"constraint name 'foo' is not unique among models: "
|
||||
"basic.Model1, check_framework.Model2.",
|
||||
id="models.E032",
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
@modify_settings(INSTALLED_APPS={'append': 'basic'})
|
||||
@isolate_apps('basic', 'check_framework', kwarg_name='apps')
|
||||
@modify_settings(INSTALLED_APPS={"append": "basic"})
|
||||
@isolate_apps("basic", "check_framework", kwarg_name="apps")
|
||||
def test_no_collision_across_apps_interpolation(self, apps):
|
||||
constraint = models.CheckConstraint(check=models.Q(id__gt=0), name='%(app_label)s_%(class)s_foo')
|
||||
constraint = models.CheckConstraint(
|
||||
check=models.Q(id__gt=0), name="%(app_label)s_%(class)s_foo"
|
||||
)
|
||||
|
||||
class Model1(models.Model):
|
||||
class Meta:
|
||||
app_label = 'basic'
|
||||
app_label = "basic"
|
||||
constraints = [constraint]
|
||||
|
||||
class Model2(models.Model):
|
||||
class Meta:
|
||||
app_label = 'check_framework'
|
||||
app_label = "check_framework"
|
||||
constraints = [constraint]
|
||||
|
||||
self.assertEqual(checks.run_checks(app_configs=apps.get_app_configs()), [])
|
||||
|
@ -366,14 +417,14 @@ def mocked_is_overridden(self, setting):
|
|||
# Force treating DEFAULT_AUTO_FIELD = 'django.db.models.AutoField' as a not
|
||||
# overridden setting.
|
||||
return (
|
||||
setting != 'DEFAULT_AUTO_FIELD' or
|
||||
self.DEFAULT_AUTO_FIELD != 'django.db.models.AutoField'
|
||||
setting != "DEFAULT_AUTO_FIELD"
|
||||
or self.DEFAULT_AUTO_FIELD != "django.db.models.AutoField"
|
||||
)
|
||||
|
||||
|
||||
@mock.patch('django.conf.UserSettingsHolder.is_overridden', mocked_is_overridden)
|
||||
@override_settings(DEFAULT_AUTO_FIELD='django.db.models.AutoField')
|
||||
@isolate_apps('check_framework.apps.CheckDefaultPKConfig', attr_name='apps')
|
||||
@mock.patch("django.conf.UserSettingsHolder.is_overridden", mocked_is_overridden)
|
||||
@override_settings(DEFAULT_AUTO_FIELD="django.db.models.AutoField")
|
||||
@isolate_apps("check_framework.apps.CheckDefaultPKConfig", attr_name="apps")
|
||||
@override_system_checks([checks.model_checks.check_all_models])
|
||||
class ModelDefaultAutoFieldTests(SimpleTestCase):
|
||||
msg = (
|
||||
|
@ -390,9 +441,12 @@ class ModelDefaultAutoFieldTests(SimpleTestCase):
|
|||
class Model(models.Model):
|
||||
pass
|
||||
|
||||
self.assertEqual(checks.run_checks(app_configs=self.apps.get_app_configs()), [
|
||||
Warning(self.msg, hint=self.hint, obj=Model, id='models.W042'),
|
||||
])
|
||||
self.assertEqual(
|
||||
checks.run_checks(app_configs=self.apps.get_app_configs()),
|
||||
[
|
||||
Warning(self.msg, hint=self.hint, obj=Model, id="models.W042"),
|
||||
],
|
||||
)
|
||||
|
||||
def test_explicit_inherited_pk(self):
|
||||
class Parent(models.Model):
|
||||
|
@ -406,7 +460,7 @@ class ModelDefaultAutoFieldTests(SimpleTestCase):
|
|||
def test_skipped_on_model_with_invalid_app_label(self):
|
||||
class Model(models.Model):
|
||||
class Meta:
|
||||
app_label = 'invalid_app_label'
|
||||
app_label = "invalid_app_label"
|
||||
|
||||
self.assertEqual(Model.check(), [])
|
||||
|
||||
|
@ -434,9 +488,12 @@ class ModelDefaultAutoFieldTests(SimpleTestCase):
|
|||
class Child(Parent):
|
||||
pass
|
||||
|
||||
self.assertEqual(checks.run_checks(app_configs=self.apps.get_app_configs()), [
|
||||
Warning(self.msg, hint=self.hint, obj=Parent, id='models.W042'),
|
||||
])
|
||||
self.assertEqual(
|
||||
checks.run_checks(app_configs=self.apps.get_app_configs()),
|
||||
[
|
||||
Warning(self.msg, hint=self.hint, obj=Parent, id="models.W042"),
|
||||
],
|
||||
)
|
||||
|
||||
def test_auto_created_inherited_parent_link(self):
|
||||
class Parent(models.Model):
|
||||
|
@ -445,9 +502,12 @@ class ModelDefaultAutoFieldTests(SimpleTestCase):
|
|||
class Child(Parent):
|
||||
parent_ptr = models.OneToOneField(Parent, models.CASCADE, parent_link=True)
|
||||
|
||||
self.assertEqual(checks.run_checks(app_configs=self.apps.get_app_configs()), [
|
||||
Warning(self.msg, hint=self.hint, obj=Parent, id='models.W042'),
|
||||
])
|
||||
self.assertEqual(
|
||||
checks.run_checks(app_configs=self.apps.get_app_configs()),
|
||||
[
|
||||
Warning(self.msg, hint=self.hint, obj=Parent, id="models.W042"),
|
||||
],
|
||||
)
|
||||
|
||||
def test_auto_created_pk_inherited_abstract_parent(self):
|
||||
class Parent(models.Model):
|
||||
|
@ -457,11 +517,14 @@ class ModelDefaultAutoFieldTests(SimpleTestCase):
|
|||
class Child(Parent):
|
||||
pass
|
||||
|
||||
self.assertEqual(checks.run_checks(app_configs=self.apps.get_app_configs()), [
|
||||
Warning(self.msg, hint=self.hint, obj=Child, id='models.W042'),
|
||||
])
|
||||
self.assertEqual(
|
||||
checks.run_checks(app_configs=self.apps.get_app_configs()),
|
||||
[
|
||||
Warning(self.msg, hint=self.hint, obj=Child, id="models.W042"),
|
||||
],
|
||||
)
|
||||
|
||||
@override_settings(DEFAULT_AUTO_FIELD='django.db.models.BigAutoField')
|
||||
@override_settings(DEFAULT_AUTO_FIELD="django.db.models.BigAutoField")
|
||||
def test_default_auto_field_setting(self):
|
||||
class Model(models.Model):
|
||||
pass
|
||||
|
@ -474,10 +537,10 @@ class ModelDefaultAutoFieldTests(SimpleTestCase):
|
|||
|
||||
self.assertEqual(checks.run_checks(app_configs=self.apps.get_app_configs()), [])
|
||||
|
||||
@isolate_apps('check_framework.apps.CheckPKConfig', kwarg_name='apps')
|
||||
@isolate_apps("check_framework.apps.CheckPKConfig", kwarg_name="apps")
|
||||
def test_app_default_auto_field(self, apps):
|
||||
class ModelWithPkViaAppConfig(models.Model):
|
||||
class Meta:
|
||||
app_label = 'check_framework.apps.CheckPKConfig'
|
||||
app_label = "check_framework.apps.CheckPKConfig"
|
||||
|
||||
self.assertEqual(checks.run_checks(app_configs=apps.get_app_configs()), [])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue