diff options
| author | Tim Graham <timograham@gmail.com> | 2015-01-18 14:43:21 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-01-18 14:43:21 -0500 |
| commit | 67a76500a56d6dbe970126e142e02254dad7dbf3 (patch) | |
| tree | 0356f45a58db30ad2cbc36acdb36090ce10e256e /tests | |
| parent | 5fb582d952673067046de0d0ddf37b45675655db (diff) | |
Removed support for admin validators per deprecation timeline; refs #16905.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/admin_checks/tests.py | 23 | ||||
| -rw-r--r-- | tests/admin_validation/__init__.py | 0 | ||||
| -rw-r--r-- | tests/admin_validation/models.py | 57 | ||||
| -rw-r--r-- | tests/admin_validation/tests.py | 319 | ||||
| -rw-r--r-- | tests/admin_views/tests.py | 19 | ||||
| -rw-r--r-- | tests/modeladmin/tests.py | 20 |
6 files changed, 2 insertions, 436 deletions
diff --git a/tests/admin_checks/tests.py b/tests/admin_checks/tests.py index ea0151cced..4f5bd5e48a 100644 --- a/tests/admin_checks/tests.py +++ b/tests/admin_checks/tests.py @@ -4,8 +4,7 @@ from django import forms from django.contrib import admin from django.contrib.contenttypes.admin import GenericStackedInline from django.core import checks -from django.core.exceptions import ImproperlyConfigured -from django.test import TestCase, ignore_warnings, override_settings +from django.test import TestCase, override_settings from .models import Song, Book, Album, TwoAlbumFKAndAnE, City, State, Influence @@ -635,26 +634,6 @@ class SystemChecksTestCase(TestCase): errors = FieldsOnFormOnlyAdmin.check(model=Song) self.assertEqual(errors, []) - @ignore_warnings(module='django.contrib.admin.options') - def test_validator_compatibility(self): - class MyValidator(object): - def validate(self, cls, model): - raise ImproperlyConfigured("error!") - - class MyModelAdmin(admin.ModelAdmin): - validator_class = MyValidator - - errors = MyModelAdmin.check(model=Song) - - expected = [ - checks.Error( - 'error!', - hint=None, - obj=MyModelAdmin, - ) - ] - self.assertEqual(errors, expected) - def test_check_sublists_for_duplicates(self): class MyModelAdmin(admin.ModelAdmin): fields = ['state', ['state']] diff --git a/tests/admin_validation/__init__.py b/tests/admin_validation/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 --- a/tests/admin_validation/__init__.py +++ /dev/null diff --git a/tests/admin_validation/models.py b/tests/admin_validation/models.py deleted file mode 100644 index d23849a2a8..0000000000 --- a/tests/admin_validation/models.py +++ /dev/null @@ -1,57 +0,0 @@ -""" -Tests of ModelAdmin validation logic. -""" - -from django.db import models -from django.utils.encoding import python_2_unicode_compatible - - -class Album(models.Model): - title = models.CharField(max_length=150) - - -@python_2_unicode_compatible -class Song(models.Model): - title = models.CharField(max_length=150) - album = models.ForeignKey(Album) - original_release = models.DateField(editable=False) - - class Meta: - ordering = ('title',) - - def __str__(self): - return self.title - - def readonly_method_on_model(self): - # does nothing - pass - - -class TwoAlbumFKAndAnE(models.Model): - album1 = models.ForeignKey(Album, related_name="album1_set") - album2 = models.ForeignKey(Album, related_name="album2_set") - e = models.CharField(max_length=1) - - -class Author(models.Model): - name = models.CharField(max_length=100) - - -class Book(models.Model): - name = models.CharField(max_length=100) - subtitle = models.CharField(max_length=100) - price = models.FloatField() - authors = models.ManyToManyField(Author, through='AuthorsBooks') - - -class AuthorsBooks(models.Model): - author = models.ForeignKey(Author) - book = models.ForeignKey(Book) - - -class State(models.Model): - name = models.CharField(max_length=15) - - -class City(models.Model): - state = models.ForeignKey(State) diff --git a/tests/admin_validation/tests.py b/tests/admin_validation/tests.py deleted file mode 100644 index 321e10428c..0000000000 --- a/tests/admin_validation/tests.py +++ /dev/null @@ -1,319 +0,0 @@ -from __future__ import unicode_literals - -from django import forms -from django.contrib import admin -from django.core.exceptions import ImproperlyConfigured -from django.test import TestCase, ignore_warnings -from django.test.utils import str_prefix -from django.utils.deprecation import RemovedInDjango19Warning - -from .models import Song, Book, Album, TwoAlbumFKAndAnE, City - - -class SongForm(forms.ModelForm): - pass - - -class ValidFields(admin.ModelAdmin): - form = SongForm - fields = ['title'] - - -class ValidFormFieldsets(admin.ModelAdmin): - def get_form(self, request, obj=None, **kwargs): - class ExtraFieldForm(SongForm): - name = forms.CharField(max_length=50) - return ExtraFieldForm - - fieldsets = ( - (None, { - 'fields': ('name',), - }), - ) - - -@ignore_warnings(category=RemovedInDjango19Warning) -class ValidationTestCase(TestCase): - - def test_readonly_and_editable(self): - class SongAdmin(admin.ModelAdmin): - readonly_fields = ["original_release"] - fieldsets = [ - (None, { - "fields": ["title", "original_release"], - }), - ] - - SongAdmin.validate(Song) - - def test_custom_modelforms_with_fields_fieldsets(self): - """ - # Regression test for #8027: custom ModelForms with fields/fieldsets - """ - ValidFields.validate(Song) - - def test_custom_get_form_with_fieldsets(self): - """ - Ensure that the fieldsets validation is skipped when the ModelAdmin.get_form() method - is overridden. - Refs #19445. - """ - ValidFormFieldsets.validate(Song) - - def test_exclude_values(self): - """ - Tests for basic validation of 'exclude' option values (#12689) - """ - class ExcludedFields1(admin.ModelAdmin): - exclude = ('foo') - - self.assertRaisesMessage(ImproperlyConfigured, - "'ExcludedFields1.exclude' must be a list or tuple.", - ExcludedFields1.validate, - Book) - - def test_exclude_duplicate_values(self): - class ExcludedFields2(admin.ModelAdmin): - exclude = ('name', 'name') - - self.assertRaisesMessage(ImproperlyConfigured, - "There are duplicate field(s) in ExcludedFields2.exclude", - ExcludedFields2.validate, - Book) - - def test_exclude_in_inline(self): - class ExcludedFieldsInline(admin.TabularInline): - model = Song - exclude = ('foo') - - class ExcludedFieldsAlbumAdmin(admin.ModelAdmin): - model = Album - inlines = [ExcludedFieldsInline] - - self.assertRaisesMessage(ImproperlyConfigured, - "'ExcludedFieldsInline.exclude' must be a list or tuple.", - ExcludedFieldsAlbumAdmin.validate, - Album) - - def test_exclude_inline_model_admin(self): - """ - # Regression test for #9932 - exclude in InlineModelAdmin - # should not contain the ForeignKey field used in ModelAdmin.model - """ - class SongInline(admin.StackedInline): - model = Song - exclude = ['album'] - - class AlbumAdmin(admin.ModelAdmin): - model = Album - inlines = [SongInline] - - self.assertRaisesMessage(ImproperlyConfigured, - "SongInline cannot exclude the field 'album' - this is the foreign key to the parent model admin_validation.Album.", - AlbumAdmin.validate, - Album) - - def test_app_label_in_admin_validation(self): - """ - Regression test for #15669 - Include app label in admin validation messages - """ - class RawIdNonexistingAdmin(admin.ModelAdmin): - raw_id_fields = ('nonexisting',) - - self.assertRaisesMessage(ImproperlyConfigured, - "'RawIdNonexistingAdmin.raw_id_fields' refers to field 'nonexisting' that is missing from model 'admin_validation.Album'.", - RawIdNonexistingAdmin.validate, - Album) - - def test_fk_exclusion(self): - """ - Regression test for #11709 - when testing for fk excluding (when exclude is - given) make sure fk_name is honored or things blow up when there is more - than one fk to the parent model. - """ - class TwoAlbumFKAndAnEInline(admin.TabularInline): - model = TwoAlbumFKAndAnE - exclude = ("e",) - fk_name = "album1" - - class MyAdmin(admin.ModelAdmin): - inlines = [TwoAlbumFKAndAnEInline] - - MyAdmin.validate(Album) - - def test_inline_self_validation(self): - class TwoAlbumFKAndAnEInline(admin.TabularInline): - model = TwoAlbumFKAndAnE - - class MyAdmin(admin.ModelAdmin): - inlines = [TwoAlbumFKAndAnEInline] - - self.assertRaisesMessage(ValueError, - "'admin_validation.TwoAlbumFKAndAnE' has more than one ForeignKey to 'admin_validation.Album'.", - MyAdmin.validate, Album) - - def test_inline_with_specified(self): - class TwoAlbumFKAndAnEInline(admin.TabularInline): - model = TwoAlbumFKAndAnE - fk_name = "album1" - - class MyAdmin(admin.ModelAdmin): - inlines = [TwoAlbumFKAndAnEInline] - - MyAdmin.validate(Album) - - def test_readonly(self): - class SongAdmin(admin.ModelAdmin): - readonly_fields = ("title",) - - SongAdmin.validate(Song) - - def test_readonly_on_method(self): - def my_function(obj): - pass - - class SongAdmin(admin.ModelAdmin): - readonly_fields = (my_function,) - - SongAdmin.validate(Song) - - def test_readonly_on_modeladmin(self): - class SongAdmin(admin.ModelAdmin): - readonly_fields = ("readonly_method_on_modeladmin",) - - def readonly_method_on_modeladmin(self, obj): - pass - - SongAdmin.validate(Song) - - def test_readonly_method_on_model(self): - class SongAdmin(admin.ModelAdmin): - readonly_fields = ("readonly_method_on_model",) - - SongAdmin.validate(Song) - - def test_nonexistent_field(self): - class SongAdmin(admin.ModelAdmin): - readonly_fields = ("title", "nonexistent") - - self.assertRaisesMessage(ImproperlyConfigured, - str_prefix("SongAdmin.readonly_fields[1], %(_)s'nonexistent' is not a callable " - "or an attribute of 'SongAdmin' or found in the model 'Song'."), - SongAdmin.validate, - Song) - - def test_nonexistent_field_on_inline(self): - class CityInline(admin.TabularInline): - model = City - readonly_fields = ['i_dont_exist'] # Missing attribute - - self.assertRaisesMessage(ImproperlyConfigured, - str_prefix("CityInline.readonly_fields[0], %(_)s'i_dont_exist' is not a callable " - "or an attribute of 'CityInline' or found in the model 'City'."), - CityInline.validate, - City) - - def test_extra(self): - class SongAdmin(admin.ModelAdmin): - def awesome_song(self, instance): - if instance.title == "Born to Run": - return "Best Ever!" - return "Status unknown." - - SongAdmin.validate(Song) - - def test_readonly_lambda(self): - class SongAdmin(admin.ModelAdmin): - readonly_fields = (lambda obj: "test",) - - SongAdmin.validate(Song) - - def test_graceful_m2m_fail(self): - """ - Regression test for #12203/#12237 - Fail more gracefully when a M2M field that - specifies the 'through' option is included in the 'fields' or the 'fieldsets' - ModelAdmin options. - """ - - class BookAdmin(admin.ModelAdmin): - fields = ['authors'] - - self.assertRaisesMessage(ImproperlyConfigured, - "'BookAdmin.fields' can't include the ManyToManyField field 'authors' because 'authors' manually specifies a 'through' model.", - BookAdmin.validate, - Book) - - def test_cannot_include_through(self): - class FieldsetBookAdmin(admin.ModelAdmin): - fieldsets = ( - ('Header 1', {'fields': ('name',)}), - ('Header 2', {'fields': ('authors',)}), - ) - - self.assertRaisesMessage(ImproperlyConfigured, - "'FieldsetBookAdmin.fieldsets[1][1]['fields']' can't include the ManyToManyField field 'authors' because 'authors' manually specifies a 'through' model.", - FieldsetBookAdmin.validate, - Book) - - def test_nested_fields(self): - class NestedFieldsAdmin(admin.ModelAdmin): - fields = ('price', ('name', 'subtitle')) - - NestedFieldsAdmin.validate(Book) - - def test_nested_fieldsets(self): - class NestedFieldsetAdmin(admin.ModelAdmin): - fieldsets = ( - ('Main', {'fields': ('price', ('name', 'subtitle'))}), - ) - - NestedFieldsetAdmin.validate(Book) - - def test_explicit_through_override(self): - """ - Regression test for #12209 -- If the explicitly provided through model - is specified as a string, the admin should still be able use - Model.m2m_field.through - """ - - class AuthorsInline(admin.TabularInline): - model = Book.authors.through - - class BookAdmin(admin.ModelAdmin): - inlines = [AuthorsInline] - - # If the through model is still a string (and hasn't been resolved to a model) - # the validation will fail. - BookAdmin.validate(Book) - - def test_non_model_fields(self): - """ - Regression for ensuring ModelAdmin.fields can contain non-model fields - that broke with r11737 - """ - class SongForm(forms.ModelForm): - extra_data = forms.CharField() - - class FieldsOnFormOnlyAdmin(admin.ModelAdmin): - form = SongForm - fields = ['title', 'extra_data'] - - FieldsOnFormOnlyAdmin.validate(Song) - - def test_non_model_first_field(self): - """ - Regression for ensuring ModelAdmin.field can handle first elem being a - non-model field (test fix for UnboundLocalError introduced with r16225). - """ - class SongForm(forms.ModelForm): - extra_data = forms.CharField() - - class Meta: - model = Song - fields = '__all__' - - class FieldsOnFormOnlyAdmin(admin.ModelAdmin): - form = SongForm - fields = ['extra_data', 'title'] - - FieldsOnFormOnlyAdmin.validate(Song) diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index c41a348078..486680fda7 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -9,7 +9,6 @@ import unittest from django.core import mail from django.core.checks import Error from django.core.files import temp as tempfile -from django.core.exceptions import ImproperlyConfigured from django.core.urlresolvers import (NoReverseMatch, get_script_prefix, resolve, reverse, set_script_prefix) # Register auth models with the admin. @@ -22,7 +21,6 @@ from django.contrib.admin.templatetags.admin_static import static from django.contrib.admin.templatetags.admin_urls import add_preserved_filters from django.contrib.admin.tests import AdminSeleniumWebDriverTestCase from django.contrib.admin.utils import quote -from django.contrib.admin.validation import ModelAdminValidator from django.contrib.admin.views.main import IS_POPUP_VAR from django.contrib.auth import REDIRECT_FIELD_NAME from django.contrib.auth.models import Group, User, Permission @@ -5272,23 +5270,6 @@ class InlineAdminViewOnSiteTest(TestCase): ) -class AdminGenericRelationTests(TestCase): - def test_generic_relation_fk_list_filter(self): - """ - Validates a model with a generic relation to a model with - a foreign key can specify the generic+fk relationship - path as a list_filter. See trac #21428. - """ - class GenericFKAdmin(ModelAdmin): - list_filter = ('tags__content_type',) - - validator = ModelAdminValidator() - try: - validator.validate_list_filter(GenericFKAdmin, Plot) - except ImproperlyConfigured: - self.fail("Couldn't validate a GenericRelation -> FK path in ModelAdmin.list_filter") - - @override_settings(ROOT_URLCONF="admin_views.urls") class TestEtagWithAdminView(TestCase): # See https://code.djangoproject.com/ticket/16003 diff --git a/tests/modeladmin/tests.py b/tests/modeladmin/tests.py index ee8c26c3ca..6157d6c1d4 100644 --- a/tests/modeladmin/tests.py +++ b/tests/modeladmin/tests.py @@ -7,16 +7,13 @@ from django.contrib.admin.options import (ModelAdmin, TabularInline, HORIZONTAL, VERTICAL) from django.contrib.admin.sites import AdminSite from django.contrib.admin.widgets import AdminDateWidget, AdminRadioSelect -from django.contrib.admin.validation import ModelAdminValidator from django.contrib.admin import (SimpleListFilter, BooleanFieldListFilter) from django.core.checks import Error -from django.core.exceptions import ImproperlyConfigured from django.forms.models import BaseModelFormSet from django.forms.widgets import Select -from django.test import TestCase, ignore_warnings +from django.test import TestCase from django.utils import six -from django.utils.deprecation import RemovedInDjango19Warning from .models import Band, Concert, ValidationTestModel, ValidationTestInlineModel @@ -1503,21 +1500,6 @@ class FormsetCheckTests(CheckTestCase): self.assertIsValid(ValidationTestModelAdmin, ValidationTestModel) -class CustomModelAdminTests(CheckTestCase): - @ignore_warnings(category=RemovedInDjango19Warning) - def test_deprecation(self): - "Deprecated Custom Validator definitions still work with the check framework." - - class CustomValidator(ModelAdminValidator): - def validate_me(self, model_admin, model): - raise ImproperlyConfigured('error!') - - class CustomModelAdmin(ModelAdmin): - validator_class = CustomValidator - - self.assertIsInvalid(CustomModelAdmin, ValidationTestModel, 'error!') - - class ListDisplayEditableTests(CheckTestCase): def test_list_display_links_is_none(self): """ |
