I have a model:
class Evaluation(models.Model):
def abc(self):
#some logic here
return something
Say, I have another function which uses this:
def filter_graded(evaluations):
return filter(lambda x: x.is_completely_graded(), evaluations)
Now when I am writing test for filter_graded
method, I mock is_completely_graded
to return true/false for some instances. Instead of respecting the mock, the test calls actual is_completely_graded
. How can I solve this?
My test looks like:
def test_filter_graded(self):
eval1 = G(Evaluation)
eval2 = G(Evaluation)
eval1.is_completely_graded = mock.MagicMock(return_value=True)
eval2.is_completely_graded = mock.MagicMock(return_value=False)
filter_graded(Evaluation.objects.all())
self.assertEqual(len(result), 1)