Permalink
Browse files

Fixed many warnings emitted by test suite

  • Loading branch information...
1 parent f8b4814 commit b9ab2f786d36e88c4988dffef94f509c80a84ac9 @spookylukey committed Apr 8, 2013
@@ -523,6 +523,9 @@ def get_changelist_form(self, request, **kwargs):
"formfield_callback": partial(self.formfield_for_dbfield, request=request),
}
defaults.update(kwargs)
+ if defaults['fields'] is None and not modelform_defines_fields(defaults['form']):
+ defaults['fields'] = forms.ALL_FIELDS
+
return modelform_factory(self.model, **defaults)
def get_changelist_formset(self, request, **kwargs):
@@ -130,6 +130,7 @@ class UserChangeForm(forms.ModelForm):
class Meta:
model = User
+ fields = '__all__'
def __init__(self, *args, **kwargs):
super(UserChangeForm, self).__init__(*args, **kwargs)
@@ -12,6 +12,7 @@ class FlatpageForm(forms.ModelForm):
class Meta:
model = FlatPage
+ fields = '__all__'
def clean_url(self):
url = self.cleaned_data['url']
@@ -60,9 +60,11 @@ class Meta:
class TestModelForm(forms.ModelForm):
class Meta:
model = TestModel
+ fields = '__all__'
-TestModelFormSet = forms.models.modelformset_factory(TestModel, form=TestModelForm, extra=2)
+TestModelFormSet = forms.models.modelformset_factory(TestModel, form=TestModelForm, extra=2,
+ fields='__all__')
class TestWizard(WizardView):
@@ -15,6 +15,7 @@
class UserForm(forms.ModelForm):
class Meta:
model = User
+ fields = '__all__'
UserFormSet = forms.models.modelformset_factory(User, form=UserForm, extra=2)
@@ -279,6 +279,8 @@ class SongForm(forms.ModelForm):
extra_data = forms.CharField()
class Meta:
model = Song
+ fields = '__all__'
+
class FieldsOnFormOnlyAdmin(admin.ModelAdmin):
form = SongForm
View
@@ -25,3 +25,4 @@ def save(self, force_insert=False, force_update=False):
class PhotoForm(ModelForm):
class Meta:
model = Photo
+ fields = '__all__'
@@ -322,6 +322,7 @@ class FormsTests(TestCase):
class ArticleForm(forms.ModelForm):
class Meta:
model = Article
+ fields = '__all__'
def test_foreign_object_form(self):
# A very crude test checking that the non-concrete fields do not get form fields.
@@ -139,6 +139,7 @@ def test_regression_14234(self):
class CheeseForm(ModelForm):
class Meta:
model = Cheese
+ fields = '__all__'
form = CheeseForm({
'name': 'Brie',
@@ -17,11 +17,13 @@
class ChoiceFieldForm(ModelForm):
class Meta:
model = ChoiceFieldModel
+ fields = '__all__'
class OptionalMultiChoiceModelForm(ModelForm):
class Meta:
model = OptionalMultiChoiceModel
+ fields = '__all__'
class FileForm(Form):
@@ -138,6 +140,7 @@ def test_boundary_conditions(self):
class BoundaryForm(ModelForm):
class Meta:
model = BoundaryModel
+ fields = '__all__'
f = BoundaryForm({'positive_integer': 100})
self.assertTrue(f.is_valid())
@@ -153,6 +156,7 @@ def test_formfield_initial(self):
class DefaultsForm(ModelForm):
class Meta:
model = Defaults
+ fields = '__all__'
self.assertEqual(DefaultsForm().fields['name'].initial, 'class default value')
self.assertEqual(DefaultsForm().fields['def_date'].initial, datetime.date(1980, 1, 1))
@@ -247,6 +247,7 @@ class CustomWidget(forms.TextInput):
class TaggedItemForm(forms.ModelForm):
class Meta:
model = TaggedItem
+ fields = '__all__'
widgets = {'tag': CustomWidget}
class GenericInlineFormsetTest(TestCase):
View
@@ -24,3 +24,4 @@ class CompanyForm(forms.ModelForm):
class Meta:
model = Company
+ fields = '__all__'
@@ -31,10 +31,14 @@
class ImageFileForm(forms.ModelForm):
class Meta:
model = ImageFile
+ fields = '__all__'
+
class OptionalImageFileForm(forms.ModelForm):
class Meta:
model = OptionalImageFile
+ fields = '__all__'
+
class ProductForm(forms.ModelForm):
class Meta:
@@ -163,6 +167,7 @@ class ShortCategory(forms.ModelForm):
class Meta:
model = Category
+ fields = '__all__'
class ImprovedArticleForm(forms.ModelForm):
@@ -44,9 +44,12 @@ def my_validator(value):
f.clean([p.pk for p in Person.objects.all()[8:9]])
self.assertTrue(self._validator_run)
+
class TripleForm(forms.ModelForm):
class Meta:
model = Triple
+ fields = '__all__'
+
class UniqueTogetherTests(TestCase):
def test_multiple_field_unique_together(self):
@@ -64,15 +67,18 @@ def test_multiple_field_unique_together(self):
form = TripleForm({'left': '1', 'middle': '3', 'right': '1'})
self.assertTrue(form.is_valid())
+
class TripleFormWithCleanOverride(forms.ModelForm):
class Meta:
model = Triple
+ fields = '__all__'
def clean(self):
if not self.cleaned_data['left'] == self.cleaned_data['right']:
raise forms.ValidationError('Left and right should be equal')
return self.cleaned_data
+
class OverrideCleanTests(TestCase):
def test_override_clean(self):
"""
@@ -85,6 +91,7 @@ def test_override_clean(self):
# by form.full_clean().
self.assertEqual(form.instance.left, 1)
+
# Regression test for #12960.
# Make sure the cleaned_data returned from ModelForm.clean() is applied to the
# model instance.
@@ -96,6 +103,8 @@ def clean(self):
class Meta:
model = Publication
+ fields = '__all__'
+
class ModelFormCleanTest(TestCase):
def test_model_form_clean_applies_to_model(self):
@@ -104,9 +113,12 @@ def test_model_form_clean_applies_to_model(self):
publication = form.save()
self.assertEqual(publication.title, 'TEST')
+
class FPForm(forms.ModelForm):
class Meta:
model = FilePathModel
+ fields = '__all__'
+
class FilePathFieldTests(TestCase):
def test_file_path_field_blank(self):
@@ -145,9 +157,12 @@ def formfield_for_dbfield(db_field, **kwargs):
</select> <span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></li>"""
% (book1.pk, book2.pk, book3.pk))
+
class CFFForm(forms.ModelForm):
class Meta:
model = CustomFF
+ fields = '__all__'
+
class CustomFieldSaveTests(TestCase):
def test_save(self):
@@ -170,9 +185,12 @@ class Meta:
f = Form()
self.assertEqual(len(f.fields["publications"].choices), 1)
+
class RealPersonForm(forms.ModelForm):
class Meta:
model = RealPerson
+ fields = '__all__'
+
class CustomModelFormSaveMethod(TestCase):
def test_string_message(self):
@@ -232,9 +250,12 @@ def test_11183(self):
self.assertTrue(field1 is not ModelChoiceForm.base_fields['person'])
self.assertTrue(field1.widget.choices.field is field1)
+
class HomepageForm(forms.ModelForm):
class Meta:
model = Homepage
+ fields = '__all__'
+
class URLFieldTests(TestCase):
def test_url_on_modelform(self):
@@ -366,6 +387,8 @@ def test_extra_field_modelform_factory(self):
class DocumentForm(forms.ModelForm):
class Meta:
model = Document
+ fields = '__all__'
+
class FileFieldTests(unittest.TestCase):
def test_clean_false(self):
@@ -429,6 +452,7 @@ def test_clear_and_file_contradiction(self):
self.assertTrue('something.txt' in rendered)
self.assertTrue('myfile-clear' in rendered)
+
class EditionForm(forms.ModelForm):
author = forms.ModelChoiceField(queryset=Person.objects.all())
publication = forms.ModelChoiceField(queryset=Publication.objects.all())
@@ -437,6 +461,8 @@ class EditionForm(forms.ModelForm):
class Meta:
model = Edition
+ fields = '__all__'
+
class UniqueErrorsTests(TestCase):
def setUp(self):
@@ -915,14 +915,14 @@ def test_modelformset_validate_max_flag(self):
'form-1-quantity': '2',
}
- FormSet = modelformset_factory(Price, extra=1, max_num=1, validate_max=True)
+ FormSet = modelformset_factory(Price, fields="__all__", extra=1, max_num=1, validate_max=True)
formset = FormSet(data)
self.assertFalse(formset.is_valid())
self.assertEqual(formset.non_form_errors(), ['Please submit 1 or fewer forms.'])
# Now test the same thing without the validate_max flag to ensure
# default behavior is unchanged
- FormSet = modelformset_factory(Price, extra=1, max_num=1)
+ FormSet = modelformset_factory(Price, fields="__all__", extra=1, max_num=1)
formset = FormSet(data)
self.assertTrue(formset.is_valid())
@@ -1102,7 +1102,7 @@ def test_model_formset_with_custom_pk(self):
def test_model_formset_with_initial_model_instance(self):
# has_changed should compare model instance and primary key
# see #18898
- FormSet = modelformset_factory(Poem)
+ FormSet = modelformset_factory(Poem, fields='__all__')
john_milton = Poet(name="John Milton")
john_milton.save()
data = {
@@ -1118,7 +1118,7 @@ def test_model_formset_with_initial_model_instance(self):
def test_model_formset_with_initial_queryset(self):
# has_changed should work with queryset and list of pk's
# see #18898
- FormSet = modelformset_factory(AuthorMeeting)
+ FormSet = modelformset_factory(AuthorMeeting, fields='__all__')
author = Author.objects.create(pk=1, name='Charles Baudelaire')
data = {
'form-TOTAL_FORMS': 1,
@@ -418,6 +418,8 @@ def test_inherited_unique_field_with_form(self):
class ProfileForm(forms.ModelForm):
class Meta:
model = Profile
+ fields = '__all__'
+
User.objects.create(username="user_only")
p = Profile.objects.create(username="user_with_profile")
form = ProfileForm({'username': "user_with_profile", 'extra': "hello"},
View
@@ -11,3 +11,4 @@ class EventSplitForm(forms.Form):
class EventModelForm(forms.ModelForm):
class Meta:
model = Event
+ fields = '__all__'

0 comments on commit b9ab2f7

Please sign in to comment.