def test_rank_all_calls_set_rank_on_quotes(self): # Create spy quote to be returned when all quotes are asked # for through the quote_vote_manager. spied_quote = Quote(episode=Episode()) spied_quote.set_rank = MagicMock() patcher = patch('quotes_app.tasks.Quote.quote_vote_manager.all', return_value=[spied_quote]) patcher.start() self.addCleanup(patcher.stop) # Act rank_all() # Assert self.assertTrue(spied_quote.set_rank.called)