Skip to content

Instantly share code, notes, and snippets.

@davbo
Created May 8, 2012 16:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davbo/2636927 to your computer and use it in GitHub Desktop.
Save davbo/2636927 to your computer and use it in GitHub Desktop.
Mocking django managers
from molly.apps.feeds.events import IndexView, Feed
from unittest import TestCase
class TestMocking(TestCase):
def test_mock_count(self):
Feed.objects = Mock()
feeds = [Feed(url='http://foo.bar'), Feed(url='http://bar.baz')]
mock_queryset = Mock(return_value=feeds)
mock_queryset.count.return_value = 42
Feed.objects.all = mock_queryset
self.assertEqual(len(Feed.objects.all()), Feed.objects.all().count())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment