MCPcopy
hub / github.com/django/django / test_multiple_conditions

Method test_multiple_conditions

tests/indexes/tests.py:461–493  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

459
460 @skipUnlessDBFeature("supports_functions_in_partial_indexes")
461 def test_multiple_conditions(self):
462 with connection.schema_editor() as editor:
463 index = Index(
464 name="recent_article_idx",
465 fields=["pub_date", "headline"],
466 condition=(
467 Q(
468 pub_date__gt=datetime.datetime(
469 year=2015,
470 month=1,
471 day=1,
472 tzinfo=timezone.get_current_timezone(),
473 )
474 )
475 & Q(headline__contains="China")
476 ),
477 )
478 sql = str(index.create_sql(Article, schema_editor=editor))
479 where = sql.find("WHERE")
480 self.assertIn("WHERE (%s" % editor.quote_name("pub_date"), sql)
481 # Because each backend has different syntax for the operators,
482 # check ONLY the occurrence of headline in the SQL.
483 self.assertGreater(sql.rfind("headline"), where)
484 editor.add_index(index=index, model=Article)
485 with connection.cursor() as cursor:
486 self.assertIn(
487 index.name,
488 connection.introspection.get_constraints(
489 cursor=cursor,
490 table_name=Article._meta.db_table,
491 ),
492 )
493 editor.remove_index(index=index, model=Article)
494
495 def test_is_null_condition(self):
496 with connection.schema_editor() as editor:

Callers

nothing calls this directly

Calls 10

create_sqlMethod · 0.95
IndexClass · 0.90
QClass · 0.90
schema_editorMethod · 0.80
cursorMethod · 0.80
findMethod · 0.45
quote_nameMethod · 0.45
add_indexMethod · 0.45
get_constraintsMethod · 0.45
remove_indexMethod · 0.45

Tested by

no test coverage detected