Skip to content

Instantly share code, notes, and snippets.

@mattjmorrison
Created February 20, 2011 04:43
Show Gist options
  • Save mattjmorrison/835706 to your computer and use it in GitHub Desktop.
Save mattjmorrison/835706 to your computer and use it in GitHub Desktop.
Simple django mocking test example 1
from django.db import models
class SampleManager(models.Manager):
def get_by_user(self, user):
self.filter(user=user)
class Sample(models.Model):
pass
import unittest
import mock
from django_testing import models
class SampleTests(unittest.TestCase):
def test_filters_by_user(self):
user = mock.Mock()
manager = mock.Mock(spec=models.SampleManager)
models.SampleManager.get_by_user(manager, user)
manager.filter.assert_called_with(user=user)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment