Skip to content

Commit 5bfc0d5

Browse files
committed
indexes
1 parent 4ff3fd6 commit 5bfc0d5

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

tests/indexes/tests.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,9 @@ def test_partial_index(self):
405405
),
406406
),
407407
)
408-
self.assertIn(
409-
"WHERE %s" % editor.quote_name("pub_date"),
410-
str(index.create_sql(Article, schema_editor=editor)),
408+
self.assertEqual(
409+
"{'pub_date': {'$gt': datetime.datetime(2015, 1, 1, 6, 0)}}",
410+
str(index._get_condition_mql(Article, schema_editor=editor)),
411411
)
412412
editor.add_index(index=index, model=Article)
413413
with connection.cursor() as cursor:
@@ -424,12 +424,13 @@ def test_integer_restriction_partial(self):
424424
with connection.schema_editor() as editor:
425425
index = Index(
426426
name="recent_article_idx",
427-
fields=["id"],
427+
# This is changed
428+
fields=["headline"],
428429
condition=Q(pk__gt=1),
429430
)
430-
self.assertIn(
431-
"WHERE %s" % editor.quote_name("id"),
432-
str(index.create_sql(Article, schema_editor=editor)),
431+
self.assertEqual(
432+
"{'_id': {'$gt': 1}}",
433+
str(index._get_condition_mql(Article, schema_editor=editor)),
433434
)
434435
editor.add_index(index=index, model=Article)
435436
with connection.cursor() as cursor:
@@ -449,9 +450,9 @@ def test_boolean_restriction_partial(self):
449450
fields=["published"],
450451
condition=Q(published=True),
451452
)
452-
self.assertIn(
453-
"WHERE %s" % editor.quote_name("published"),
454-
str(index.create_sql(Article, schema_editor=editor)),
453+
self.assertEqual(
454+
"{'published': {'$eq': True}}",
455+
str(index._get_condition_mql(Article, schema_editor=editor)),
455456
)
456457
editor.add_index(index=index, model=Article)
457458
with connection.cursor() as cursor:
@@ -482,12 +483,13 @@ def test_multiple_conditions(self):
482483
& Q(headline__contains="China")
483484
),
484485
)
485-
sql = str(index.create_sql(Article, schema_editor=editor))
486-
where = sql.find("WHERE")
487-
self.assertIn("WHERE (%s" % editor.quote_name("pub_date"), sql)
486+
sql = str(index._get_condition_mql(Article, schema_editor=editor))
487+
self.assertEqual(sql, "... TO FILL IN ...")
488+
# where = sql.find("WHERE")
489+
# self.assertIn("WHERE (%s" % editor.quote_name("pub_date"), sql)
488490
# Because each backend has different syntax for the operators,
489491
# check ONLY the occurrence of headline in the SQL.
490-
self.assertGreater(sql.rfind("headline"), where)
492+
# self.assertGreater(sql.rfind("headline"), where)
491493
editor.add_index(index=index, model=Article)
492494
with connection.cursor() as cursor:
493495
self.assertIn(
@@ -506,9 +508,10 @@ def test_is_null_condition(self):
506508
fields=["pub_date"],
507509
condition=Q(pub_date__isnull=False),
508510
)
509-
self.assertIn(
510-
"WHERE %s IS NOT NULL" % editor.quote_name("pub_date"),
511+
512+
self.assertEqual(
511513
str(index.create_sql(Article, schema_editor=editor)),
514+
"... TO FILL IN ...",
512515
)
513516
editor.add_index(index=index, model=Article)
514517
with connection.cursor() as cursor:

0 commit comments

Comments
 (0)