File tree Expand file tree Collapse file tree 1 file changed +55
-0
lines changed
simple_history/tests/tests Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Original file line number Diff line number Diff line change 8
8
from simple_history .manager import SIMPLE_HISTORY_REVERSE_ATTR_NAME
9
9
10
10
from ..models import Choice , Document , Poll , RankedDocument
11
+ from .utils import HistoricalTestCase
11
12
12
13
User = get_user_model ()
13
14
14
15
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
+
15
70
class AsOfTestCase (TestCase ):
16
71
model = Document
17
72
You can’t perform that action at this time.
0 commit comments