2018-11-15 15:37:58 +03:00
|
|
|
import datetime
|
|
|
|
|
|
|
|
from django.test import TestCase
|
|
|
|
|
|
|
|
from django_clickhouse.serializers import Django2ClickHouseModelSerializer
|
2018-11-16 13:16:36 +03:00
|
|
|
from tests.clickhouse_models import ClickHouseTestModel
|
2018-11-15 15:37:58 +03:00
|
|
|
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):
|
2018-11-22 10:33:51 +03:00
|
|
|
serializer = Django2ClickHouseModelSerializer(ClickHouseTestModel)
|
|
|
|
res = serializer.serialize(self.obj)
|
2018-11-16 13:16:36 +03:00
|
|
|
self.assertIsInstance(res, ClickHouseTestModel)
|
2018-11-15 15:37:58 +03:00
|
|
|
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):
|
2018-11-22 10:33:51 +03:00
|
|
|
serializer = Django2ClickHouseModelSerializer(ClickHouseTestModel, fields=('value'))
|
|
|
|
res = serializer.serialize(self.obj)
|
2018-11-16 13:16:36 +03:00
|
|
|
self.assertIsInstance(res, ClickHouseTestModel)
|
2018-11-15 15:37:58 +03:00
|
|
|
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):
|
2018-11-22 10:33:51 +03:00
|
|
|
serializer = Django2ClickHouseModelSerializer(ClickHouseTestModel, exclude_fields=('created_date',))
|
|
|
|
res = serializer.serialize(self.obj)
|
2018-11-16 13:16:36 +03:00
|
|
|
self.assertIsInstance(res, ClickHouseTestModel)
|
2018-11-15 15:37:58 +03:00
|
|
|
self.assertEqual(datetime.date(1970, 1, 1), res.created_date)
|
|
|
|
self.assertEqual(self.obj.id, res.id)
|
|
|
|
self.assertEqual(self.obj.value, res.value)
|