Refactoring

This commit is contained in:
M1ha 2018-11-28 15:33:01 +05:00
parent abe0ae45c5
commit 166d23ca7c
3 changed files with 10 additions and 10 deletions

View File

@ -1,4 +1,4 @@
from typing import Optional, Iterable
from typing import Optional, Iterable, List
from copy import copy
from infi.clickhouse_orm.database import Database
@ -70,9 +70,9 @@ class QuerySet(InfiQuerySet):
self.get_database(for_write=True).insert([instance])
return instance
def bulk_create(self, model_instances, batch_size=1000): # type: (Iterable[InfiModel], int)
def bulk_create(self, model_instances, batch_size=1000): # type: (Iterable[InfiModel], int) -> List[InfiModel]
self.get_database(for_write=True).insert(model_instances=model_instances, batch_size=batch_size)
return model_instances
return list(model_instances)
class AggregateQuerySet(QuerySet, InfiAggregateQuerySet):

View File

@ -25,7 +25,7 @@ class TestQuerySet(TestCase):
def test_all(self):
self.db.insert([ClickHouseTestModel(id=i, created_date=datetime.date.today(), value=i) for i in range(1, 4)])
qs = ClickHouseTestModel.objects.all()
print(qs.get_database(for_write=True).db_name)
self.assertIsInstance(qs, QuerySet)
self.assertEqual(3, qs.count())

View File

@ -28,7 +28,7 @@ class SyncTest(TransactionTestCase):
obj = TestModel.objects.create(value=1, created_date=datetime.date.today())
ClickHouseTestModel.sync_batch_from_storage()
synced_data = list(ClickHouseTestModel.objects_in(connections['default']))
synced_data = list(ClickHouseTestModel.objects.all())
self.assertEqual(1, len(synced_data))
self.assertEqual(obj.created_date, synced_data[0].created_date)
self.assertEqual(obj.value, synced_data[0].value)
@ -41,7 +41,7 @@ class SyncTest(TransactionTestCase):
ClickHouseCollapseTestModel.sync_batch_from_storage()
# sync_batch_from_storage uses FINAL, so data would be collapsed by now
synced_data = list(ClickHouseCollapseTestModel.objects_in(connections['default']))
synced_data = list(ClickHouseCollapseTestModel.objects.all())
self.assertEqual(1, len(synced_data))
self.assertEqual(obj.created_date, synced_data[0].created_date)
self.assertEqual(obj.value, synced_data[0].value)
@ -65,7 +65,7 @@ class SyncTest(TransactionTestCase):
ClickHouseCollapseTestModel.sync_batch_from_storage()
# sync_batch_from_storage uses FINAL, so data would be collapsed by now
synced_data = list(ClickHouseCollapseTestModel.objects_in(connections['default']))
synced_data = list(ClickHouseCollapseTestModel.objects.all())
self.assertEqual(0, len(synced_data))
def test_multi_model(self):
@ -74,14 +74,14 @@ class SyncTest(TransactionTestCase):
obj.save()
ClickHouseMultiTestModel.sync_batch_from_storage()
synced_data = list(ClickHouseTestModel.objects_in(connections['default']))
synced_data = list(ClickHouseTestModel.objects.all())
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']))
synced_data = list(ClickHouseCollapseTestModel.objects.all())
self.assertEqual(1, len(synced_data))
self.assertEqual(obj.created_date, synced_data[0].created_date)
self.assertEqual(obj.value, synced_data[0].value)