Added warning silencers to some noisy tests.

These warnings all emerged as the result of the introduction of the checks framework.

Thanks to Anssi Kääriäinen for the report.
This commit is contained in:
Russell Keith-Magee 2014-01-20 20:30:29 +08:00
parent b0602e935c
commit 53aa6c6ac1
4 changed files with 85 additions and 33 deletions

View File

@ -1,5 +1,7 @@
from __future__ import unicode_literals
import warnings
from django import forms
from django.contrib import admin
from django.core import checks
@ -425,7 +427,10 @@ class SystemChecksTestCase(TestCase):
class MyModelAdmin(admin.ModelAdmin):
validator_class = MyValidator
with warnings.catch_warnings(record=True):
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
errors = MyModelAdmin.check(model=Song)
expected = [
checks.Error(
'error!',

View File

@ -3,7 +3,7 @@ from django.core.management.base import NoArgsCommand
class Command(NoArgsCommand):
help = "Test color output"
requires_model_validation = False
requires_system_checks = False
def handle_noargs(self, **options):
return self.style.SQL_KEYWORD('BEGIN')

View File

@ -6,7 +6,6 @@ A series of tests to establish that the command-line managment tools work as
advertised - especially with regards to the handling of the DJANGO_SETTINGS_MODULE
and default settings.py files.
"""
from __future__ import unicode_literals
import codecs
import os
@ -16,6 +15,7 @@ import socket
import subprocess
import sys
import unittest
import warnings
import django
from django import conf, get_version
@ -1556,6 +1556,8 @@ class CommandTypes(AdminScriptTestCase):
self.assertOutput(out, str_prefix("EXECUTE:LabelCommand label=anotherlabel, options=[('no_color', False), ('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', %(_)s'1')]"))
def test_requires_model_validation_and_requires_system_checks_both_defined(self):
with warnings.catch_warnings(record=True):
warnings.filterwarnings('ignore', module='django.core.management.base')
from .management.commands.validation_command import InvalidCommand
self.assertRaises(ImproperlyConfigured, InvalidCommand)

View File

@ -1,5 +1,7 @@
from __future__ import unicode_literals
import warnings
from django import forms
from django.contrib import admin
from django.core.exceptions import ImproperlyConfigured
@ -41,12 +43,17 @@ class ValidationTestCase(TestCase):
"fields": ["title", "original_release"],
}),
]
with warnings.catch_warnings(record=True):
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
SongAdmin.validate(Song)
def test_custom_modelforms_with_fields_fieldsets(self):
"""
# Regression test for #8027: custom ModelForms with fields/fieldsets
"""
with warnings.catch_warnings(record=True):
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
ValidFields.validate(Song)
def test_custom_get_form_with_fieldsets(self):
@ -55,6 +62,8 @@ class ValidationTestCase(TestCase):
is overridden.
Refs #19445.
"""
with warnings.catch_warnings(record=True):
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
ValidFormFieldsets.validate(Song)
def test_exclude_values(self):
@ -63,6 +72,7 @@ class ValidationTestCase(TestCase):
"""
class ExcludedFields1(admin.ModelAdmin):
exclude = ('foo')
self.assertRaisesMessage(ImproperlyConfigured,
"'ExcludedFields1.exclude' must be a list or tuple.",
ExcludedFields1.validate,
@ -71,6 +81,7 @@ class ValidationTestCase(TestCase):
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,
@ -115,6 +126,8 @@ class ValidationTestCase(TestCase):
class RawIdNonexistingAdmin(admin.ModelAdmin):
raw_id_fields = ('nonexisting',)
with warnings.catch_warnings(record=True):
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
self.assertRaisesMessage(ImproperlyConfigured,
"'RawIdNonexistingAdmin.raw_id_fields' refers to field 'nonexisting' that is missing from model 'admin_validation.Album'.",
RawIdNonexistingAdmin.validate,
@ -133,6 +146,9 @@ class ValidationTestCase(TestCase):
class MyAdmin(admin.ModelAdmin):
inlines = [TwoAlbumFKAndAnEInline]
with warnings.catch_warnings(record=True):
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
MyAdmin.validate(Album)
def test_inline_self_validation(self):
@ -153,12 +169,17 @@ class ValidationTestCase(TestCase):
class MyAdmin(admin.ModelAdmin):
inlines = [TwoAlbumFKAndAnEInline]
with warnings.catch_warnings(record=True):
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
MyAdmin.validate(Album)
def test_readonly(self):
class SongAdmin(admin.ModelAdmin):
readonly_fields = ("title",)
with warnings.catch_warnings(record=True):
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
SongAdmin.validate(Song)
def test_readonly_on_method(self):
@ -168,6 +189,8 @@ class ValidationTestCase(TestCase):
class SongAdmin(admin.ModelAdmin):
readonly_fields = (my_function,)
with warnings.catch_warnings(record=True):
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
SongAdmin.validate(Song)
def test_readonly_on_modeladmin(self):
@ -177,12 +200,16 @@ class ValidationTestCase(TestCase):
def readonly_method_on_modeladmin(self, obj):
pass
with warnings.catch_warnings(record=True):
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
SongAdmin.validate(Song)
def test_readonly_method_on_model(self):
class SongAdmin(admin.ModelAdmin):
readonly_fields = ("readonly_method_on_model",)
with warnings.catch_warnings(record=True):
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
SongAdmin.validate(Song)
def test_nonexistant_field(self):
@ -212,12 +239,17 @@ class ValidationTestCase(TestCase):
if instance.title == "Born to Run":
return "Best Ever!"
return "Status unknown."
with warnings.catch_warnings(record=True):
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
SongAdmin.validate(Song)
def test_readonly_lambda(self):
class SongAdmin(admin.ModelAdmin):
readonly_fields = (lambda obj: "test",)
with warnings.catch_warnings(record=True):
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
SongAdmin.validate(Song)
def test_graceful_m2m_fail(self):
@ -241,6 +273,7 @@ class ValidationTestCase(TestCase):
('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,
@ -249,6 +282,9 @@ class ValidationTestCase(TestCase):
def test_nested_fields(self):
class NestedFieldsAdmin(admin.ModelAdmin):
fields = ('price', ('name', 'subtitle'))
with warnings.catch_warnings(record=True):
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
NestedFieldsAdmin.validate(Book)
def test_nested_fieldsets(self):
@ -256,6 +292,9 @@ class ValidationTestCase(TestCase):
fieldsets = (
('Main', {'fields': ('price', ('name', 'subtitle'))}),
)
with warnings.catch_warnings(record=True):
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
NestedFieldsetAdmin.validate(Book)
def test_explicit_through_override(self):
@ -273,6 +312,8 @@ class ValidationTestCase(TestCase):
# If the through model is still a string (and hasn't been resolved to a model)
# the validation will fail.
with warnings.catch_warnings(record=True):
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
BookAdmin.validate(Book)
def test_non_model_fields(self):
@ -287,6 +328,8 @@ class ValidationTestCase(TestCase):
form = SongForm
fields = ['title', 'extra_data']
with warnings.catch_warnings(record=True):
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
FieldsOnFormOnlyAdmin.validate(Song)
def test_non_model_first_field(self):
@ -305,4 +348,6 @@ class ValidationTestCase(TestCase):
form = SongForm
fields = ['extra_data', 'title']
with warnings.catch_warnings(record=True):
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
FieldsOnFormOnlyAdmin.validate(Song)