Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 18 lines (14 sloc) 0.43 kb
2142b5e David Cramer Initial commit
authored
1 import mock
2
3 __all__ = ('ModelMock',)
4
5
6 def ModelMock(model):
7 """
8 >>> Post = ModelMock(Post)
9 >>> assert post.pk == post.id
10 """
11 class ModelMock(mock.MagicMock):
12 def _get_child_mock(self, **kwargs):
13 name = kwargs.get('name', '')
14 if name == 'pk':
15 return self.id
16 return super(ModelMock, self)._get_child_mock(**kwargs)
17 return ModelMock(spec=model())
Something went wrong with that request. Please try again.