1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15+ import re
1516from datetime import timedelta , datetime
1617from unittest import mock
17- import sure
1818from uuid import uuid4
1919
2020from cassandra .cqlengine import columns
@@ -47,7 +47,7 @@ def test_batch_is_included(self):
4747 with BatchQuery (timestamp = timedelta (seconds = 30 )) as b :
4848 TestTimestampModel .batch (b ).create (count = 1 )
4949
50- "USING TIMESTAMP" . should . be . within ( m .call_args [0 ][0 ].query_string )
50+ assert re . search ( "USING TIMESTAMP" , m .call_args [0 ][0 ].query_string )
5151
5252
5353class CreateWithTimestampTest (BaseTimestampTest ):
@@ -58,47 +58,42 @@ def test_batch(self):
5858 TestTimestampModel .timestamp (timedelta (seconds = 10 )).batch (b ).create (count = 1 )
5959
6060 query = m .call_args [0 ][0 ].query_string
61-
62- query .should .match (r"INSERT.*USING TIMESTAMP" )
63- query .should_not .match (r"TIMESTAMP.*INSERT" )
61+ assert re .search (r"INSERT.*USING TIMESTAMP" , query )
62+ assert not re .search (r"TIMESTAMP.*INSERT" , query )
6463
6564 def test_timestamp_not_included_on_normal_create (self ):
6665 with mock .patch .object (self .session , "execute" ) as m :
6766 TestTimestampModel .create (count = 2 )
6867
69- "USING TIMESTAMP" . shouldnt . be . within ( m .call_args [0 ][0 ].query_string )
68+ assert not re . search ( "USING TIMESTAMP" , m .call_args [0 ][0 ].query_string )
7069
7170 def test_timestamp_is_set_on_model_queryset (self ):
7271 delta = timedelta (seconds = 30 )
7372 tmp = TestTimestampModel .timestamp (delta )
74- tmp ._timestamp . should . equal ( delta )
73+ assert tmp ._timestamp == delta
7574
7675 def test_non_batch_syntax_integration (self ):
7776 tmp = TestTimestampModel .timestamp (timedelta (seconds = 30 )).create (count = 1 )
78- tmp . should . be . ok
77+ assert tmp
7978
8079 def test_non_batch_syntax_with_tll_integration (self ):
8180 tmp = TestTimestampModel .timestamp (timedelta (seconds = 30 )).ttl (30 ).create (count = 1 )
82- tmp . should . be . ok
81+ assert tmp
8382
8483 def test_non_batch_syntax_unit (self ):
8584
8685 with mock .patch .object (self .session , "execute" ) as m :
8786 TestTimestampModel .timestamp (timedelta (seconds = 30 )).create (count = 1 )
8887
89- query = m .call_args [0 ][0 ].query_string
90-
91- "USING TIMESTAMP" .should .be .within (query )
88+ assert re .search ("USING TIMESTAMP" , m .call_args [0 ][0 ].query_string )
9289
9390 def test_non_batch_syntax_with_ttl_unit (self ):
9491
9592 with mock .patch .object (self .session , "execute" ) as m :
9693 TestTimestampModel .timestamp (timedelta (seconds = 30 )).ttl (30 ).create (
9794 count = 1 )
9895
99- query = m .call_args [0 ][0 ].query_string
100-
101- query .should .match (r"USING TTL \d* AND TIMESTAMP" )
96+ assert re .search (r"USING TTL \d* AND TIMESTAMP" , m .call_args [0 ][0 ].query_string )
10297
10398
10499class UpdateWithTimestampTest (BaseTimestampTest ):
@@ -112,15 +107,14 @@ def test_instance_update_includes_timestamp_in_query(self):
112107 with mock .patch .object (self .session , "execute" ) as m :
113108 self .instance .timestamp (timedelta (seconds = 30 )).update (count = 2 )
114109
115- "USING TIMESTAMP" . should . be . within ( m .call_args [0 ][0 ].query_string )
110+ assert re . search ( "USING TIMESTAMP" , m .call_args [0 ][0 ].query_string )
116111
117112 def test_instance_update_in_batch (self ):
118113 with mock .patch .object (self .session , "execute" ) as m :
119114 with BatchQuery () as b :
120115 self .instance .batch (b ).timestamp (timedelta (seconds = 30 )).update (count = 2 )
121116
122- query = m .call_args [0 ][0 ].query_string
123- "USING TIMESTAMP" .should .be .within (query )
117+ assert re .search ("USING TIMESTAMP" , m .call_args [0 ][0 ].query_string )
124118
125119
126120class DeleteWithTimestampTest (BaseTimestampTest ):
@@ -132,7 +126,7 @@ def test_non_batch(self):
132126 uid = uuid4 ()
133127 tmp = TestTimestampModel .create (id = uid , count = 1 )
134128
135- TestTimestampModel .get (id = uid ). should . be . ok
129+ assert TestTimestampModel .get (id = uid )
136130
137131 tmp .timestamp (timedelta (seconds = 5 )).delete ()
138132
@@ -146,15 +140,15 @@ def test_non_batch(self):
146140
147141 # calling .timestamp sets the TS on the model
148142 tmp .timestamp (timedelta (seconds = 5 ))
149- tmp ._timestamp . should . be . ok
143+ assert tmp ._timestamp
150144
151145 # calling save clears the set timestamp
152146 tmp .save ()
153- tmp ._timestamp . shouldnt . be . ok
147+ assert not tmp ._timestamp
154148
155149 tmp .timestamp (timedelta (seconds = 5 ))
156150 tmp .update ()
157- tmp ._timestamp . shouldnt . be . ok
151+ assert not tmp ._timestamp
158152
159153 def test_blind_delete (self ):
160154 """
@@ -163,7 +157,7 @@ def test_blind_delete(self):
163157 uid = uuid4 ()
164158 tmp = TestTimestampModel .create (id = uid , count = 1 )
165159
166- TestTimestampModel .get (id = uid ). should . be . ok
160+ assert TestTimestampModel .get (id = uid )
167161
168162 TestTimestampModel .objects (id = uid ).timestamp (timedelta (seconds = 5 )).delete ()
169163
@@ -182,7 +176,7 @@ def test_blind_delete_with_datetime(self):
182176 uid = uuid4 ()
183177 tmp = TestTimestampModel .create (id = uid , count = 1 )
184178
185- TestTimestampModel .get (id = uid ). should . be . ok
179+ assert TestTimestampModel .get (id = uid )
186180
187181 plus_five_seconds = datetime .now () + timedelta (seconds = 5 )
188182
@@ -200,11 +194,9 @@ def test_delete_in_the_past(self):
200194 uid = uuid4 ()
201195 tmp = TestTimestampModel .create (id = uid , count = 1 )
202196
203- TestTimestampModel .get (id = uid ). should . be . ok
197+ assert TestTimestampModel .get (id = uid )
204198
205199 # delete the in past, should not affect the object created above
206200 TestTimestampModel .objects (id = uid ).timestamp (timedelta (seconds = - 60 )).delete ()
207201
208202 TestTimestampModel .get (id = uid )
209-
210-
0 commit comments