Skip to content

Commit 50f7e70

Browse files
committed
Changed QuerySetMock so that the iterator generating methods return a reference to the mock object instead of a generator object. This was we can chain function calls such as mock.all().filter() while retaining the iterator functionality of the returned objects
1 parent 1036ab1 commit 50f7e70

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

mock_django/query.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def _iterator(*a, **k):
6565
m = SharedMock(reserved=['count', 'exists'])
6666
m.__start = None
6767
m.__stop = None
68-
m.__iter__.side_effect = lambda: iter(m.iterator())
68+
m.__iter__.side_effect = make_iterator(m)
6969
m.__getitem__.side_effect = make_getitem(m)
7070
m.model = model
7171
m.get = make_get(m, actual_model)
@@ -77,5 +77,5 @@ def _iterator(*a, **k):
7777
# Note since this is a SharedMock, *all* auto-generated child
7878
# attributes will have the same side_effect ... might not make
7979
# sense for some like count().
80-
m.iterator.side_effect = make_iterator(m)
80+
m.iterator.return_value = m
8181
return m

0 commit comments

Comments
 (0)