Updated some tests to use the check framework and silenced a PendingDeprecationWarning.
This commit is contained in:
parent
9c8d62a06f
commit
a938fff030
|
@ -1,6 +1,7 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
import warnings
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib.admin.options import (ModelAdmin, TabularInline,
|
from django.contrib.admin.options import (ModelAdmin, TabularInline,
|
||||||
|
@ -14,7 +15,6 @@ from django.core.checks import Error
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
from django.forms.models import BaseModelFormSet
|
from django.forms.models import BaseModelFormSet
|
||||||
from django.forms.widgets import Select
|
from django.forms.widgets import Select
|
||||||
from django.utils import six
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from .models import Band, Concert, ValidationTestModel, ValidationTestInlineModel
|
from .models import Band, Concert, ValidationTestModel, ValidationTestInlineModel
|
||||||
|
@ -794,13 +794,10 @@ class FilterHorizontalCheckTests(CheckTestCase):
|
||||||
class ValidationTestModelAdmin(ModelAdmin):
|
class ValidationTestModelAdmin(ModelAdmin):
|
||||||
filter_horizontal = 10
|
filter_horizontal = 10
|
||||||
|
|
||||||
six.assertRaisesRegex(
|
self.assertIsInvalid(
|
||||||
self,
|
ValidationTestModelAdmin, ValidationTestModel,
|
||||||
ImproperlyConfigured,
|
'"filter_horizontal" must be a list or tuple.',
|
||||||
"'ValidationTestModelAdmin.filter_horizontal' must be a list or tuple.",
|
'admin.E018')
|
||||||
ValidationTestModelAdmin.validate,
|
|
||||||
ValidationTestModel,
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_missing_field(self):
|
def test_missing_field(self):
|
||||||
class ValidationTestModelAdmin(ModelAdmin):
|
class ValidationTestModelAdmin(ModelAdmin):
|
||||||
|
@ -932,13 +929,10 @@ class ListDisplayTests(CheckTestCase):
|
||||||
class ValidationTestModelAdmin(ModelAdmin):
|
class ValidationTestModelAdmin(ModelAdmin):
|
||||||
list_display = 10
|
list_display = 10
|
||||||
|
|
||||||
six.assertRaisesRegex(
|
self.assertIsInvalid(
|
||||||
self,
|
ValidationTestModelAdmin, ValidationTestModel,
|
||||||
ImproperlyConfigured,
|
'"list_display" must be a list or tuple.',
|
||||||
"'ValidationTestModelAdmin.list_display' must be a list or tuple.",
|
'admin.E107')
|
||||||
ValidationTestModelAdmin.validate,
|
|
||||||
ValidationTestModel,
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_missing_field(self):
|
def test_missing_field(self):
|
||||||
class ValidationTestModelAdmin(ModelAdmin):
|
class ValidationTestModelAdmin(ModelAdmin):
|
||||||
|
@ -1470,11 +1464,14 @@ class FormsetCheckTests(CheckTestCase):
|
||||||
class CustomModelAdminTests(CheckTestCase):
|
class CustomModelAdminTests(CheckTestCase):
|
||||||
def test_deprecation(self):
|
def test_deprecation(self):
|
||||||
"Deprecated Custom Validator definitions still work with the check framework."
|
"Deprecated Custom Validator definitions still work with the check framework."
|
||||||
class CustomValidator(ModelAdminValidator):
|
with warnings.catch_warnings():
|
||||||
def validate_me(self, model_admin, model):
|
warnings.simplefilter("ignore", category=PendingDeprecationWarning)
|
||||||
raise ImproperlyConfigured('error!')
|
|
||||||
|
|
||||||
class CustomModelAdmin(ModelAdmin):
|
class CustomValidator(ModelAdminValidator):
|
||||||
validator_class = CustomValidator
|
def validate_me(self, model_admin, model):
|
||||||
|
raise ImproperlyConfigured('error!')
|
||||||
|
|
||||||
self.assertIsInvalid(CustomModelAdmin, ValidationTestModel, 'error!')
|
class CustomModelAdmin(ModelAdmin):
|
||||||
|
validator_class = CustomValidator
|
||||||
|
|
||||||
|
self.assertIsInvalid(CustomModelAdmin, ValidationTestModel, 'error!')
|
||||||
|
|
Loading…
Reference in New Issue