infi.clickhouse_orm/tests/test_inheritance.py

55 lines
1.7 KiB
Python
Raw Permalink Normal View History

2017-08-16 23:48:18 +03:00
from __future__ import unicode_literals
2016-06-29 14:52:55 +03:00
import unittest
import datetime
import pytz
from infi.clickhouse_orm.database import Database
2016-06-29 14:52:55 +03:00
from infi.clickhouse_orm.models import Model
from infi.clickhouse_orm.fields import *
from infi.clickhouse_orm.engines import *
class InheritanceTestCase(unittest.TestCase):
def assertFieldNames(self, model_class, names):
self.assertEqual(names, list(model_class.fields()))
2016-06-29 14:52:55 +03:00
def test_field_inheritance(self):
self.assertFieldNames(ParentModel, ['date_field', 'int_field'])
self.assertFieldNames(Model1, ['date_field', 'int_field', 'string_field'])
self.assertFieldNames(Model2, ['date_field', 'int_field', 'float_field'])
def test_create_table_sql(self):
default_db = Database('default')
sql1 = ParentModel.create_table_sql(default_db)
sql2 = Model1.create_table_sql(default_db)
sql3 = Model2.create_table_sql(default_db)
2016-06-29 14:52:55 +03:00
self.assertNotEqual(sql1, sql2)
self.assertNotEqual(sql1, sql3)
self.assertNotEqual(sql2, sql3)
def test_get_field(self):
self.assertIsNotNone(ParentModel().get_field('date_field'))
self.assertIsNone(ParentModel().get_field('string_field'))
self.assertIsNotNone(Model1().get_field('date_field'))
self.assertIsNotNone(Model1().get_field('string_field'))
self.assertIsNone(Model1().get_field('float_field'))
class ParentModel(Model):
date_field = DateField()
int_field = Int32Field()
engine = MergeTree('date_field', ('int_field', 'date_field'))
class Model1(ParentModel):
string_field = StringField()
class Model2(ParentModel):
float_field = Float32Field()