Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

More fixes and cleanup for various behaviors (count and exists) (0.6.5)

  • Loading branch information...
commit 181330b7eb3c09cc72c71754fe06e222ca6be997 1 parent ef3edd4
@dcramer authored
View
2  mock_django/managers.py
@@ -43,6 +43,8 @@ def _get(*a, **k):
m.model = model
m.get_query_set = make_get_query_set(m, actual_model)
m.get = m.get_query_set().get
+ m.count = m.get_query_set().count
+ m.exists = m.get_query_set().exists
m.__iter__ = m.get_query_set().__iter__
m.__getitem__ = m.get_query_set().__getitem__
return m
View
7 mock_django/query.py
@@ -69,14 +69,17 @@ def _iterator(*a, **k):
else:
model = mock.MagicMock()
- m = SharedMock()
+ m = SharedMock(reserved=['count', 'exists'])
m.__start = None
m.__stop = None
m.__iter__.side_effect = lambda: iter(m.iterator())
m.__getitem__.side_effect = make_getitem(m)
m.model = model
m.get = make_get(m, actual_model)
- m.exists.return_value = bool(return_value)
+ m.__nonzero__.side_effect = lambda: bool(return_value)
+ m.__len__.side_effect = lambda: len(return_value)
+ m.exists.side_effect = m.__nonzero__
+ m.count.side_effect = m.__len__
# Note since this is a SharedMock, *all* auto-generated child
# attributes will have the same side_effect ... might not make
View
7 mock_django/shared.py
@@ -25,14 +25,19 @@ class SharedMock(mock.MagicMock):
"""
def __init__(self, *args, **kwargs):
+ reserved = kwargs.pop('reserved', [])
+
+ # XXX: we cannot bind to self until after the mock is initialized
super(SharedMock, self).__init__(*args, **kwargs)
+
parent = mock.MagicMock()
parent.child = self
self.__parent = parent
+ self.__reserved = reserved
def _get_child_mock(self, **kwargs):
name = kwargs.get('name', '')
- if name[:2] == name[-2:] == '__':
+ if (name[:2] == name[-2:] == '__') or name in self.__reserved:
return super(SharedMock, self)._get_child_mock(**kwargs)
return self
View
2  setup.py
@@ -11,7 +11,7 @@
setup(
name='mock-django',
- version='0.6.4',
+ version='0.6.5',
description='',
license='Apache License 2.0',
author='David Cramer',
Please sign in to comment.
Something went wrong with that request. Please try again.