I have a model with clean method that checks if either 2 fields are null, and if so it raises ValidationError
How can I perform a test (usually I'm using nose) to instance creation without making the test fail with error. I want to do some assertion to make sure that the creation of the instance has failed.
This is the clean method:
def clean(self):
if not self.message and not self.image:
raise ValidationError('You must provide either Message and/or '
'Image')
Use assertRaises():
instance = YourModel()
self.assertRaises(ValidationError, instance.clean)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With