Question

How to write a test case for a model method which returns nothing like:

def model_method(self):
    # some operations
    self.field1 = self.get_some_value()
    self.save()

Above method is performing some operations and saved, but returns nothing. I am doing something like this

def test_model_method(self)
    self.assertEqual(self.instance_object.model_method(), None)

Please refer some better approach and let me know if i am not clear.

Was it helpful?

Solution

Instead of checking the return value, it is better to check the changed attribute. (if the method does not return anything)

def test_model_method(self)
    self.instance_object.model_method()
    self.assertEqual(self.instance_object.field1, EXPECTED_FIELD1_VALUE)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top