Ejemplo n.º 1
0
    def test_add_field_errors_string(self):
        form = Form('f')
        form.add_text('text1', 'Value')
        form.add_text('text2', 'Value')

        result = form.add_field_errors({
            'text1': 'Generic Error',
            'text2': 'Error'
        })
        assert result
        self.assertEqual(form.elements.text1.errors, ['Generic Error'])
        self.assertEqual(form.elements.text2.errors, ['Error'])
Ejemplo n.º 2
0
    def test_add_field_errors_extras(self):
        # the result of calling add_field_errors() when all errors are not
        # processed should be False
        form = Form('f')
        form.add_text('text1', 'Value')
        form.add_text('text2', 'Value')

        result = form.add_field_errors({
            'text1': 'Generic Error',
            'text2': 'Error',
            'not there': 'Error'
        })
        assert result is False
Ejemplo n.º 3
0
    def test_add_field_errors_list(self):
        form = Form('f')
        form.add_text('text1', 'Value')
        form.add_text('text2', 'Value')

        result = form.add_field_errors({
            'text1': ['Generic Error 1', 'Generic Error 2'],
            'text2': ['Error 1', 'Error 2']
        })
        assert result
        assert len(form.elements.text1.errors) == 2
        self.assertEqual(form.elements.text1.errors,
                         ['Generic Error 1', 'Generic Error 2'])
        self.assertEqual(form.elements.text2.errors, ['Error 1', 'Error 2'])