2015-01-01 23:31:36 +08:00
|
|
|
from django.core import checks
|
2015-01-28 20:35:27 +08:00
|
|
|
from django.db import models
|
2015-01-01 23:31:36 +08:00
|
|
|
from django.test import SimpleTestCase
|
2015-11-17 13:39:28 +08:00
|
|
|
from django.test.utils import isolate_apps
|
2015-01-01 23:31:36 +08:00
|
|
|
|
|
|
|
|
2015-11-17 13:39:28 +08:00
|
|
|
@isolate_apps("check_framework")
|
|
|
|
class TestDeprecatedField(SimpleTestCase):
|
2015-01-01 23:31:36 +08:00
|
|
|
def test_default_details(self):
|
|
|
|
class MyField(models.Field):
|
|
|
|
system_check_deprecated_details = {}
|
|
|
|
|
|
|
|
class Model(models.Model):
|
|
|
|
name = MyField()
|
|
|
|
|
|
|
|
model = Model()
|
|
|
|
self.assertEqual(
|
|
|
|
model.check(),
|
|
|
|
[
|
|
|
|
checks.Warning(
|
|
|
|
msg="MyField has been deprecated.",
|
|
|
|
obj=Model._meta.get_field("name"),
|
|
|
|
id="fields.WXXX",
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_user_specified_details(self):
|
|
|
|
class MyField(models.Field):
|
|
|
|
system_check_deprecated_details = {
|
|
|
|
"msg": "This field is deprecated and will be removed soon.",
|
|
|
|
"hint": "Use something else.",
|
|
|
|
"id": "fields.W999",
|
|
|
|
}
|
|
|
|
|
|
|
|
class Model(models.Model):
|
|
|
|
name = MyField()
|
|
|
|
|
|
|
|
model = Model()
|
|
|
|
self.assertEqual(
|
|
|
|
model.check(),
|
|
|
|
[
|
|
|
|
checks.Warning(
|
|
|
|
msg="This field is deprecated and will be removed soon.",
|
|
|
|
hint="Use something else.",
|
|
|
|
obj=Model._meta.get_field("name"),
|
|
|
|
id="fields.W999",
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2015-11-17 13:39:28 +08:00
|
|
|
@isolate_apps("check_framework")
|
|
|
|
class TestRemovedField(SimpleTestCase):
|
2015-01-01 23:31:36 +08:00
|
|
|
def test_default_details(self):
|
|
|
|
class MyField(models.Field):
|
|
|
|
system_check_removed_details = {}
|
|
|
|
|
|
|
|
class Model(models.Model):
|
|
|
|
name = MyField()
|
|
|
|
|
|
|
|
model = Model()
|
|
|
|
self.assertEqual(
|
|
|
|
model.check(),
|
|
|
|
[
|
|
|
|
checks.Error(
|
|
|
|
msg=(
|
|
|
|
"MyField has been removed except for support in historical "
|
|
|
|
"migrations."
|
|
|
|
),
|
|
|
|
obj=Model._meta.get_field("name"),
|
|
|
|
id="fields.EXXX",
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_user_specified_details(self):
|
|
|
|
class MyField(models.Field):
|
|
|
|
system_check_removed_details = {
|
|
|
|
"msg": "Support for this field is gone.",
|
|
|
|
"hint": "Use something else.",
|
|
|
|
"id": "fields.E999",
|
|
|
|
}
|
|
|
|
|
|
|
|
class Model(models.Model):
|
|
|
|
name = MyField()
|
|
|
|
|
|
|
|
model = Model()
|
|
|
|
self.assertEqual(
|
|
|
|
model.check(),
|
|
|
|
[
|
|
|
|
checks.Error(
|
|
|
|
msg="Support for this field is gone.",
|
|
|
|
hint="Use something else.",
|
|
|
|
obj=Model._meta.get_field("name"),
|
|
|
|
id="fields.E999",
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)
|