def test_paradoxical_condition(self): comb = Filter({'roll': 27}) & Filter({'roll': {'$lte': 42}}) assert comb.as_query == {'roll': {'$eq': 27, '$lte': 42}} comb = Filter({'roll': {'$gte': 27}}) & Filter({'roll': 42}) assert list(comb.as_query['roll'].items()) in ([('$gte', 27), ('$eq', 42)], [('$eq', 42), ('$gte', 27)])
def test_operations_hard_and(self): comb = Filter({'$and': [{ 'a': 1 }, { 'b': 2 }]}) & Filter({'$and': [{ 'c': 3 }]}) assert comb.as_query == {'$and': [{'a': 1}, {'b': 2}, {'c': 3}]}
def test_operations_or_clean_merge(self): comb = Filter({'roll': 27}) | Filter({'foo': 42}) assert comb.as_query == {'$or': [{'roll': 27}, {'foo': 42}]} comb = comb | Filter({'bar': 'baz'}) assert comb.as_query == { '$or': [{ 'roll': 27 }, { 'foo': 42 }, { 'bar': 'baz' }] }
def single_ops(request): return Filter({'roll': 27})
def test_operations_and_operator_overlap(self): comb = Filter({'roll': {'$gte': 27}}) & Filter({'roll': {'$lte': 42}}) assert comb.as_query == {'roll': {'$gte': 27, '$lte': 42}}
def test_operations_and_clean_merge(self): comb = Filter({'roll': 27}) & Filter({'foo': 42}) assert comb.as_query == {'roll': 27, 'foo': 42}
def empty_ops(request): return Filter()