From c5df329996ca4801b0d97d4a70bc1bea6b8663c4 Mon Sep 17 00:00:00 2001 From: Honza Král Date: Mon, 18 Oct 2010 04:44:49 +0000 Subject: Fixed #12074 -- Adding .as_p and as_ul methods to FormSet. Thanks arthurdebert and dpn for the patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@14250 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/forms/formsets.py | 38 +++++++++++++++++++++++++++++++++ tests/regressiontests/forms/tests.py | 2 ++ 2 files changed, 40 insertions(+) (limited to 'tests/regressiontests/forms') diff --git a/tests/regressiontests/forms/formsets.py b/tests/regressiontests/forms/formsets.py index fade987c26..f8b8ae2a8a 100644 --- a/tests/regressiontests/forms/formsets.py +++ b/tests/regressiontests/forms/formsets.py @@ -1,4 +1,8 @@ # -*- coding: utf-8 -*- +from django.test.testcases import TestCase +from django.forms.forms import Form +from django.forms.fields import CharField, IntegerField +from django.forms.formsets import formset_factory tests = """ # Basic FormSet creation and usage ############################################ @@ -722,3 +726,37 @@ False """ + +data = { + 'choices-TOTAL_FORMS': '1', # the number of forms rendered + 'choices-INITIAL_FORMS': '0', # the number of forms with initial data + 'choices-MAX_NUM_FORMS': '0', # max number of forms + 'choices-0-choice': 'Calexico', + 'choices-0-votes': '100', +} + +class Choice(Form): + choice = CharField() + votes = IntegerField() + +ChoiceFormSet = formset_factory(Choice) + +class FormsetAsFooTests(TestCase): + def test_as_table(self): + formset = ChoiceFormSet(data, auto_id=False, prefix='choices') + self.assertEqual(formset.as_table(),""" +Choice: +Votes:""") + + def test_as_p(self): + formset = ChoiceFormSet(data, auto_id=False, prefix='choices') + self.assertEqual(formset.as_p(),""" +

Choice:

+

Votes:

""") + + def test_as_ul(self): + formset = ChoiceFormSet(data, auto_id=False, prefix='choices') + self.assertEqual(formset.as_ul(),""" +
  • Choice:
  • +
  • Votes:
  • """) + diff --git a/tests/regressiontests/forms/tests.py b/tests/regressiontests/forms/tests.py index 635a989b05..fbf3158ca1 100644 --- a/tests/regressiontests/forms/tests.py +++ b/tests/regressiontests/forms/tests.py @@ -38,6 +38,8 @@ from widgets import tests as widgets_tests from formsets import tests as formset_tests from media import media_tests + +from formsets import FormsetAsFooTests from fields import FieldsTests from validators import TestFieldWithValidators from widgets import WidgetTests, ClearableFileInputTests -- cgit v1.3