def test_execute(self, MockCache): obj_cache = Mock(pks=[1, 2, 3, 4]) MockCache.return_value = obj_cache qs = QuerySet(X) qs.query = MagicMock() qs.query.__and__.return_value = qs.query qs.query.execute.return_value = [1, 2, 3] eq_(qs._execute(a=1, b=2), ([1, 2, 3], obj_cache)) qs.query.__and__.assert_called_once_with(Q(a=1, b=2)) qs.query.execute.assert_called_once_with(obj_cache, obj_cache.pks)
def slice_order_by(self): eq_(QuerySet(X)[:3].order_by('a').query, Q()[:3].order_by('a'))
def test_with_kwargs(self): eq_(self.exclude(a=1), ~Q(a=1)) eq_(self.exclude(a=1, b=2), ~Q(a=1, b=2))
def test_exclude(self): eq_(self.exclude(), ~Q())
def test_with_kwargs(self): eq_(self.filter(a=1), Q(a=1)) eq_(self.filter(a=1, b=2), Q(a=1, b=2))
def test_filter(self): eq_(self.filter(), Q())
def test_slice(self): qs = QuerySet(X) eq_(qs[:3].query, Q()[:3])
def test_and(self): qs = QuerySet(X) eq_((qs.filter(a=1) & qs.filter(b=2)).query, Q(a=1, b=2))
def exclude_order_by(self): eq_(QuerySet(X).exclude(a=1).order_by('b').query, ~Q(a=1).order_by('b'))
def exclude_filter(self): eq_(QuerySet(X).exclude(a=1).filter(b=2).query, ~Q(a=1) & Q(b=2))
def filter_slice(self): eq_(QuerySet(X).filter(a=1)[:3].query, Q(a=1)[:3])
def filter_order_by(self): eq_(QuerySet(X).filter(a=1).order_by('b').query, Q(a=1).order_by('b'))
def filter_exclude(self): eq_(QuerySet(X).filter(a=1).exclude(b=2).query, Q(a=1) & ~Q(b=2))
def test_order_by(self): eq_(self.order_by(), Q().order_by()) eq_(self.order_by('a'), Q().order_by('a')) eq_(self.order_by('a', '-b'), Q().order_by('a', '-b'))
def test_with_args_and_kwargs(self): eq_(self.exclude(Q(a=1), b=2), ~Q(a=1, b=2)) eq_(self.exclude(Q(a=1), Q(b=2), c=3), ~Q(a=1, b=2, c=3)) eq_(self.exclude(Q(a=1), b=2, c=3), ~Q(a=1, b=2, c=3)) eq_(self.exclude(Q(a=1), Q(b=2), c=3, d=4), ~Q(a=1, b=2, c=3, d=4))
def exclude_slice(self): eq_(QuerySet(X).exclude(a=1)[:3].query, ~Q(a=1)[:3])
def test_or(self): qs = QuerySet(X) eq_((qs.filter(a=1) | qs.filter(b=2)).query, Q(a=1) | Q(b=2))
def order_by_filter(self): eq_(QuerySet(X).order_by('a').filter(b=2).query, Q().order_by('a') & Q(b=2))
def test_invert(self): qs = QuerySet(X) eq_(~qs.filter(a=1).query, ~Q(a=1))
def order_by_exclude(self): eq_(QuerySet(X).order_by('a').exclude(b=2).query, Q().order_by('a') & ~Q(b=2))
def test_all(self): eq_(QuerySet(X).all().query, Q())
def order_by_slice(self): eq_(QuerySet(X).order_by('a')[:3].query, Q().order_by('a')[:3])
def test_with_args(self): eq_(self.filter(Q(a=1)), Q(a=1)) eq_(self.filter(Q(a=1), Q(b=2)), Q(a=1, b=2))
def slice_filter(self): eq_(QuerySet(X)[:3].filter(a=1).query, Q()[:3] & Q(a=1))
def test_with_args_and_kwargs(self): eq_(self.filter(Q(a=1), b=2), Q(a=1, b=2)) eq_(self.filter(Q(a=1), Q(b=2), c=3), Q(a=1, b=2, c=3)) eq_(self.filter(Q(a=1), b=2, c=3), Q(a=1, b=2, c=3)) eq_(self.filter(Q(a=1), Q(b=2), c=3, d=4), Q(a=1, b=2, c=3, d=4))
def slice_exclude(self): eq_(QuerySet(X)[:3].exclude(a=1).query, Q()[:3] & ~Q(a=1))
def test_objects(self): eq_(Ticket.objects.model, Ticket) eq_(Ticket.objects.query, Q())
def test_with_args(self): eq_(self.exclude(Q(a=1)), ~Q(a=1)) eq_(self.exclude(Q(a=1), Q(b=2)), ~Q(a=1, b=2))