samedi 11 janvier 2020

Django form test non-field errors

I'd like to ask for a method to check if any kind of non-field errors was raised during form validation in Django. So far I found solution to do this during view testing. Well, it wasn't what I was looking for since I'm interested in doing it at form tests.

I know the way to look for fields' errors:

class FormTest(TestCase)
    def test_fields_errors(self):
        """
        Suppose form has one field which has to be filled
        """

        form = TestForm()
        form.full_clean()

        self.assertFalse(form.is_valid())
        self.assertIsInstance(
            form.errors.as_data()['required_field'][0],
            ValidationError
        )
        self.assertEquals(
            form.errors['deadline_datetime'][0],
            'This field must not be empty'
        )

Is there any way to do this when we deal with non-field errors?

Aucun commentaire:

Enregistrer un commentaire