def find(cls, q=None): '''Equivalent to Ming's query.find but calls self.canonical on address before lookup. You should always use this instead of query.find''' if q: if q.get('email'): email = cls.canonical(q['email']) if email is not None: q['email'] = email else: return utils.EmptyCursor() return cls.query.find(q) return cls.query.find()
def test_empty_cursor(): """EmptyCursors conforms to specification of Ming's ODMCursor""" cursor = utils.EmptyCursor() assert_equal(cursor.count(), 0) assert_equal(cursor.first(), None) assert_equal(cursor.all(), []) assert_equal(cursor.limit(10), cursor) assert_equal(cursor.skip(10), cursor) assert_equal(cursor.sort('name', 1), cursor) assert_equal(cursor.hint('index'), cursor) assert_equal(cursor.extensions, []) assert_equal(cursor.options(arg1='val1', arg2='val2'), cursor) assert_raises(ValueError, cursor.one) assert_raises(StopIteration, cursor.next) assert_raises(StopIteration, cursor._next_impl)