Created
February 20, 2011 04:43
-
-
Save mattjmorrison/835706 to your computer and use it in GitHub Desktop.
Simple django mocking test example 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
class SampleManager(models.Manager): | |
def get_by_user(self, user): | |
self.filter(user=user) | |
class Sample(models.Model): | |
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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