11from django .db import IntegrityError
22from django .test import TestCase , TransactionTestCase
3- from django .utils . timezone import now
3+ from django .utils import timezone
44from mock import Mock , patch
55
66from simple_history .exceptions import NotHistoricalModelError
1717class BulkCreateWithHistoryTestCase (TestCase ):
1818 def setUp (self ):
1919 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 ()),
2525 ]
2626 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 ()),
3232 ]
3333
3434 def test_bulk_create_history (self ):
@@ -84,11 +84,11 @@ def test_bulk_create_history_with_relation_name(self):
8484class BulkCreateWithHistoryTransactionTestCase (TransactionTestCase ):
8585 def setUp (self ):
8686 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 ()),
9292 ]
9393
9494 @patch (
@@ -112,7 +112,7 @@ def test_bulk_create_history_on_objects_that_already_exist(self):
112112 self .assertEqual (Poll .history .count (), 0 )
113113
114114 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 ())
116116
117117 self .assertEqual (Poll .objects .count (), 1 )
118118 self .assertEqual (Poll .history .count (), 1 )
@@ -149,7 +149,7 @@ def test_bulk_create_no_ids_return(self, hist_manager_mock):
149149class UpdateChangeReasonTestCase (TestCase ):
150150 def test_update_change_reason_with_excluded_fields (self ):
151151 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"
153153 )
154154 poll .save ()
155155 update_change_reason (poll , "Test change reason." )
0 commit comments