You are raising a dict style ValidationError. To get the actual fields you need to use the_exception.error_dict[’note’].error_list[0].code.
> On Jul 30, 2015, at 4:10 AM, ThomasTheDjangoFan > <stefan.eichholz.ber...@googlemail.com> wrote: > > class TestMyNotebookModelTest(unittest): > def test_clean(self): > # I'd love to be able to do a test like this one > # and valide the error code! > > # Lets get an error-message > with self.assertRaises(ValidationError) as test: > model = MyNotebookModel() > model.note = 'Now this is a valid one. P.S. I love django!' > model.name = 'Britney is gonna fail - Hit me Baby One More Time!' > model.clean() > model.save() > # validate that the error messages has the right code > the_exception = test.exception > self.assertEqual(the_exception.error_code, 2) Peter of the Norse rahmc...@radio1190.org -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/979B813D-C9D4-4933-9A8E-1921A73DD991%40Radio1190.org. For more options, visit https://groups.google.com/d/optout.