Kaydet (Commit) a938fff0 authored tarafından Tim Graham's avatar Tim Graham

Updated some tests to use the check framework and silenced a PendingDeprecationWarning.

üst 9c8d62a0
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 ...@@ -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): ...@@ -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): ...@@ -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): ...@@ -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 CustomValidator(ModelAdminValidator):
def validate_me(self, model_admin, model):
raise ImproperlyConfigured('error!')
class CustomModelAdmin(ModelAdmin): class CustomModelAdmin(ModelAdmin):
validator_class = CustomValidator validator_class = CustomValidator
self.assertIsInvalid(CustomModelAdmin, ValidationTestModel, 'error!') self.assertIsInvalid(CustomModelAdmin, ValidationTestModel, 'error!')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment