@@ -59,7 +59,7 @@ def wrapper(self, fetch, *args, **kwargs):
59
59
60
60
@skipUnlessDBFeature ("supports_atlas_search" )
61
61
class SearchUtilsMixin (TransactionTestCase ):
62
- available_apps = []
62
+ available_apps = ["queries_" ]
63
63
models_to_clean = [Article ]
64
64
65
65
delayedAssertCountEqual = _delayed_assertion (timeout = 2 )(TransactionTestCase .assertCountEqual )
@@ -72,7 +72,7 @@ class SearchUtilsMixin(TransactionTestCase):
72
72
def setUpClass (cls ):
73
73
super ().setUpClass ()
74
74
# Register the cleanup to run after all tests in this class
75
- cls .addClassCleanup (cls .drop_search_indexes_and_data )
75
+ cls .addClassCleanup (cls .drop_search_indexes )
76
76
77
77
@staticmethod
78
78
def _get_collection (model ):
@@ -85,12 +85,11 @@ def create_search_index(cls, model, index_name, definition, type="search"):
85
85
collection .create_search_index (idx )
86
86
87
87
@classmethod
88
- def drop_search_indexes_and_data (cls ):
88
+ def drop_search_indexes (cls ):
89
89
for model in cls .models_to_clean :
90
90
collection = cls ._get_collection (model )
91
91
for search_indexes in collection .list_search_indexes ():
92
92
collection .drop_search_index (search_indexes ["name" ])
93
- collection .delete_many ({})
94
93
95
94
96
95
@skipUnlessDBFeature ("supports_atlas_search" )
@@ -108,7 +107,10 @@ def setUpClass(cls):
108
107
}
109
108
},
110
109
)
111
- cls .article = Article .objects .create (headline = "cross" , number = 1 , body = "body" )
110
+
111
+ def setUp (self ):
112
+ super ().setUp ()
113
+ self .article = Article .objects .create (headline = "cross" , number = 1 , body = "body" )
112
114
Article .objects .create (headline = "other thing" , number = 2 , body = "body" )
113
115
114
116
def test_search_equals (self ):
@@ -191,7 +193,10 @@ def setUpClass(cls):
191
193
}
192
194
},
193
195
)
194
- cls .article = Article .objects .create (
196
+
197
+ def setUp (self ):
198
+ super ().setUp ()
199
+ self .article = Article .objects .create (
195
200
headline = "crossing and something" ,
196
201
number = 2 ,
197
202
body = "river" ,
@@ -242,7 +247,10 @@ def setUpClass(cls):
242
247
"exists_body_index" ,
243
248
{"mappings" : {"dynamic" : False , "fields" : {"body" : {"type" : "token" }}}},
244
249
)
245
- cls .article = Article .objects .create (headline = "ignored" , number = 3 , body = "something" )
250
+
251
+ def setUp (self ):
252
+ super ().setUp ()
253
+ self .article = Article .objects .create (headline = "ignored" , number = 3 , body = "something" )
246
254
247
255
def test_search_exists (self ):
248
256
qs = Article .objects .annotate (score = SearchExists (path = "body" ))
@@ -266,7 +274,10 @@ def setUpClass(cls):
266
274
"in_headline_index" ,
267
275
{"mappings" : {"dynamic" : False , "fields" : {"headline" : {"type" : "token" }}}},
268
276
)
269
- cls .article = Article .objects .create (headline = "cross" , number = 1 , body = "a" )
277
+
278
+ def setUp (self ):
279
+ super ().setUp ()
280
+ self .article = Article .objects .create (headline = "cross" , number = 1 , body = "a" )
270
281
Article .objects .create (headline = "road" , number = 2 , body = "b" )
271
282
272
283
def test_search_in (self ):
@@ -293,7 +304,10 @@ def setUpClass(cls):
293
304
"phrase_body_index" ,
294
305
{"mappings" : {"dynamic" : False , "fields" : {"body" : {"type" : "string" }}}},
295
306
)
296
- cls .article = Article .objects .create (
307
+
308
+ def setUp (self ):
309
+ super ().setUp ()
310
+ self .article = Article .objects .create (
297
311
headline = "irrelevant" , number = 1 , body = "the quick brown fox"
298
312
)
299
313
Article .objects .create (headline = "cheetah" , number = 2 , body = "fastest animal" )
@@ -323,7 +337,10 @@ def setUpClass(cls):
323
337
{"mappings" : {"dynamic" : False , "fields" : {"number" : {"type" : "number" }}}},
324
338
)
325
339
Article .objects .create (headline = "x" , number = 5 , body = "z" )
326
- cls .number20 = Article .objects .create (headline = "y" , number = 20 , body = "z" )
340
+
341
+ def setUp (self ):
342
+ super ().setUp ()
343
+ self .number20 = Article .objects .create (headline = "y" , number = 20 , body = "z" )
327
344
328
345
def test_search_range (self ):
329
346
qs = Article .objects .annotate (score = SearchRange (path = "number" , gte = 10 , lt = 30 ))
@@ -354,7 +371,10 @@ def setUpClass(cls):
354
371
}
355
372
},
356
373
)
357
- cls .article = Article .objects .create (headline = "hello world" , number = 1 , body = "abc" )
374
+
375
+ def setUp (self ):
376
+ super ().setUp ()
377
+ self .article = Article .objects .create (headline = "hello world" , number = 1 , body = "abc" )
358
378
Article .objects .create (headline = "hola mundo" , number = 2 , body = "abc" )
359
379
360
380
def test_search_regex (self ):
@@ -385,7 +405,10 @@ def setUpClass(cls):
385
405
"text_body_index" ,
386
406
{"mappings" : {"dynamic" : False , "fields" : {"body" : {"type" : "string" }}}},
387
407
)
388
- cls .article = Article .objects .create (
408
+
409
+ def setUp (self ):
410
+ super ().setUp ()
411
+ self .article = Article .objects .create (
389
412
headline = "ignored" , number = 1 , body = "The lazy dog sleeps"
390
413
)
391
414
Article .objects .create (headline = "ignored" , number = 2 , body = "The sleepy bear" )
@@ -437,7 +460,10 @@ def setUpClass(cls):
437
460
}
438
461
},
439
462
)
440
- cls .article = Article .objects .create (headline = "dark-knight" , number = 1 , body = "" )
463
+
464
+ def setUp (self ):
465
+ super ().setUp ()
466
+ self .article = Article .objects .create (headline = "dark-knight" , number = 1 , body = "" )
441
467
Article .objects .create (headline = "batman" , number = 2 , body = "" )
442
468
443
469
def test_search_wildcard (self ):
@@ -469,7 +495,10 @@ def setUpClass(cls):
469
495
}
470
496
},
471
497
)
472
- cls .article = Article .objects .create (
498
+
499
+ def setUp (self ):
500
+ super ().setUp ()
501
+ self .article = Article .objects .create (
473
502
headline = "any" , number = 1 , body = "" , location = {"type" : "Point" , "coordinates" : [40 , 5 ]}
474
503
)
475
504
Article .objects .create (
@@ -512,7 +541,10 @@ def setUpClass(cls):
512
541
"geowithin_location_index" ,
513
542
{"mappings" : {"dynamic" : False , "fields" : {"location" : {"type" : "geo" }}}},
514
543
)
515
- cls .article = Article .objects .create (
544
+
545
+ def setUp (self ):
546
+ super ().setUp ()
547
+ self .article = Article .objects .create (
516
548
headline = "geo" , number = 2 , body = "" , location = {"type" : "Point" , "coordinates" : [40 , 5 ]}
517
549
)
518
550
Article .objects .create (
@@ -615,25 +647,28 @@ def setUpClass(cls):
615
647
}
616
648
},
617
649
)
618
- cls .mars_mission = Article .objects .create (
650
+
651
+ def setUp (self ):
652
+ super ().setUp ()
653
+ self .mars_mission = Article .objects .create (
619
654
number = 1 ,
620
655
headline = "space exploration" ,
621
656
body = "NASA launches a new mission to Mars, aiming to study surface geology" ,
622
657
)
623
658
624
- cls .exoplanet = Article .objects .create (
659
+ self .exoplanet = Article .objects .create (
625
660
number = 2 ,
626
661
headline = "space exploration" ,
627
662
body = "Astronomers discover exoplanets orbiting distant stars using Webb telescope" ,
628
663
)
629
664
630
- cls .icy_moons = Article .objects .create (
665
+ self .icy_moons = Article .objects .create (
631
666
number = 3 ,
632
667
headline = "space exploration" ,
633
668
body = "ESA prepares a robotic expedition to explore the icy moons of Jupiter" ,
634
669
)
635
670
636
- cls .comodities_drop = Article .objects .create (
671
+ self .comodities_drop = Article .objects .create (
637
672
number = 4 ,
638
673
headline = "astronomy news" ,
639
674
body = "Commodities dropped sharply due to inflation concerns" ,
@@ -780,13 +815,15 @@ def setUpClass(cls):
780
815
type = "vectorSearch" ,
781
816
)
782
817
783
- cls .mars = Article .objects .create (
818
+ def setUp (self ):
819
+ super ().setUp ()
820
+ self .mars = Article .objects .create (
784
821
headline = "Mars landing" ,
785
822
number = 1 ,
786
823
body = "The rover has landed on Mars" ,
787
824
plot_embedding = [0.1 , 0.2 , 0.3 ],
788
825
)
789
- cls .cooking = Article .objects .create (
826
+ self .cooking = Article .objects .create (
790
827
headline = "Cooking tips" ,
791
828
number = 2 ,
792
829
body = "This article is about pasta" ,
0 commit comments