| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from django.test import TestCase |
| 4 |
|
| 5 |
from tests.models import Post |
| 6 |
|
| 7 |
|
| 8 |
class QueryManagerTests(TestCase): |
| 9 |
def setUp(self) -> None: |
| 10 |
data = ((True, True, 0), |
| 11 |
(True, False, 4), |
| 12 |
(False, False, 2), |
| 13 |
(False, True, 3), |
| 14 |
(True, True, 1), |
| 15 |
(True, False, 5)) |
| 16 |
for p, c, o in data: |
| 17 |
Post.objects.create(published=p, confirmed=c, order=o) |
| 18 |
|
| 19 |
def test_passing_kwargs(self) -> None: |
| 20 |
qs = Post.public.all() |
| 21 |
self.assertEqual([p.order for p in qs], [0, 1, 4, 5]) |
| 22 |
|
| 23 |
def test_passing_Q(self) -> None: |
| 24 |
qs = Post.public_confirmed.all() |
| 25 |
self.assertEqual([p.order for p in qs], [0, 1]) |
| 26 |
|
| 27 |
def test_ordering(self) -> None: |
| 28 |
qs = Post.public_reversed.all() |
| 29 |
self.assertEqual([p.order for p in qs], [5, 4, 1, 0]) |