'Ensure that where clauses work.'

def test_where(self):

    class IntPair(Document, ):
        fielda = IntField()
        fieldb = IntField()
    IntPair.objects._collection.remove()
    a = IntPair(fielda=1, fieldb=1)
    b = IntPair(fielda=1, fieldb=2)
    c = IntPair(fielda=2, fieldb=1)
    a.save()
    b.save()
    c.save()
    query = IntPair.objects.where('this[~fielda]    >=    this[~fieldb]')
    self.assertEqual('this["fielda"]    >=    this["fieldb"]', query._where_clause)
    results = list(query)
    self.assertEqual(2, len(results))
    self.assertTrue((a in results))
    self.assertTrue((c in results))
    query = IntPair.objects.where('this[~fielda]    ==    this[~fieldb]')
    results = list(query)
    self.assertEqual(1, len(results))
    self.assertTrue((a in results))
    query = IntPair.objects.where('function()    {    return    this[~fielda]    >=    this[~fieldb]    }')
    self.assertEqual('function()    {    return    this["fielda"]    >=    this["fieldb"]    }', query._where_clause)
    results = list(query)
    self.assertEqual(2, len(results))
    self.assertTrue((a in results))
    self.assertTrue((c in results))
    with self.assertRaises(TypeError):
        list(IntPair.objects.where(fielda__gte=3))
