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)
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)
def setUp(self): class IteratorMock(mock.Mock): def __init__(self, base_iter): super(IteratorMock, self).__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)
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)
class TestCursor(TestCase): 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) def test_cursor(self): obj = dict(a=None, b=dict(a=None)) self.assertEqual(self.cursor.count(), 3) self.assertEqual(self.cursor.next(), obj) self.cursor.limit(100) self.cursor.skip(10) self.cursor.hint('foo') self.cursor.sort('a') self.assertEqual(self.cursor.all(), [obj, obj]) self.cursor.cursor.limit.assert_called_with(100) self.cursor.cursor.skip.assert_called_with(10) self.cursor.cursor.hint.assert_called_with('foo') self.cursor.cursor.sort.assert_called_with('a') def test_first(self): obj = dict(a=None, b=dict(a=None)) self.assertEqual(self.cursor.first(), obj) self.assertEqual(self.cursor.first(), obj) self.assertEqual(self.cursor.first(), obj) self.assertEqual(self.cursor.first(), None) def test_one_full(self): self.assertRaises(ValueError, self.cursor.one) def test_one_empty(self): self.cursor.all() self.assertRaises(ValueError, self.cursor.one) def test_one_ok(self): self.cursor.next() self.cursor.next() obj = dict(a=None, b=dict(a=None)) self.assertEqual(self.cursor.one(), obj)
class TestCursor(TestCase): 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) def test_cursor(self): obj = dict(a=None, b=dict(a=None)) self.assertEqual(len(self.cursor), 3) self.assertEqual(self.cursor.count(), 3) self.assertEqual(next(self.cursor), obj) self.cursor.limit(100) self.cursor.skip(10) self.cursor.hint('foo') self.cursor.sort('a') self.assertEqual(self.cursor.all(), [obj,obj]) self.cursor.cursor.limit.assert_called_with(100) self.cursor.cursor.skip.assert_called_with(10) self.cursor.cursor.hint.assert_called_with('foo') self.cursor.cursor.sort.assert_called_with('a') def test_first(self): obj = dict(a=None, b=dict(a=None)) self.assertEqual(self.cursor.first(), obj) self.assertEqual(self.cursor.first(), obj) self.assertEqual(self.cursor.first(), obj) self.assertEqual(self.cursor.first(), None) def test_one_full(self): self.assertRaises(ValueError, self.cursor.one) def test_one_empty(self): self.cursor.all() self.assertRaises(ValueError, self.cursor.one) def test_one_ok(self): next(self.cursor) next(self.cursor) obj = dict(a=None, b=dict(a=None)) self.assertEqual(self.cursor.one(), obj)
class TestCursor(TestCase): 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) def test_cursor(self): obj = dict(a=None, b=dict(a=None)) self.assertEqual(self.cursor.count(), 3) self.assertEqual(self.cursor.next(), obj) self.cursor.limit(100) self.cursor.skip(10) self.cursor.hint('foo') self.cursor.sort('a') self.assertEqual(self.cursor.all(), [obj, obj]) self.cursor.cursor.limit.assert_called_with(100) self.cursor.cursor.skip.assert_called_with(10) self.cursor.cursor.hint.assert_called_with('foo') self.cursor.cursor.sort.assert_called_with('a') def test_first(self): obj = dict(a=None, b=dict(a=None)) self.assertEqual(self.cursor.first(), obj) self.assertEqual(self.cursor.first(), obj) self.assertEqual(self.cursor.first(), obj) self.assertEqual(self.cursor.first(), None) def test_one_full(self): self.assertRaises(ValueError, self.cursor.one) def test_one_empty(self): self.cursor.all() self.assertRaises(ValueError, self.cursor.one) def test_one_ok(self): self.cursor.next() self.cursor.next() obj = dict(a=None, b=dict(a=None)) self.assertEqual(self.cursor.one(), obj)
class TestCursor(TestCase): def setUp(self): class IteratorMock(mock.Mock): def __init__(self, base_iter): super(IteratorMock, self).__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) def test_cursor(self): obj = dict(a=None, b=dict(a=None)) self.assertEqual(self.cursor.count(), 3) self.assertEqual(self.cursor.next(), obj) self.cursor.limit(100) self.cursor.skip(10) self.cursor.hint('foo') self.cursor.sort('a') self.assertEqual(self.cursor.all(), [obj,obj]) self.cursor.cursor.limit.assert_called_with(100) self.cursor.cursor.skip.assert_called_with(10) self.cursor.cursor.hint.assert_called_with('foo') self.cursor.cursor.sort.assert_called_with('a') def test_first(self): obj = dict(a=None, b=dict(a=None)) self.assertEqual(self.cursor.first(), obj) self.assertEqual(self.cursor.first(), obj) self.assertEqual(self.cursor.first(), obj) self.assertEqual(self.cursor.first(), None) def test_one_full(self): self.assertRaises(ValueError, self.cursor.one) def test_one_empty(self): self.cursor.all() self.assertRaises(ValueError, self.cursor.one) def test_one_ok(self): self.cursor.next() self.cursor.next() obj = dict(a=None, b=dict(a=None)) self.assertEqual(self.cursor.one(), obj)