Skip to content

Commit

Permalink
Add test for indexes with computed columns.
Browse files Browse the repository at this point in the history
  • Loading branch information
coleifer committed Oct 4, 2018
1 parent a4621ba commit 1c1a4f9
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions tests/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,19 @@ class Article(TestModel):
Article.add_index(SQL('CREATE INDEX "article_foo" ON "article" ("flags" & 3)'))


class FuncIdx(TestModel):
a = IntegerField()
b = IntegerField()

idx = FuncIdx.index(FuncIdx.a, FuncIdx.b, fn.SUM(FuncIdx.a + FuncIdx.b))
FuncIdx.add_index(idx)


class TestModelDDL(ModelDatabaseTestCase):
database = get_in_memory_db()
requires = [Article, Category, KV, Note, Person, Relationship, TMUnique,
TMSequence, TMIndexes, TMConstraints, User, CacheData]
requires = [Article, CacheData, Category, FuncIdx, KV, Note, Person,
Relationship, TMUnique, TMSequence, TMIndexes, TMConstraints,
User]

def test_database_required(self):
class MissingDB(Model):
Expand Down Expand Up @@ -167,6 +176,12 @@ def test_model_indexes_custom_tablename(self):
('CREATE UNIQUE INDEX "kvs_key_value" ON "kvs" ("key", "value")',
[])])

def test_model_indexes_computed_columns(self):
self.assertIndexes(FuncIdx, [
('CREATE INDEX "func_idx_a_b" ON "func_idx" '
'("a", "b", SUM("a" + "b"))', []),
])

def test_model_indexes_complex_columns(self):
class Taxonomy(TestModel):
name = CharField()
Expand Down

0 comments on commit 1c1a4f9

Please sign in to comment.