mirror of
https://github.com/carrotquest/django-clickhouse.git
synced 2024-11-11 03:46:46 +03:00
d4e9a705d1
2) Bug fixes 3) Simple tests on syncing MergeTree and CollapsingMergeTree
39 lines
1.5 KiB
Python
39 lines
1.5 KiB
Python
import datetime
|
|
|
|
from django.test import TestCase
|
|
|
|
from django_clickhouse.serializers import Django2ClickHouseModelSerializer
|
|
from tests.clickhouse_models import ClickHouseTestModel
|
|
from tests.models import TestModel
|
|
|
|
|
|
class Django2ClickHouseModelSerializerTest(TestCase):
|
|
fixtures = ['test_model']
|
|
|
|
def setUp(self):
|
|
self.obj = TestModel.objects.get(pk=1)
|
|
|
|
def test_all(self):
|
|
serializer = Django2ClickHouseModelSerializer()
|
|
res = serializer.serialize(self.obj, ClickHouseTestModel)
|
|
self.assertIsInstance(res, ClickHouseTestModel)
|
|
self.assertEqual(self.obj.id, res.id)
|
|
self.assertEqual(self.obj.value, res.value)
|
|
self.assertEqual(self.obj.created_date, res.created_date)
|
|
|
|
def test_fields(self):
|
|
serializer = Django2ClickHouseModelSerializer(fields=('value'))
|
|
res = serializer.serialize(self.obj, ClickHouseTestModel)
|
|
self.assertIsInstance(res, ClickHouseTestModel)
|
|
self.assertEqual(0, res.id)
|
|
self.assertEqual(datetime.date(1970, 1, 1), res.created_date)
|
|
self.assertEqual(self.obj.value, res.value)
|
|
|
|
def test_exclude_fields(self):
|
|
serializer = Django2ClickHouseModelSerializer(exclude_fields=('created_date',))
|
|
res = serializer.serialize(self.obj, ClickHouseTestModel)
|
|
self.assertIsInstance(res, ClickHouseTestModel)
|
|
self.assertEqual(datetime.date(1970, 1, 1), res.created_date)
|
|
self.assertEqual(self.obj.id, res.id)
|
|
self.assertEqual(self.obj.value, res.value)
|