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:
parent
b0602e935c
commit
53aa6c6ac1
|
@ -1,5 +1,7 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import warnings
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.core import checks
|
from django.core import checks
|
||||||
|
@ -425,12 +427,15 @@ class SystemChecksTestCase(TestCase):
|
||||||
class MyModelAdmin(admin.ModelAdmin):
|
class MyModelAdmin(admin.ModelAdmin):
|
||||||
validator_class = MyValidator
|
validator_class = MyValidator
|
||||||
|
|
||||||
errors = MyModelAdmin.check(model=Song)
|
with warnings.catch_warnings(record=True):
|
||||||
expected = [
|
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
|
||||||
checks.Error(
|
errors = MyModelAdmin.check(model=Song)
|
||||||
'error!',
|
|
||||||
hint=None,
|
expected = [
|
||||||
obj=MyModelAdmin,
|
checks.Error(
|
||||||
)
|
'error!',
|
||||||
]
|
hint=None,
|
||||||
self.assertEqual(errors, expected)
|
obj=MyModelAdmin,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
self.assertEqual(errors, expected)
|
||||||
|
|
|
@ -3,7 +3,7 @@ from django.core.management.base import NoArgsCommand
|
||||||
|
|
||||||
class Command(NoArgsCommand):
|
class Command(NoArgsCommand):
|
||||||
help = "Test color output"
|
help = "Test color output"
|
||||||
requires_model_validation = False
|
requires_system_checks = False
|
||||||
|
|
||||||
def handle_noargs(self, **options):
|
def handle_noargs(self, **options):
|
||||||
return self.style.SQL_KEYWORD('BEGIN')
|
return self.style.SQL_KEYWORD('BEGIN')
|
||||||
|
|
|
@ -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
|
advertised - especially with regards to the handling of the DJANGO_SETTINGS_MODULE
|
||||||
and default settings.py files.
|
and default settings.py files.
|
||||||
"""
|
"""
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
import codecs
|
import codecs
|
||||||
import os
|
import os
|
||||||
|
@ -16,6 +15,7 @@ import socket
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
|
import warnings
|
||||||
|
|
||||||
import django
|
import django
|
||||||
from django import conf, get_version
|
from django import conf, get_version
|
||||||
|
@ -1556,8 +1556,10 @@ 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')]"))
|
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):
|
def test_requires_model_validation_and_requires_system_checks_both_defined(self):
|
||||||
from .management.commands.validation_command import InvalidCommand
|
with warnings.catch_warnings(record=True):
|
||||||
self.assertRaises(ImproperlyConfigured, InvalidCommand)
|
warnings.filterwarnings('ignore', module='django.core.management.base')
|
||||||
|
from .management.commands.validation_command import InvalidCommand
|
||||||
|
self.assertRaises(ImproperlyConfigured, InvalidCommand)
|
||||||
|
|
||||||
|
|
||||||
class Discovery(TestCase):
|
class Discovery(TestCase):
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import warnings
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
|
@ -41,13 +43,18 @@ class ValidationTestCase(TestCase):
|
||||||
"fields": ["title", "original_release"],
|
"fields": ["title", "original_release"],
|
||||||
}),
|
}),
|
||||||
]
|
]
|
||||||
SongAdmin.validate(Song)
|
|
||||||
|
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):
|
def test_custom_modelforms_with_fields_fieldsets(self):
|
||||||
"""
|
"""
|
||||||
# Regression test for #8027: custom ModelForms with fields/fieldsets
|
# Regression test for #8027: custom ModelForms with fields/fieldsets
|
||||||
"""
|
"""
|
||||||
ValidFields.validate(Song)
|
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):
|
def test_custom_get_form_with_fieldsets(self):
|
||||||
"""
|
"""
|
||||||
|
@ -55,7 +62,9 @@ class ValidationTestCase(TestCase):
|
||||||
is overridden.
|
is overridden.
|
||||||
Refs #19445.
|
Refs #19445.
|
||||||
"""
|
"""
|
||||||
ValidFormFieldsets.validate(Song)
|
with warnings.catch_warnings(record=True):
|
||||||
|
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
|
||||||
|
ValidFormFieldsets.validate(Song)
|
||||||
|
|
||||||
def test_exclude_values(self):
|
def test_exclude_values(self):
|
||||||
"""
|
"""
|
||||||
|
@ -63,6 +72,7 @@ class ValidationTestCase(TestCase):
|
||||||
"""
|
"""
|
||||||
class ExcludedFields1(admin.ModelAdmin):
|
class ExcludedFields1(admin.ModelAdmin):
|
||||||
exclude = ('foo')
|
exclude = ('foo')
|
||||||
|
|
||||||
self.assertRaisesMessage(ImproperlyConfigured,
|
self.assertRaisesMessage(ImproperlyConfigured,
|
||||||
"'ExcludedFields1.exclude' must be a list or tuple.",
|
"'ExcludedFields1.exclude' must be a list or tuple.",
|
||||||
ExcludedFields1.validate,
|
ExcludedFields1.validate,
|
||||||
|
@ -71,6 +81,7 @@ class ValidationTestCase(TestCase):
|
||||||
def test_exclude_duplicate_values(self):
|
def test_exclude_duplicate_values(self):
|
||||||
class ExcludedFields2(admin.ModelAdmin):
|
class ExcludedFields2(admin.ModelAdmin):
|
||||||
exclude = ('name', 'name')
|
exclude = ('name', 'name')
|
||||||
|
|
||||||
self.assertRaisesMessage(ImproperlyConfigured,
|
self.assertRaisesMessage(ImproperlyConfigured,
|
||||||
"There are duplicate field(s) in ExcludedFields2.exclude",
|
"There are duplicate field(s) in ExcludedFields2.exclude",
|
||||||
ExcludedFields2.validate,
|
ExcludedFields2.validate,
|
||||||
|
@ -115,10 +126,12 @@ class ValidationTestCase(TestCase):
|
||||||
class RawIdNonexistingAdmin(admin.ModelAdmin):
|
class RawIdNonexistingAdmin(admin.ModelAdmin):
|
||||||
raw_id_fields = ('nonexisting',)
|
raw_id_fields = ('nonexisting',)
|
||||||
|
|
||||||
self.assertRaisesMessage(ImproperlyConfigured,
|
with warnings.catch_warnings(record=True):
|
||||||
"'RawIdNonexistingAdmin.raw_id_fields' refers to field 'nonexisting' that is missing from model 'admin_validation.Album'.",
|
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
|
||||||
RawIdNonexistingAdmin.validate,
|
self.assertRaisesMessage(ImproperlyConfigured,
|
||||||
Album)
|
"'RawIdNonexistingAdmin.raw_id_fields' refers to field 'nonexisting' that is missing from model 'admin_validation.Album'.",
|
||||||
|
RawIdNonexistingAdmin.validate,
|
||||||
|
Album)
|
||||||
|
|
||||||
def test_fk_exclusion(self):
|
def test_fk_exclusion(self):
|
||||||
"""
|
"""
|
||||||
|
@ -133,7 +146,10 @@ class ValidationTestCase(TestCase):
|
||||||
|
|
||||||
class MyAdmin(admin.ModelAdmin):
|
class MyAdmin(admin.ModelAdmin):
|
||||||
inlines = [TwoAlbumFKAndAnEInline]
|
inlines = [TwoAlbumFKAndAnEInline]
|
||||||
MyAdmin.validate(Album)
|
|
||||||
|
with warnings.catch_warnings(record=True):
|
||||||
|
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
|
||||||
|
MyAdmin.validate(Album)
|
||||||
|
|
||||||
def test_inline_self_validation(self):
|
def test_inline_self_validation(self):
|
||||||
class TwoAlbumFKAndAnEInline(admin.TabularInline):
|
class TwoAlbumFKAndAnEInline(admin.TabularInline):
|
||||||
|
@ -153,13 +169,18 @@ class ValidationTestCase(TestCase):
|
||||||
|
|
||||||
class MyAdmin(admin.ModelAdmin):
|
class MyAdmin(admin.ModelAdmin):
|
||||||
inlines = [TwoAlbumFKAndAnEInline]
|
inlines = [TwoAlbumFKAndAnEInline]
|
||||||
MyAdmin.validate(Album)
|
|
||||||
|
with warnings.catch_warnings(record=True):
|
||||||
|
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
|
||||||
|
MyAdmin.validate(Album)
|
||||||
|
|
||||||
def test_readonly(self):
|
def test_readonly(self):
|
||||||
class SongAdmin(admin.ModelAdmin):
|
class SongAdmin(admin.ModelAdmin):
|
||||||
readonly_fields = ("title",)
|
readonly_fields = ("title",)
|
||||||
|
|
||||||
SongAdmin.validate(Song)
|
with warnings.catch_warnings(record=True):
|
||||||
|
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
|
||||||
|
SongAdmin.validate(Song)
|
||||||
|
|
||||||
def test_readonly_on_method(self):
|
def test_readonly_on_method(self):
|
||||||
def my_function(obj):
|
def my_function(obj):
|
||||||
|
@ -168,7 +189,9 @@ class ValidationTestCase(TestCase):
|
||||||
class SongAdmin(admin.ModelAdmin):
|
class SongAdmin(admin.ModelAdmin):
|
||||||
readonly_fields = (my_function,)
|
readonly_fields = (my_function,)
|
||||||
|
|
||||||
SongAdmin.validate(Song)
|
with warnings.catch_warnings(record=True):
|
||||||
|
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
|
||||||
|
SongAdmin.validate(Song)
|
||||||
|
|
||||||
def test_readonly_on_modeladmin(self):
|
def test_readonly_on_modeladmin(self):
|
||||||
class SongAdmin(admin.ModelAdmin):
|
class SongAdmin(admin.ModelAdmin):
|
||||||
|
@ -177,13 +200,17 @@ class ValidationTestCase(TestCase):
|
||||||
def readonly_method_on_modeladmin(self, obj):
|
def readonly_method_on_modeladmin(self, obj):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
SongAdmin.validate(Song)
|
with warnings.catch_warnings(record=True):
|
||||||
|
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
|
||||||
|
SongAdmin.validate(Song)
|
||||||
|
|
||||||
def test_readonly_method_on_model(self):
|
def test_readonly_method_on_model(self):
|
||||||
class SongAdmin(admin.ModelAdmin):
|
class SongAdmin(admin.ModelAdmin):
|
||||||
readonly_fields = ("readonly_method_on_model",)
|
readonly_fields = ("readonly_method_on_model",)
|
||||||
|
|
||||||
SongAdmin.validate(Song)
|
with warnings.catch_warnings(record=True):
|
||||||
|
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
|
||||||
|
SongAdmin.validate(Song)
|
||||||
|
|
||||||
def test_nonexistant_field(self):
|
def test_nonexistant_field(self):
|
||||||
class SongAdmin(admin.ModelAdmin):
|
class SongAdmin(admin.ModelAdmin):
|
||||||
|
@ -212,13 +239,18 @@ class ValidationTestCase(TestCase):
|
||||||
if instance.title == "Born to Run":
|
if instance.title == "Born to Run":
|
||||||
return "Best Ever!"
|
return "Best Ever!"
|
||||||
return "Status unknown."
|
return "Status unknown."
|
||||||
SongAdmin.validate(Song)
|
|
||||||
|
with warnings.catch_warnings(record=True):
|
||||||
|
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
|
||||||
|
SongAdmin.validate(Song)
|
||||||
|
|
||||||
def test_readonly_lambda(self):
|
def test_readonly_lambda(self):
|
||||||
class SongAdmin(admin.ModelAdmin):
|
class SongAdmin(admin.ModelAdmin):
|
||||||
readonly_fields = (lambda obj: "test",)
|
readonly_fields = (lambda obj: "test",)
|
||||||
|
|
||||||
SongAdmin.validate(Song)
|
with warnings.catch_warnings(record=True):
|
||||||
|
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
|
||||||
|
SongAdmin.validate(Song)
|
||||||
|
|
||||||
def test_graceful_m2m_fail(self):
|
def test_graceful_m2m_fail(self):
|
||||||
"""
|
"""
|
||||||
|
@ -241,6 +273,7 @@ class ValidationTestCase(TestCase):
|
||||||
('Header 1', {'fields': ('name',)}),
|
('Header 1', {'fields': ('name',)}),
|
||||||
('Header 2', {'fields': ('authors',)}),
|
('Header 2', {'fields': ('authors',)}),
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertRaisesMessage(ImproperlyConfigured,
|
self.assertRaisesMessage(ImproperlyConfigured,
|
||||||
"'FieldsetBookAdmin.fieldsets[1][1]['fields']' can't include the ManyToManyField field 'authors' because 'authors' manually specifies a 'through' model.",
|
"'FieldsetBookAdmin.fieldsets[1][1]['fields']' can't include the ManyToManyField field 'authors' because 'authors' manually specifies a 'through' model.",
|
||||||
FieldsetBookAdmin.validate,
|
FieldsetBookAdmin.validate,
|
||||||
|
@ -249,14 +282,20 @@ class ValidationTestCase(TestCase):
|
||||||
def test_nested_fields(self):
|
def test_nested_fields(self):
|
||||||
class NestedFieldsAdmin(admin.ModelAdmin):
|
class NestedFieldsAdmin(admin.ModelAdmin):
|
||||||
fields = ('price', ('name', 'subtitle'))
|
fields = ('price', ('name', 'subtitle'))
|
||||||
NestedFieldsAdmin.validate(Book)
|
|
||||||
|
with warnings.catch_warnings(record=True):
|
||||||
|
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
|
||||||
|
NestedFieldsAdmin.validate(Book)
|
||||||
|
|
||||||
def test_nested_fieldsets(self):
|
def test_nested_fieldsets(self):
|
||||||
class NestedFieldsetAdmin(admin.ModelAdmin):
|
class NestedFieldsetAdmin(admin.ModelAdmin):
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
('Main', {'fields': ('price', ('name', 'subtitle'))}),
|
('Main', {'fields': ('price', ('name', 'subtitle'))}),
|
||||||
)
|
)
|
||||||
NestedFieldsetAdmin.validate(Book)
|
|
||||||
|
with warnings.catch_warnings(record=True):
|
||||||
|
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
|
||||||
|
NestedFieldsetAdmin.validate(Book)
|
||||||
|
|
||||||
def test_explicit_through_override(self):
|
def test_explicit_through_override(self):
|
||||||
"""
|
"""
|
||||||
|
@ -273,7 +312,9 @@ class ValidationTestCase(TestCase):
|
||||||
|
|
||||||
# If the through model is still a string (and hasn't been resolved to a model)
|
# If the through model is still a string (and hasn't been resolved to a model)
|
||||||
# the validation will fail.
|
# the validation will fail.
|
||||||
BookAdmin.validate(Book)
|
with warnings.catch_warnings(record=True):
|
||||||
|
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
|
||||||
|
BookAdmin.validate(Book)
|
||||||
|
|
||||||
def test_non_model_fields(self):
|
def test_non_model_fields(self):
|
||||||
"""
|
"""
|
||||||
|
@ -287,7 +328,9 @@ class ValidationTestCase(TestCase):
|
||||||
form = SongForm
|
form = SongForm
|
||||||
fields = ['title', 'extra_data']
|
fields = ['title', 'extra_data']
|
||||||
|
|
||||||
FieldsOnFormOnlyAdmin.validate(Song)
|
with warnings.catch_warnings(record=True):
|
||||||
|
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
|
||||||
|
FieldsOnFormOnlyAdmin.validate(Song)
|
||||||
|
|
||||||
def test_non_model_first_field(self):
|
def test_non_model_first_field(self):
|
||||||
"""
|
"""
|
||||||
|
@ -305,4 +348,6 @@ class ValidationTestCase(TestCase):
|
||||||
form = SongForm
|
form = SongForm
|
||||||
fields = ['extra_data', 'title']
|
fields = ['extra_data', 'title']
|
||||||
|
|
||||||
FieldsOnFormOnlyAdmin.validate(Song)
|
with warnings.catch_warnings(record=True):
|
||||||
|
warnings.filterwarnings('ignore', module='django.contrib.admin.options')
|
||||||
|
FieldsOnFormOnlyAdmin.validate(Song)
|
||||||
|
|
Loading…
Reference in New Issue