test_cursor.py 文件源码

python
阅读 47 收藏 0 点赞 0 评论 0

项目:aiomongo 作者: ZeoAlliance 项目源码 文件源码
def test_where(self, test_db):
        a = test_db.test.find()

        with pytest.raises(TypeError):
            a.where(5)
        with pytest.raises(TypeError):
            a.where(None)
        with pytest.raises(TypeError):
            a.where({})

        await test_db.test.insert_many([{'x': i} for i in range(10)])

        assert 3 == len(await test_db.test.find().where('this.x < 3').to_list())
        assert 3 == len(await test_db.test.find().where(Code('this.x < 3')).to_list())
        assert 3 == len(await test_db.test.find().where(Code('this.x < i', {'i': 3})).to_list())
        assert 10 == len(await test_db.test.find().to_list())

        assert 3 == await test_db.test.find().where('this.x < 3').count()
        assert 10 == await test_db.test.find().count()
        assert 3 == await test_db.test.find().where(u'this.x < 3').count()
        assert [0, 1, 2] == [a['x'] for a in await test_db.test.find().where('this.x < 3').to_list()]
        assert [] == [a['x'] for a in await test_db.test.find({'x': 5}).where('this.x < 3').to_list()]
        assert [5] == [a['x'] for a in await test_db.test.find({'x': 5}).where('this.x > 3').to_list()]

        cursor = test_db.test.find().where('this.x < 3').where('this.x > 7')
        assert [8, 9] == [a['x'] for a in await cursor.to_list()]

        a = test_db.test.find()
        b = a.where('this.x > 3')
        async for _ in a:
            break
        with pytest.raises(InvalidOperation):
            a.where('this.x < 3')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号