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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -