14
14
15
15
from datetime import timedelta , datetime
16
16
from unittest import mock
17
- import sure
18
17
from uuid import uuid4
19
18
20
19
from cassandra .cqlengine import columns
@@ -44,7 +43,7 @@ def test_batch_is_included(self):
44
43
with BatchQuery (timestamp = timedelta (seconds = 30 )) as b :
45
44
TestTimestampModel .batch (b ).create (count = 1 )
46
45
47
- "USING TIMESTAMP" . should . be . within ( m .call_args [0 ][0 ].query_string )
46
+ self . assertIn ( "USING TIMESTAMP" , m .call_args [0 ][0 ].query_string )
48
47
49
48
50
49
class CreateWithTimestampTest (BaseTimestampTest ):
@@ -56,27 +55,27 @@ def test_batch(self):
56
55
57
56
query = m .call_args [0 ][0 ].query_string
58
57
59
- query . should . match ( r"INSERT.*USING TIMESTAMP" )
60
- query . should_not . match ( r"TIMESTAMP.*INSERT" )
58
+ self . assertRegex ( query , r"INSERT.*USING TIMESTAMP" )
59
+ self . assertNotRegex ( query , r"TIMESTAMP.*INSERT" )
61
60
62
61
def test_timestamp_not_included_on_normal_create (self ):
63
62
with mock .patch .object (self .session , "execute" ) as m :
64
63
TestTimestampModel .create (count = 2 )
65
64
66
- "USING TIMESTAMP" . shouldnt . be . within ( m .call_args [0 ][0 ].query_string )
65
+ self . assertNotIn ( "USING TIMESTAMP" , m .call_args [0 ][0 ].query_string )
67
66
68
67
def test_timestamp_is_set_on_model_queryset (self ):
69
68
delta = timedelta (seconds = 30 )
70
69
tmp = TestTimestampModel .timestamp (delta )
71
- tmp ._timestamp . should . equal ( delta )
70
+ self . assertEqual ( tmp ._timestamp , delta )
72
71
73
72
def test_non_batch_syntax_integration (self ):
74
73
tmp = TestTimestampModel .timestamp (timedelta (seconds = 30 )).create (count = 1 )
75
- tmp . should . be . ok
74
+ self . assertIsNotNone ( tmp )
76
75
77
76
def test_non_batch_syntax_with_tll_integration (self ):
78
77
tmp = TestTimestampModel .timestamp (timedelta (seconds = 30 )).ttl (30 ).create (count = 1 )
79
- tmp . should . be . ok
78
+ self . assertIsNotNone ( tmp )
80
79
81
80
def test_non_batch_syntax_unit (self ):
82
81
@@ -85,7 +84,7 @@ def test_non_batch_syntax_unit(self):
85
84
86
85
query = m .call_args [0 ][0 ].query_string
87
86
88
- "USING TIMESTAMP" . should . be . within ( query )
87
+ self . assertIn ( "USING TIMESTAMP" , query )
89
88
90
89
def test_non_batch_syntax_with_ttl_unit (self ):
91
90
@@ -95,7 +94,7 @@ def test_non_batch_syntax_with_ttl_unit(self):
95
94
96
95
query = m .call_args [0 ][0 ].query_string
97
96
98
- query . should . match ( r"USING TTL \d* AND TIMESTAMP" )
97
+ self . assertRegex ( query , r"USING TTL \d* AND TIMESTAMP" )
99
98
100
99
101
100
class UpdateWithTimestampTest (BaseTimestampTest ):
@@ -109,15 +108,15 @@ def test_instance_update_includes_timestamp_in_query(self):
109
108
with mock .patch .object (self .session , "execute" ) as m :
110
109
self .instance .timestamp (timedelta (seconds = 30 )).update (count = 2 )
111
110
112
- "USING TIMESTAMP" . should . be . within ( m .call_args [0 ][0 ].query_string )
111
+ self . assertIn ( "USING TIMESTAMP" , m .call_args [0 ][0 ].query_string )
113
112
114
113
def test_instance_update_in_batch (self ):
115
114
with mock .patch .object (self .session , "execute" ) as m :
116
115
with BatchQuery () as b :
117
116
self .instance .batch (b ).timestamp (timedelta (seconds = 30 )).update (count = 2 )
118
117
119
118
query = m .call_args [0 ][0 ].query_string
120
- "USING TIMESTAMP" . should . be . within ( query )
119
+ self . assertIn ( "USING TIMESTAMP" , query )
121
120
122
121
123
122
class DeleteWithTimestampTest (BaseTimestampTest ):
@@ -129,7 +128,7 @@ def test_non_batch(self):
129
128
uid = uuid4 ()
130
129
tmp = TestTimestampModel .create (id = uid , count = 1 )
131
130
132
- TestTimestampModel .get (id = uid ). should . be . ok
131
+ self . assertIsNotNone ( TestTimestampModel .get (id = uid ))
133
132
134
133
tmp .timestamp (timedelta (seconds = 5 )).delete ()
135
134
@@ -143,15 +142,15 @@ def test_non_batch(self):
143
142
144
143
# calling .timestamp sets the TS on the model
145
144
tmp .timestamp (timedelta (seconds = 5 ))
146
- tmp ._timestamp . should . be . ok
145
+ self . assertIsNotNone ( tmp ._timestamp )
147
146
148
147
# calling save clears the set timestamp
149
148
tmp .save ()
150
- tmp ._timestamp . shouldnt . be . ok
149
+ self . assertIsNone ( tmp ._timestamp )
151
150
152
151
tmp .timestamp (timedelta (seconds = 5 ))
153
152
tmp .update ()
154
- tmp ._timestamp . shouldnt . be . ok
153
+ self . assertIsNone ( tmp ._timestamp )
155
154
156
155
def test_blind_delete (self ):
157
156
"""
@@ -160,7 +159,7 @@ def test_blind_delete(self):
160
159
uid = uuid4 ()
161
160
tmp = TestTimestampModel .create (id = uid , count = 1 )
162
161
163
- TestTimestampModel .get (id = uid ). should . be . ok
162
+ self . assertIsNotNone ( TestTimestampModel .get (id = uid ))
164
163
165
164
TestTimestampModel .objects (id = uid ).timestamp (timedelta (seconds = 5 )).delete ()
166
165
@@ -179,7 +178,7 @@ def test_blind_delete_with_datetime(self):
179
178
uid = uuid4 ()
180
179
tmp = TestTimestampModel .create (id = uid , count = 1 )
181
180
182
- TestTimestampModel .get (id = uid ). should . be . ok
181
+ self . assertIsNotNone ( TestTimestampModel .get (id = uid ))
183
182
184
183
plus_five_seconds = datetime .now () + timedelta (seconds = 5 )
185
184
@@ -197,7 +196,7 @@ def test_delete_in_the_past(self):
197
196
uid = uuid4 ()
198
197
tmp = TestTimestampModel .create (id = uid , count = 1 )
199
198
200
- TestTimestampModel .get (id = uid ). should . be . ok
199
+ self . assertIsNotNone ( TestTimestampModel .get (id = uid ))
201
200
202
201
# delete in the past, should not affect the object created above
203
202
TestTimestampModel .objects (id = uid ).timestamp (timedelta (seconds = - 60 )).delete ()
0 commit comments