Skip to content

Commit 4b79f88

Browse files
committed
Added LatestOfEachTestCase
1 parent 7398af3 commit 4b79f88

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

simple_history/tests/tests/test_manager.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,65 @@
88
from simple_history.manager import SIMPLE_HISTORY_REVERSE_ATTR_NAME
99

1010
from ..models import Choice, Document, Poll, RankedDocument
11+
from .utils import HistoricalTestCase
1112

1213
User = get_user_model()
1314

1415

16+
class LatestOfEachTestCase(HistoricalTestCase):
17+
def test_filtered_instances_are_as_expected(self):
18+
document1 = RankedDocument.objects.create(rank=10)
19+
document2 = RankedDocument.objects.create(rank=20)
20+
document2.rank = 21
21+
document2.save()
22+
document3 = RankedDocument.objects.create(rank=30)
23+
document3.rank = 31
24+
document3.save()
25+
document3.delete()
26+
document4 = RankedDocument.objects.create(rank=40)
27+
document4_pk = document4.pk
28+
document4.delete()
29+
reincarnated_document4 = RankedDocument.objects.create(pk=document4_pk, rank=42)
30+
31+
record4, record3, record2, record1 = RankedDocument.history.latest_of_each()
32+
self.assertRecordValues(
33+
record1,
34+
RankedDocument,
35+
{
36+
"rank": 10,
37+
"id": document1.id,
38+
"history_type": "+",
39+
},
40+
)
41+
self.assertRecordValues(
42+
record2,
43+
RankedDocument,
44+
{
45+
"rank": 21,
46+
"id": document2.id,
47+
"history_type": "~",
48+
},
49+
)
50+
self.assertRecordValues(
51+
record3,
52+
RankedDocument,
53+
{
54+
"rank": 31,
55+
"id": document3.id,
56+
"history_type": "-",
57+
},
58+
)
59+
self.assertRecordValues(
60+
record4,
61+
RankedDocument,
62+
{
63+
"rank": 42,
64+
"id": reincarnated_document4.id,
65+
"history_type": "+",
66+
},
67+
)
68+
69+
1570
class AsOfTestCase(TestCase):
1671
model = Document
1772

0 commit comments

Comments
 (0)