Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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.
  • Loading branch information...
commit 53aa6c6ac1b6534f2e3a159014401b84bf1f70c1 1 parent b0602e9
@freakboy3742 freakboy3742 authored
View
23 tests/admin_checks/tests.py
@@ -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,12 +427,15 @@ def validate(self, cls, model):
class MyModelAdmin(admin.ModelAdmin):
validator_class = MyValidator
- errors = MyModelAdmin.check(model=Song)
- expected = [
- checks.Error(
- 'error!',
- hint=None,
- obj=MyModelAdmin,
- )
- ]
- self.assertEqual(errors, expected)
+ with warnings.catch_warnings(record=True):
+ warnings.filterwarnings('ignore', module='django.contrib.admin.options')
+ errors = MyModelAdmin.check(model=Song)
+
+ expected = [
+ checks.Error(
+ 'error!',
+ hint=None,
+ obj=MyModelAdmin,
+ )
+ ]
+ self.assertEqual(errors, expected)
View
2  tests/admin_scripts/management/commands/color_command.py
@@ -3,7 +3,7 @@
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
8 tests/admin_scripts/tests.py
@@ -6,7 +6,6 @@
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 subprocess
import sys
import unittest
+import warnings
import django
from django import conf, get_version
@@ -1556,8 +1556,10 @@ def test_label_command_multiple_label(self):
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):
- from .management.commands.validation_command import InvalidCommand
- self.assertRaises(ImproperlyConfigured, InvalidCommand)
+ 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)
class Discovery(TestCase):
View
85 tests/admin_validation/tests.py
@@ -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,13 +43,18 @@ class SongAdmin(admin.ModelAdmin):
"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):
"""
# 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):
"""
@@ -55,7 +62,9 @@ def test_custom_get_form_with_fieldsets(self):
is overridden.
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):
"""
@@ -63,6 +72,7 @@ def test_exclude_values(self):
"""
class ExcludedFields1(admin.ModelAdmin):
exclude = ('foo')
+
self.assertRaisesMessage(ImproperlyConfigured,
"'ExcludedFields1.exclude' must be a list or tuple.",
ExcludedFields1.validate,
@@ -71,6 +81,7 @@ class ExcludedFields1(admin.ModelAdmin):
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,10 +126,12 @@ def test_app_label_in_admin_validation(self):
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)
+ 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,
+ Album)
def test_fk_exclusion(self):
"""
@@ -133,7 +146,10 @@ class TwoAlbumFKAndAnEInline(admin.TabularInline):
class MyAdmin(admin.ModelAdmin):
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):
class TwoAlbumFKAndAnEInline(admin.TabularInline):
@@ -153,13 +169,18 @@ class TwoAlbumFKAndAnEInline(admin.TabularInline):
class MyAdmin(admin.ModelAdmin):
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):
class SongAdmin(admin.ModelAdmin):
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 my_function(obj):
@@ -168,7 +189,9 @@ def my_function(obj):
class SongAdmin(admin.ModelAdmin):
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):
class SongAdmin(admin.ModelAdmin):
@@ -177,13 +200,17 @@ class SongAdmin(admin.ModelAdmin):
def readonly_method_on_modeladmin(self, obj):
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):
class SongAdmin(admin.ModelAdmin):
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):
class SongAdmin(admin.ModelAdmin):
@@ -212,13 +239,18 @@ def awesome_song(self, instance):
if instance.title == "Born to Run":
return "Best Ever!"
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):
class SongAdmin(admin.ModelAdmin):
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):
"""
@@ -241,6 +273,7 @@ class FieldsetBookAdmin(admin.ModelAdmin):
('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,14 +282,20 @@ class FieldsetBookAdmin(admin.ModelAdmin):
def test_nested_fields(self):
class NestedFieldsAdmin(admin.ModelAdmin):
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):
class NestedFieldsetAdmin(admin.ModelAdmin):
fieldsets = (
('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):
"""
@@ -273,7 +312,9 @@ class BookAdmin(admin.ModelAdmin):
# If the through model is still a string (and hasn't been resolved to a model)
# 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):
"""
@@ -287,7 +328,9 @@ class FieldsOnFormOnlyAdmin(admin.ModelAdmin):
form = SongForm
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):
"""
@@ -305,4 +348,6 @@ class FieldsOnFormOnlyAdmin(admin.ModelAdmin):
form = SongForm
fields = ['extra_data', 'title']
- FieldsOnFormOnlyAdmin.validate(Song)
+ with warnings.catch_warnings(record=True):
+ warnings.filterwarnings('ignore', module='django.contrib.admin.options')
+ FieldsOnFormOnlyAdmin.validate(Song)
Please sign in to comment.
Something went wrong with that request. Please try again.