1
1
from django .db import IntegrityError
2
2
from django .test import TestCase , TransactionTestCase
3
- from django .utils . timezone import now
3
+ from django .utils import timezone
4
4
from mock import Mock , patch
5
5
6
6
from simple_history .exceptions import NotHistoricalModelError
17
17
class BulkCreateWithHistoryTestCase (TestCase ):
18
18
def setUp (self ):
19
19
self .data = [
20
- Poll (id = 1 , question = "Question 1" , pub_date = now ()),
21
- Poll (id = 2 , question = "Question 2" , pub_date = now ()),
22
- Poll (id = 3 , question = "Question 3" , pub_date = now ()),
23
- Poll (id = 4 , question = "Question 4" , pub_date = now ()),
24
- Poll (id = 5 , question = "Question 5" , pub_date = now ()),
20
+ Poll (id = 1 , question = "Question 1" , pub_date = timezone . now ()),
21
+ Poll (id = 2 , question = "Question 2" , pub_date = timezone . now ()),
22
+ Poll (id = 3 , question = "Question 3" , pub_date = timezone . now ()),
23
+ Poll (id = 4 , question = "Question 4" , pub_date = timezone . now ()),
24
+ Poll (id = 5 , question = "Question 5" , pub_date = timezone . now ()),
25
25
]
26
26
self .data_with_excluded_fields = [
27
- PollWithExcludeFields (id = 1 , question = "Question 1" , pub_date = now ()),
28
- PollWithExcludeFields (id = 2 , question = "Question 2" , pub_date = now ()),
29
- PollWithExcludeFields (id = 3 , question = "Question 3" , pub_date = now ()),
30
- PollWithExcludeFields (id = 4 , question = "Question 4" , pub_date = now ()),
31
- PollWithExcludeFields (id = 5 , question = "Question 5" , pub_date = now ()),
27
+ PollWithExcludeFields (id = 1 , question = "Question 1" , pub_date = timezone . now ()),
28
+ PollWithExcludeFields (id = 2 , question = "Question 2" , pub_date = timezone . now ()),
29
+ PollWithExcludeFields (id = 3 , question = "Question 3" , pub_date = timezone . now ()),
30
+ PollWithExcludeFields (id = 4 , question = "Question 4" , pub_date = timezone . now ()),
31
+ PollWithExcludeFields (id = 5 , question = "Question 5" , pub_date = timezone . now ()),
32
32
]
33
33
34
34
def test_bulk_create_history (self ):
@@ -84,11 +84,11 @@ def test_bulk_create_history_with_relation_name(self):
84
84
class BulkCreateWithHistoryTransactionTestCase (TransactionTestCase ):
85
85
def setUp (self ):
86
86
self .data = [
87
- Poll (id = 1 , question = "Question 1" , pub_date = now ()),
88
- Poll (id = 2 , question = "Question 2" , pub_date = now ()),
89
- Poll (id = 3 , question = "Question 3" , pub_date = now ()),
90
- Poll (id = 4 , question = "Question 4" , pub_date = now ()),
91
- Poll (id = 5 , question = "Question 5" , pub_date = now ()),
87
+ Poll (id = 1 , question = "Question 1" , pub_date = timezone . now ()),
88
+ Poll (id = 2 , question = "Question 2" , pub_date = timezone . now ()),
89
+ Poll (id = 3 , question = "Question 3" , pub_date = timezone . now ()),
90
+ Poll (id = 4 , question = "Question 4" , pub_date = timezone . now ()),
91
+ Poll (id = 5 , question = "Question 5" , pub_date = timezone . now ()),
92
92
]
93
93
94
94
@patch (
@@ -112,7 +112,7 @@ def test_bulk_create_history_on_objects_that_already_exist(self):
112
112
self .assertEqual (Poll .history .count (), 0 )
113
113
114
114
def test_bulk_create_history_rolls_back_when_last_exists (self ):
115
- Poll .objects .create (id = 5 , question = "Question 5" , pub_date = now ())
115
+ Poll .objects .create (id = 5 , question = "Question 5" , pub_date = timezone . now ())
116
116
117
117
self .assertEqual (Poll .objects .count (), 1 )
118
118
self .assertEqual (Poll .history .count (), 1 )
@@ -149,7 +149,7 @@ def test_bulk_create_no_ids_return(self, hist_manager_mock):
149
149
class UpdateChangeReasonTestCase (TestCase ):
150
150
def test_update_change_reason_with_excluded_fields (self ):
151
151
poll = PollWithExcludeFields (
152
- question = "what's up?" , pub_date = now (), place = "The Pub"
152
+ question = "what's up?" , pub_date = timezone . now (), place = "The Pub"
153
153
)
154
154
poll .save ()
155
155
update_change_reason (poll , "Test change reason." )
0 commit comments