Skip to content

Commit 80a4387

Browse files
committed
add available_apps to unit test
1 parent c663007 commit 80a4387

File tree

1 file changed

+58
-21
lines changed

1 file changed

+58
-21
lines changed

tests/queries_/test_search.py

Lines changed: 58 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def wrapper(self, fetch, *args, **kwargs):
5959

6060
@skipUnlessDBFeature("supports_atlas_search")
6161
class SearchUtilsMixin(TransactionTestCase):
62-
available_apps = []
62+
available_apps = ["queries_"]
6363
models_to_clean = [Article]
6464

6565
delayedAssertCountEqual = _delayed_assertion(timeout=2)(TransactionTestCase.assertCountEqual)
@@ -72,7 +72,7 @@ class SearchUtilsMixin(TransactionTestCase):
7272
def setUpClass(cls):
7373
super().setUpClass()
7474
# 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)
7676

7777
@staticmethod
7878
def _get_collection(model):
@@ -85,12 +85,11 @@ def create_search_index(cls, model, index_name, definition, type="search"):
8585
collection.create_search_index(idx)
8686

8787
@classmethod
88-
def drop_search_indexes_and_data(cls):
88+
def drop_search_indexes(cls):
8989
for model in cls.models_to_clean:
9090
collection = cls._get_collection(model)
9191
for search_indexes in collection.list_search_indexes():
9292
collection.drop_search_index(search_indexes["name"])
93-
collection.delete_many({})
9493

9594

9695
@skipUnlessDBFeature("supports_atlas_search")
@@ -108,7 +107,10 @@ def setUpClass(cls):
108107
}
109108
},
110109
)
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")
112114
Article.objects.create(headline="other thing", number=2, body="body")
113115

114116
def test_search_equals(self):
@@ -191,7 +193,10 @@ def setUpClass(cls):
191193
}
192194
},
193195
)
194-
cls.article = Article.objects.create(
196+
197+
def setUp(self):
198+
super().setUp()
199+
self.article = Article.objects.create(
195200
headline="crossing and something",
196201
number=2,
197202
body="river",
@@ -242,7 +247,10 @@ def setUpClass(cls):
242247
"exists_body_index",
243248
{"mappings": {"dynamic": False, "fields": {"body": {"type": "token"}}}},
244249
)
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")
246254

247255
def test_search_exists(self):
248256
qs = Article.objects.annotate(score=SearchExists(path="body"))
@@ -266,7 +274,10 @@ def setUpClass(cls):
266274
"in_headline_index",
267275
{"mappings": {"dynamic": False, "fields": {"headline": {"type": "token"}}}},
268276
)
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")
270281
Article.objects.create(headline="road", number=2, body="b")
271282

272283
def test_search_in(self):
@@ -293,7 +304,10 @@ def setUpClass(cls):
293304
"phrase_body_index",
294305
{"mappings": {"dynamic": False, "fields": {"body": {"type": "string"}}}},
295306
)
296-
cls.article = Article.objects.create(
307+
308+
def setUp(self):
309+
super().setUp()
310+
self.article = Article.objects.create(
297311
headline="irrelevant", number=1, body="the quick brown fox"
298312
)
299313
Article.objects.create(headline="cheetah", number=2, body="fastest animal")
@@ -323,7 +337,10 @@ def setUpClass(cls):
323337
{"mappings": {"dynamic": False, "fields": {"number": {"type": "number"}}}},
324338
)
325339
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")
327344

328345
def test_search_range(self):
329346
qs = Article.objects.annotate(score=SearchRange(path="number", gte=10, lt=30))
@@ -354,7 +371,10 @@ def setUpClass(cls):
354371
}
355372
},
356373
)
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")
358378
Article.objects.create(headline="hola mundo", number=2, body="abc")
359379

360380
def test_search_regex(self):
@@ -385,7 +405,10 @@ def setUpClass(cls):
385405
"text_body_index",
386406
{"mappings": {"dynamic": False, "fields": {"body": {"type": "string"}}}},
387407
)
388-
cls.article = Article.objects.create(
408+
409+
def setUp(self):
410+
super().setUp()
411+
self.article = Article.objects.create(
389412
headline="ignored", number=1, body="The lazy dog sleeps"
390413
)
391414
Article.objects.create(headline="ignored", number=2, body="The sleepy bear")
@@ -437,7 +460,10 @@ def setUpClass(cls):
437460
}
438461
},
439462
)
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="")
441467
Article.objects.create(headline="batman", number=2, body="")
442468

443469
def test_search_wildcard(self):
@@ -469,7 +495,10 @@ def setUpClass(cls):
469495
}
470496
},
471497
)
472-
cls.article = Article.objects.create(
498+
499+
def setUp(self):
500+
super().setUp()
501+
self.article = Article.objects.create(
473502
headline="any", number=1, body="", location={"type": "Point", "coordinates": [40, 5]}
474503
)
475504
Article.objects.create(
@@ -512,7 +541,10 @@ def setUpClass(cls):
512541
"geowithin_location_index",
513542
{"mappings": {"dynamic": False, "fields": {"location": {"type": "geo"}}}},
514543
)
515-
cls.article = Article.objects.create(
544+
545+
def setUp(self):
546+
super().setUp()
547+
self.article = Article.objects.create(
516548
headline="geo", number=2, body="", location={"type": "Point", "coordinates": [40, 5]}
517549
)
518550
Article.objects.create(
@@ -615,25 +647,28 @@ def setUpClass(cls):
615647
}
616648
},
617649
)
618-
cls.mars_mission = Article.objects.create(
650+
651+
def setUp(self):
652+
super().setUp()
653+
self.mars_mission = Article.objects.create(
619654
number=1,
620655
headline="space exploration",
621656
body="NASA launches a new mission to Mars, aiming to study surface geology",
622657
)
623658

624-
cls.exoplanet = Article.objects.create(
659+
self.exoplanet = Article.objects.create(
625660
number=2,
626661
headline="space exploration",
627662
body="Astronomers discover exoplanets orbiting distant stars using Webb telescope",
628663
)
629664

630-
cls.icy_moons = Article.objects.create(
665+
self.icy_moons = Article.objects.create(
631666
number=3,
632667
headline="space exploration",
633668
body="ESA prepares a robotic expedition to explore the icy moons of Jupiter",
634669
)
635670

636-
cls.comodities_drop = Article.objects.create(
671+
self.comodities_drop = Article.objects.create(
637672
number=4,
638673
headline="astronomy news",
639674
body="Commodities dropped sharply due to inflation concerns",
@@ -780,13 +815,15 @@ def setUpClass(cls):
780815
type="vectorSearch",
781816
)
782817

783-
cls.mars = Article.objects.create(
818+
def setUp(self):
819+
super().setUp()
820+
self.mars = Article.objects.create(
784821
headline="Mars landing",
785822
number=1,
786823
body="The rover has landed on Mars",
787824
plot_embedding=[0.1, 0.2, 0.3],
788825
)
789-
cls.cooking = Article.objects.create(
826+
self.cooking = Article.objects.create(
790827
headline="Cooking tips",
791828
number=2,
792829
body="This article is about pasta",

0 commit comments

Comments
 (0)