コード例 #1
0
    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"
        )
コード例 #2
0
    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"
        )
コード例 #3
0
    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"]
コード例 #4
0
    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"]