def test_init_with_instances(self):
        post_data = {'field1': 'example', 'field2': 1}
        form1 = Form1(data=post_data)
        form2 = Form2(data=post_data)

        form = CompositeForm(form_instances=[form1, form2])
        self.assertEquals(len(form._subforms), 2)
        self.assertEquals(form.is_valid(), True)
    def test_access_is_bound(self):
        form_classes = [Form1, Form2]
        form = CompositeForm(form_classes=form_classes)

        self.assertEqual(form.is_bound, False)

        form.is_bound = True
        self.assertEqual(form.is_bound, True)
        for subform in form._subforms:
            self.assertEqual(form.is_bound, True)
Ejemplo n.º 3
0
class ValidationTest(TestCase):
    def setUp(self):
        form_classes = [Form1, Form2]
        post_data = {'field1': 'asdf'}
        self.form = CompositeForm(post_data, form_classes=form_classes)

    def test_form_has_errors(self):
        self.assertEquals(self.form.is_valid(), False)
        self.assertEquals(list(self.form.errors.keys()), ['field2'])

    def test_form_errors_as_json(self):
        self.assertIsInstance(self.form.errors.as_json(), str)

    def test_form_valid(self):
        post_data = {'field1': 'asdf', 'field2': 'asdf'}
        form_classes = [Form1, Form2]
        form = CompositeForm(post_data, form_classes=form_classes)
        self.assertEquals(form.is_valid(), True)
Ejemplo n.º 4
0
 def setUp(self):
     form_classes = [Form1, Form2]
     post_data = {'field1': 'asdf'}
     self.form = CompositeForm(post_data, form_classes=form_classes)
Ejemplo n.º 5
0
 def test_form_valid(self):
     post_data = {'field1': 'asdf', 'field2': 'asdf'}
     form_classes = [Form1, Form2]
     form = CompositeForm(post_data, form_classes=form_classes)
     self.assertEquals(form.is_valid(), True)