python - Django unit test on custom model manager method -
i pretty new in python , django.
i have model custom model manager method ,where raising validationerror
on exceptions.now want test custom manager method.but don't know how catch validationerror
or anyother error in terms of testing django model's customs manager method.
my scenario depicted below,
class custommodelmanager(model.manager): def custom_method(self): #for exception raise validationerror('a sample validation error') class samplemodel(models.model): ###fields objects = custommodelmanager()
i have tried following unit test,but not working ,
def test_samle_model(self): issues = issues.objects.custom_method(field1='wrong field')###this raise validationerror self.assertequalvalidationerror, 'a sample validation error')
is possible catch 'any error' test? or missing something?
you want `assertraises':
def test_sample_model(self): self.assertraises(validationerror): issues = issues.objects.custom_method(field1='wrong field')
Comments
Post a Comment