Skip to content

Instantly share code, notes, and snippets.

Last active Jun 21, 2021
What would you like to do?
Django model method mocking
class Blog(django.model):
name = models.CharField(null=False, max_length=64)
def list_articles(self):
return [
{'body': 'abcdefg'},
{'body': 'abcdefg'},
{'body': 'abcdefg'},
import mock # python 2.7
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment