-
-
Save hungneox/366eff33a44456f64616a81ff78b79ee to your computer and use it in GitHub Desktop.
Django model method mocking
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
class Blog(django.model): | |
name = models.CharField(null=False, max_length=64) | |
def list_articles(self): | |
return [ | |
{'body': 'abcdefg'}, | |
{'body': 'abcdefg'}, | |
{'body': 'abcdefg'}, | |
] |
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 mock # python 2.7 | |
@mock.patch('blog.models.Blog.list_articles') | |
class BlogFunctionalTestCase(django.test.TestCase): | |
def test_blog__list_articles(self, mock_list): | |
blog = Blog.objects.create( | |
name = 'abc blog' | |
) | |
mock_list.return_value = [ | |
{'body': 'abcdefg'}, | |
{'body': 'abcdefg'}, | |
{'body': 'abcdefg'}, | |
] | |
articles = blog.list_articles() | |
self.assertIsNone(articles) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment