mirror of
https://github.com/Infinidat/infi.clickhouse_orm.git
synced 2024-11-11 03:46:34 +03:00
1) Added a test on https://github.com/Infinidat/infi.clickhouse_orm/issues/66
2) Fixed issue
This commit is contained in:
parent
c023ad407d
commit
0927136ffd
|
@ -57,6 +57,10 @@ class ModelBase(type):
|
||||||
# Enums
|
# Enums
|
||||||
if db_type.startswith('Enum'):
|
if db_type.startswith('Enum'):
|
||||||
return orm_fields.BaseEnumField.create_ad_hoc_field(db_type)
|
return orm_fields.BaseEnumField.create_ad_hoc_field(db_type)
|
||||||
|
# DateTime with timezone
|
||||||
|
if db_type.startswith('DateTime('):
|
||||||
|
# Some functions return DateTimeField with timezone in brackets
|
||||||
|
return orm_fields.DateTimeField()
|
||||||
# Arrays
|
# Arrays
|
||||||
if db_type.startswith('Array'):
|
if db_type.startswith('Array'):
|
||||||
inner_field = cls.create_ad_hoc_field(db_type[6 : -1])
|
inner_field = cls.create_ad_hoc_field(db_type[6 : -1])
|
||||||
|
|
42
tests/test_datetime_fields.py
Normal file
42
tests/test_datetime_fields.py
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from infi.clickhouse_orm.database import Database
|
||||||
|
from infi.clickhouse_orm.models import Model
|
||||||
|
from infi.clickhouse_orm.fields import *
|
||||||
|
from infi.clickhouse_orm.engines import *
|
||||||
|
|
||||||
|
|
||||||
|
class DateFieldsTest(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.database = Database('test-db')
|
||||||
|
self.database.create_table(ModelWithDate)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
self.database.drop_database()
|
||||||
|
|
||||||
|
def test_ad_hoc_model(self):
|
||||||
|
self.database.insert([
|
||||||
|
ModelWithDate(date_field='2016-08-30', datetime_field='2016-08-30 03:50:00'),
|
||||||
|
ModelWithDate(date_field='2016-08-31', datetime_field='2016-08-31 01:30:00')
|
||||||
|
])
|
||||||
|
|
||||||
|
# toStartOfHour returns DateTime('Asia/Yekaterinburg') in my case, so I test it here to
|
||||||
|
query = 'SELECT toStartOfHour(datetime_field) as hour_start, * from $db.modelwithdate ORDER BY date_field'
|
||||||
|
results = list(self.database.select(query))
|
||||||
|
self.assertEquals(len(results), 2)
|
||||||
|
self.assertEquals(results[0].date_field, datetime.date(2016, 8, 30))
|
||||||
|
self.assertEquals(results[0].datetime_field, datetime.datetime(2016, 8, 30, 3, 50, 0, tzinfo=pytz.UTC))
|
||||||
|
self.assertEquals(results[0].hour_start, datetime.datetime(2016, 8, 30, 3, 0, 0, tzinfo=pytz.UTC))
|
||||||
|
self.assertEquals(results[1].date_field, datetime.date(2016, 8, 31))
|
||||||
|
self.assertEquals(results[1].datetime_field, datetime.datetime(2016, 8, 31, 1, 30, 0, tzinfo=pytz.UTC))
|
||||||
|
self.assertEquals(results[1].hour_start, datetime.datetime(2016, 8, 31, 1, 0, 0, tzinfo=pytz.UTC))
|
||||||
|
|
||||||
|
|
||||||
|
class ModelWithDate(Model):
|
||||||
|
|
||||||
|
date_field = DateField()
|
||||||
|
datetime_field = DateTimeField()
|
||||||
|
|
||||||
|
engine = MergeTree('date_field', ('date_field',))
|
Loading…
Reference in New Issue
Block a user