(self)
| 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: |
nothing calls this directly
no test coverage detected