mirror of
https://github.com/carrotquest/django-clickhouse.git
synced 2024-11-22 00:56:37 +03:00
Фиксы по тестам
This commit is contained in:
parent
745b7b7788
commit
d300d6e46e
|
@ -8,7 +8,7 @@ Storage should be able to restore current importing batch, if something goes wro
|
|||
"""
|
||||
import datetime
|
||||
from itertools import chain
|
||||
from typing import Any, Optional, List, Tuple, Iterable
|
||||
from typing import Any, Optional, List, Tuple
|
||||
|
||||
from statsd.defaults.django import statsd
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from infi.clickhouse_orm import fields
|
||||
|
||||
from django_clickhouse.clickhouse_models import ClickHouseModel
|
||||
from django_clickhouse.clickhouse_models import ClickHouseModel, ClickHouseMultiModel
|
||||
from django_clickhouse.engines import ReplacingMergeTree, CollapsingMergeTree
|
||||
from tests.models import TestModel
|
||||
|
||||
|
@ -26,3 +26,8 @@ class ClickHouseCollapseTestModel(ClickHouseModel):
|
|||
sign = fields.Int8Field()
|
||||
|
||||
engine = CollapsingMergeTree('created_date', ('id',), 'sign')
|
||||
|
||||
|
||||
class ClickHouseMultiTestModel(ClickHouseMultiModel):
|
||||
django_model = TestModel
|
||||
sub_models = [ClickHouseTestModel, ClickHouseCollapseTestModel]
|
||||
|
|
|
@ -14,7 +14,7 @@ from django.test import TransactionTestCase, override_settings
|
|||
from django_clickhouse import config
|
||||
from django_clickhouse.database import connections
|
||||
from django_clickhouse.migrations import migrate_app
|
||||
from tests.clickhouse_models import ClickHouseTestModel, ClickHouseCollapseTestModel
|
||||
from tests.clickhouse_models import ClickHouseTestModel, ClickHouseCollapseTestModel, ClickHouseMultiTestModel
|
||||
from tests.models import TestModel
|
||||
|
||||
|
||||
|
@ -71,6 +71,35 @@ class SyncTest(TransactionTestCase):
|
|||
synced_data = list(ClickHouseCollapseTestModel.objects_in(connections['default']))
|
||||
self.assertEqual(0, len(synced_data))
|
||||
|
||||
def test_multi_model(self):
|
||||
obj = TestModel.objects.create(value=1, created_date=datetime.date.today())
|
||||
obj.value = 2
|
||||
obj.save()
|
||||
ClickHouseMultiTestModel.sync_batch_from_storage()
|
||||
|
||||
synced_data = list(ClickHouseTestModel.objects_in(connections['default']))
|
||||
self.assertEqual(1, len(synced_data))
|
||||
self.assertEqual(obj.created_date, synced_data[0].created_date)
|
||||
self.assertEqual(obj.value, synced_data[0].value)
|
||||
self.assertEqual(obj.id, synced_data[0].id)
|
||||
|
||||
# sync_batch_from_storage uses FINAL, so data would be collapsed by now
|
||||
synced_data = list(ClickHouseCollapseTestModel.objects_in(connections['default']))
|
||||
self.assertEqual(1, len(synced_data))
|
||||
self.assertEqual(obj.created_date, synced_data[0].created_date)
|
||||
self.assertEqual(obj.value, synced_data[0].value)
|
||||
self.assertEqual(obj.id, synced_data[0].id)
|
||||
|
||||
obj.value = 3
|
||||
obj.save()
|
||||
ClickHouseMultiTestModel.sync_batch_from_storage()
|
||||
|
||||
synced_data = list(self.db.select('SELECT * FROM $table FINAL', model_class=ClickHouseCollapseTestModel))
|
||||
self.assertGreaterEqual(1, len(synced_data))
|
||||
self.assertEqual(obj.created_date, synced_data[0].created_date)
|
||||
self.assertEqual(obj.value, synced_data[0].value)
|
||||
self.assertEqual(obj.id, synced_data[0].id)
|
||||
|
||||
|
||||
@skip("This doesn't work due to different threads connection problems")
|
||||
class KillTest(TransactionTestCase):
|
||||
|
|
Loading…
Reference in New Issue
Block a user