1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
from django.core import checks
from django.db import models
from django.test import SimpleTestCase
from django.test.utils import isolate_apps
@isolate_apps("check_framework")
class TestDeprecatedField(SimpleTestCase):
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",
)
],
)
@isolate_apps("check_framework")
class TestRemovedField(SimpleTestCase):
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",
)
],
)
|