Skip to content

Commit

Permalink
indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
timgraham committed Oct 23, 2024
1 parent bdc3273 commit e03e963
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions tests/indexes/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,9 @@ def test_partial_index(self):
),
),
)
self.assertIn(
"WHERE %s" % editor.quote_name("pub_date"),
str(index.create_sql(Article, schema_editor=editor)),
self.assertEqual(
"{'pub_date': {'$gt': datetime.datetime(2015, 1, 1, 6, 0)}}",
str(index._get_condition_mql(Article, schema_editor=editor)),
)
editor.add_index(index=index, model=Article)
with connection.cursor() as cursor:
Expand All @@ -424,12 +424,13 @@ def test_integer_restriction_partial(self):
with connection.schema_editor() as editor:
index = Index(
name="recent_article_idx",
fields=["id"],
# This is changed
fields=["headline"],
condition=Q(pk__gt=1),
)
self.assertIn(
"WHERE %s" % editor.quote_name("id"),
str(index.create_sql(Article, schema_editor=editor)),
self.assertEqual(
"{'_id': {'$gt': 1}}",
str(index._get_condition_mql(Article, schema_editor=editor)),
)
editor.add_index(index=index, model=Article)
with connection.cursor() as cursor:
Expand All @@ -449,9 +450,9 @@ def test_boolean_restriction_partial(self):
fields=["published"],
condition=Q(published=True),
)
self.assertIn(
"WHERE %s" % editor.quote_name("published"),
str(index.create_sql(Article, schema_editor=editor)),
self.assertEqual(
"{'published': {'$eq': True}}",
str(index._get_condition_mql(Article, schema_editor=editor)),
)
editor.add_index(index=index, model=Article)
with connection.cursor() as cursor:
Expand Down Expand Up @@ -482,12 +483,13 @@ def test_multiple_conditions(self):
& Q(headline__contains="China")
),
)
sql = str(index.create_sql(Article, schema_editor=editor))
where = sql.find("WHERE")
self.assertIn("WHERE (%s" % editor.quote_name("pub_date"), sql)
sql = str(index._get_condition_mql(Article, schema_editor=editor))
self.assertEqual(sql, "... TO FILL IN ...")
# where = sql.find("WHERE")
# self.assertIn("WHERE (%s" % editor.quote_name("pub_date"), sql)
# Because each backend has different syntax for the operators,
# check ONLY the occurrence of headline in the SQL.
self.assertGreater(sql.rfind("headline"), where)
# self.assertGreater(sql.rfind("headline"), where)
editor.add_index(index=index, model=Article)
with connection.cursor() as cursor:
self.assertIn(
Expand All @@ -506,9 +508,10 @@ def test_is_null_condition(self):
fields=["pub_date"],
condition=Q(pub_date__isnull=False),
)
self.assertIn(
"WHERE %s IS NOT NULL" % editor.quote_name("pub_date"),

self.assertEqual(
str(index.create_sql(Article, schema_editor=editor)),
"... TO FILL IN ...",
)
editor.add_index(index=index, model=Article)
with connection.cursor() as cursor:
Expand Down

0 comments on commit e03e963

Please sign in to comment.