'Ensure that Q-objects correctly AND together.'

def test_and_combination(self):

    class TestDoc(Document, ):
        x = IntField()
        y = StringField()
    query = (Q(x__lt=7) & Q(x__lt=3)).to_query(TestDoc)
    self.assertEqual(query, {'$and': [{'x': {'$lt': 7}}, {'x': {'$lt': 3}}]})
    query = ((Q(y='a') & Q(x__lt=7)) & Q(x__lt=3)).to_query(TestDoc)
    self.assertEqual(query, {'$and': [{'y': 'a'}, {'x': {'$lt': 7}}, {'x': {'$lt': 3}}]})
    query = (Q(x__lt=7) & Q(x__gt=3))
    q1 = Q(x__lt=7)
    q2 = Q(x__gt=3)
    query = (q1 & q2).to_query(TestDoc)
    self.assertEqual(query, {'x': {'$lt': 7, '$gt': 3}})
    query = (Q(x__lt=100) & Q(y__ne='NotMyString'))
    query &= (Q(y__in=['a', 'b', 'c']) & Q(x__gt=(-100)))
    mongo_query = {'x': {'$lt': 100, '$gt': (-100)}, 'y': {'$ne': 'NotMyString', '$in': ['a', 'b', 'c']}}
    self.assertEqual(query.to_query(TestDoc), mongo_query)
