Ejemplo n.º 1
0
    def setUp(self):
        class IteratorMock(mock.Mock):
            def __init__(self, base_iter):
                super().__init__()
                self._base_iter = base_iter

            def __iter__(self):
                return self

            def next(self):
                return next(self._base_iter)

            __next__ = next

        self.MockSession = mock.Mock()
        self.MockSession.db = mock.MagicMock()
        self.TestDoc = collection('test_doc', self.MockSession,
                                  Field('a', int), Field('b', dict(a=int)))

        mongo_cursor = IteratorMock(iter([{}, {}, {}]))
        mongo_cursor.count = mock.Mock(return_value=3)
        mongo_cursor.limit = mock.Mock(return_value=mongo_cursor)
        mongo_cursor.hint = mock.Mock(return_value=mongo_cursor)
        mongo_cursor.skip = mock.Mock(return_value=mongo_cursor)
        mongo_cursor.sort = mock.Mock(return_value=mongo_cursor)
        self.cursor = Cursor(self.TestDoc, mongo_cursor)
Ejemplo n.º 2
0
 def setUp(self):
     self.MockSession = mock.Mock()
     self.MockSession.db = mock.MagicMock()
     self.TestDoc = collection('test_doc', self.MockSession,
                               Field('a', int), Field('b', dict(a=int)))
     base_iter = iter([{}, {}, {}])
     mongo_cursor = mock.Mock()
     mongo_cursor.count = mock.Mock(return_value=3)
     mongo_cursor.__iter__ = lambda self: base_iter
     mongo_cursor.next = base_iter.next
     mongo_cursor.limit = mock.Mock(return_value=mongo_cursor)
     mongo_cursor.hint = mock.Mock(return_value=mongo_cursor)
     mongo_cursor.skip = mock.Mock(return_value=mongo_cursor)
     mongo_cursor.sort = mock.Mock(return_value=mongo_cursor)
     self.cursor = Cursor(self.TestDoc, mongo_cursor)