@@ -128,7 +128,8 @@ def test_if_false_default_None(self):
128
128
class NumericFunctionTests (TestCase ):
129
129
def test_crc32 (self ):
130
130
Alphabet .objects .create (d = "AAAAAA" )
131
- ab = Alphabet .objects .annotate (crc = CRC32 ("d" )).first ()
131
+ ab = Alphabet .objects .annotate (crc = CRC32 ("d" )).get ()
132
+
132
133
# Precalculated this in MySQL prompt. Python's binascii.crc32 doesn't
133
134
# match - maybe sign issues?
134
135
assert ab .crc == 2854018686
@@ -145,7 +146,7 @@ def test_sign(self):
145
146
"csign" : Sign ("c" ),
146
147
}
147
148
148
- ab = Alphabet .objects .annotate (** kwargs ).first ()
149
+ ab = Alphabet .objects .annotate (** kwargs ).get ()
149
150
150
151
assert ab .asign == 1
151
152
assert ab .bsign == 0
@@ -155,34 +156,34 @@ def test_sign(self):
155
156
class StringFunctionTests (TestCase ):
156
157
def test_concat_ws (self ):
157
158
Alphabet .objects .create (d = "AAA" , e = "BBB" )
158
- ab = Alphabet .objects .annotate (de = ConcatWS ("d" , "e" )).first ()
159
+ ab = Alphabet .objects .annotate (de = ConcatWS ("d" , "e" )).get ()
159
160
assert ab .de == "AAA,BBB"
160
161
161
162
def test_concat_ws_integers (self ):
162
163
Alphabet .objects .create (a = 1 , b = 2 )
163
- ab = Alphabet .objects .annotate (ab = ConcatWS ("a" , "b" )).first ()
164
+ ab = Alphabet .objects .annotate (ab = ConcatWS ("a" , "b" )).get ()
164
165
assert ab .ab == "1,2"
165
166
166
167
def test_concat_ws_skips_nulls (self ):
167
168
Alphabet .objects .create (d = "AAA" , e = None , f = 2 )
168
- ab = Alphabet .objects .annotate (de = ConcatWS ("d" , "e" , "f" )).first ()
169
+ ab = Alphabet .objects .annotate (de = ConcatWS ("d" , "e" , "f" )).get ()
169
170
assert ab .de == "AAA,2"
170
171
171
172
def test_concat_ws_separator (self ):
172
173
Alphabet .objects .create (d = "AAA" , e = "BBB" )
173
- ab = Alphabet .objects .annotate (de = ConcatWS ("d" , "e" , separator = ":" )).first ()
174
+ ab = Alphabet .objects .annotate (de = ConcatWS ("d" , "e" , separator = ":" )).get ()
174
175
assert ab .de == "AAA:BBB"
175
176
176
177
def test_concat_ws_separator_null_returns_none (self ):
177
178
Alphabet .objects .create (a = 1 , b = 2 )
178
179
concat = ConcatWS ("a" , "b" , separator = None )
179
- ab = Alphabet .objects .annotate (ab = concat ).first ()
180
+ ab = Alphabet .objects .annotate (ab = concat ).get ()
180
181
assert ab .ab is None
181
182
182
183
def test_concat_ws_separator_field (self ):
183
184
Alphabet .objects .create (a = 1 , d = "AAA" , e = "BBB" )
184
185
concat = ConcatWS ("d" , "e" , separator = F ("a" ))
185
- ab = Alphabet .objects .annotate (de = concat ).first ()
186
+ ab = Alphabet .objects .annotate (de = concat ).get ()
186
187
assert ab .de == "AAA1BBB"
187
188
188
189
def test_concat_ws_too_few_fields (self ):
@@ -196,7 +197,7 @@ def test_concat_ws_then_lookups_from_textfield(self):
196
197
ab = (
197
198
Alphabet .objects .annotate (de = ConcatWS ("d" , "e" , separator = ":" ))
198
199
.filter (de__endswith = ":BBB" )
199
- .first ()
200
+ .get ()
200
201
)
201
202
assert ab .de == "AAA:BBB"
202
203
@@ -216,16 +217,16 @@ def test_elt_expression(self):
216
217
217
218
def test_field_simple (self ):
218
219
Alphabet .objects .create (d = "a" )
219
- ab = Alphabet .objects .annotate (dp = Field ("d" , ["a" , "b" ])).first ()
220
+ ab = Alphabet .objects .annotate (dp = Field ("d" , ["a" , "b" ])).get ()
220
221
assert ab .dp == 1
221
- ab = Alphabet .objects .annotate (dp = Field ("d" , ["b" , "a" ])).first ()
222
+ ab = Alphabet .objects .annotate (dp = Field ("d" , ["b" , "a" ])).get ()
222
223
assert ab .dp == 2
223
- ab = Alphabet .objects .annotate (dp = Field ("d" , ["c" , "d" ])).first ()
224
+ ab = Alphabet .objects .annotate (dp = Field ("d" , ["c" , "d" ])).get ()
224
225
assert ab .dp == 0
225
226
226
227
def test_field_expression (self ):
227
228
Alphabet .objects .create (d = "b" )
228
- ab = Alphabet .objects .annotate (dp = Field ("d" , [Value ("a" ), Value ("b" )])).first ()
229
+ ab = Alphabet .objects .annotate (dp = Field ("d" , [Value ("a" ), Value ("b" )])).get ()
229
230
assert ab .dp == 2
230
231
231
232
def test_order_by (self ):
@@ -287,7 +288,7 @@ def test_xmlextractvalue_expression(self):
287
288
288
289
def test_xmlextractvalue_invalid_xml (self ):
289
290
Alphabet .objects .create (d = '{"this": "isNotXML"}' )
290
- ab = Alphabet .objects .annotate (ev = XMLExtractValue ("d" , "/some" )).first ()
291
+ ab = Alphabet .objects .annotate (ev = XMLExtractValue ("d" , "/some" )).get ()
291
292
assert ab .ev == ""
292
293
293
294
@@ -301,7 +302,7 @@ def test_md5_string(self):
301
302
DeprecationWarning , "This function is deprecated."
302
303
):
303
304
md5 = MD5 ("d" )
304
- ab = Alphabet .objects .annotate (md5 = md5 ).first ()
305
+ ab = Alphabet .objects .annotate (md5 = md5 ).get ()
305
306
306
307
assert ab .md5 == pymd5
307
308
@@ -314,7 +315,7 @@ def test_sha1_string(self):
314
315
DeprecationWarning , "This function is deprecated."
315
316
):
316
317
sha1 = SHA1 ("d" )
317
- ab = Alphabet .objects .annotate (sha = sha1 ).first ()
318
+ ab = Alphabet .objects .annotate (sha = sha1 ).get ()
318
319
319
320
assert ab .sha == pysha1
320
321
@@ -330,7 +331,7 @@ def test_sha2_string(self):
330
331
DeprecationWarning , "This function is deprecated."
331
332
):
332
333
sha2 = SHA2 ("d" , hash_len )
333
- ab = Alphabet .objects .annotate (sha = sha2 ).first ()
334
+ ab = Alphabet .objects .annotate (sha = sha2 ).get ()
334
335
335
336
assert ab .sha == pysha
336
337
@@ -343,7 +344,7 @@ def test_sha2_string_hash_len_default(self):
343
344
DeprecationWarning , "This function is deprecated."
344
345
):
345
346
sha2 = SHA2 ("d" )
346
- ab = Alphabet .objects .annotate (sha = sha2 ).first ()
347
+ ab = Alphabet .objects .annotate (sha = sha2 ).get ()
347
348
348
349
assert ab .sha == pysha512
349
350
@@ -381,6 +382,8 @@ def test_last_insert_id_in_query(self):
381
382
382
383
383
384
class JSONFunctionTests (TestCase ):
385
+ obj : JSONModel
386
+
384
387
@classmethod
385
388
def setUpTestData (cls ):
386
389
super ().setUpTestData ()
0 commit comments