def test_fail_when_defining_invalid_index(self): index = Index("my_super_index", self.table.c.name.distinct()) with pytest.raises(errors.InvalidIndexDefinition) as err: meta.convert_index(self.table, index) assert err.value.args[0] == ( "Table `test_table` index `my_super_index`: \n" "Invalid index definition.\n" "Example: Index('some_index', some_table.c.some_column)\n" "Cf: https://docs.sqlalchemy.org/en/13/core/constraints.html#indexes" )
def test_fail_when_using_unsupported_functional_index(self): index = Index("my_super_index", func.lower(self.table.c.name)) with pytest.raises(errors.UnsupportedFunctionalIndex) as err: meta.convert_index(self.table, index) assert err.value.args[0] == ( "Table `test_table` index `my_super_index`: \n" "Only descending index is supported yet.\n" "Example: Index('some_index', some_table.c.some_column.desc())\n" "Cf: https://docs.sqlalchemy.org/en/13/core/constraints.html#functional-indexes" )
def test_descending_index(self): index = Index("my_super_index", self.table.c.name.desc()) django_index = meta.convert_index(self.table, index) assert django_index.name == "my_super_index" assert django_index.fields == ["-name"]
def test_multiple_field(self): index = Index("my_super_index", self.table.c.name, self.table.c.age) django_index = meta.convert_index(self.table, index) assert django_index.name == "my_super_index" assert django_index.fields == ["name", "age"]