2023-03-21 13:21:03 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
2016-11-23 23:49:53 +00:00
|
|
|
from django.test import TestCase
|
|
|
|
|
|
2017-02-15 23:00:10 +00:00
|
|
|
from tests.models import Post
|
2016-11-23 23:49:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class QueryManagerTests(TestCase):
|
2023-03-22 17:50:18 +00:00
|
|
|
def setUp(self) -> None:
|
2016-11-23 23:49:53 +00:00
|
|
|
data = ((True, True, 0),
|
|
|
|
|
(True, False, 4),
|
|
|
|
|
(False, False, 2),
|
|
|
|
|
(False, True, 3),
|
|
|
|
|
(True, True, 1),
|
|
|
|
|
(True, False, 5))
|
|
|
|
|
for p, c, o in data:
|
|
|
|
|
Post.objects.create(published=p, confirmed=c, order=o)
|
|
|
|
|
|
2023-03-22 17:50:18 +00:00
|
|
|
def test_passing_kwargs(self) -> None:
|
2016-11-23 23:49:53 +00:00
|
|
|
qs = Post.public.all()
|
|
|
|
|
self.assertEqual([p.order for p in qs], [0, 1, 4, 5])
|
|
|
|
|
|
2023-03-22 17:50:18 +00:00
|
|
|
def test_passing_Q(self) -> None:
|
2016-11-23 23:49:53 +00:00
|
|
|
qs = Post.public_confirmed.all()
|
|
|
|
|
self.assertEqual([p.order for p in qs], [0, 1])
|
|
|
|
|
|
2023-03-22 17:50:18 +00:00
|
|
|
def test_ordering(self) -> None:
|
2016-11-23 23:49:53 +00:00
|
|
|
qs = Post.public_reversed.all()
|
|
|
|
|
self.assertEqual([p.order for p in qs], [5, 4, 1, 0])
|