Removed BaseDatabaseValidation.validate_field() per deprecation timeline.

This commit is contained in:
Tim Graham 2015-01-17 14:58:09 -05:00
parent e1b93dbbef
commit 3b570dbcdb
2 changed files with 1 additions and 61 deletions

View File

@ -1,6 +1,3 @@
from django.core import checks
class BaseDatabaseValidation(object):
"""
This class encapsulates all backend-specific model validation.
@ -8,31 +5,5 @@ class BaseDatabaseValidation(object):
def __init__(self, connection):
self.connection = connection
def validate_field(self, errors, opts, f):
"""
By default, there is no backend-specific validation.
This method has been deprecated by the new checks framework. New
backends should implement check_field instead.
"""
# This is deliberately commented out. It exists as a marker to
# remind us to remove this method, and the check_field() shim,
# when the time comes.
# warnings.warn('"validate_field" has been deprecated", RemovedInDjango19Warning)
pass
def check_field(self, field, **kwargs):
class ErrorList(list):
"""A dummy list class that emulates API used by the older
validate_field() method. When validate_field() is fully
deprecated, this dummy can be removed too.
"""
def add(self, opts, error_message):
self.append(checks.Error(error_message, hint=None, obj=field))
errors = ErrorList()
# Some tests create fields in isolation -- the fields are not attached
# to any model, so they have no `model` attribute.
opts = field.model._meta if hasattr(field, 'model') else None
self.validate_field(errors, field, opts)
return list(errors)
return []

View File

@ -35,34 +35,3 @@ class BackendSpecificChecksTests(IsolatedModelsTestCase):
v.check_field = old_check_field
self.assertEqual(errors, [error])
def test_validate_field(self):
""" Errors raised by deprecated `validate_field` method should be
collected. """
def mock(self, errors, opts, field):
errors.add(opts, "An error!")
class Model(models.Model):
field = models.IntegerField()
field = Model._meta.get_field('field')
expected = [
Error(
"An error!",
hint=None,
obj=field,
)
]
# Mock connection.validation.validate_field method.
v = connection.validation
old_validate_field = v.validate_field
v.validate_field = MethodType(mock, v)
try:
errors = field.check()
finally:
# Unmock connection.validation.validate_field method.
v.validate_field = old_validate_field
self.assertEqual(errors, expected)