jeudi 28 juillet 2016

dango unit test on custom model manager method

I am pretty new in python and django.

I have model with custom model manager with a method ,where i am raising ValidationError on some exceptions.now i want to test this custom manager method.but don't know how to catch ValidationError or anyother error in terms of testing django model's customs manager method.

My scenario is depicted below,

class CustomModelManager(model.Manager):

    def custom_method(self):
        #for some exception
        raise ValidationError('a sample validation error')

class SampleModel(models.Model):
    ###fields
    objects = CustomModelManager()

i have tried the following unit test,but its not working ,

def test_samle_model(self):
    issues = Issues.objects.custom_method(field1='wrong field')###this will raise that validationError
    self.assertEqualValidationError, 'a sample validation error')

is it possible to catch 'any error' to test? or am i missing something?

Aucun commentaire:

Enregistrer un commentaire