diff --git a/tests/indexes/tests.py b/tests/indexes/tests.py index 8fdaec25f5..c8e810f0e6 100644 --- a/tests/indexes/tests.py +++ b/tests/indexes/tests.py @@ -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: @@ -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: @@ -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: @@ -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( @@ -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: