mirror of
https://github.com/carrotquest/django-clickhouse.git
synced 2024-11-22 17:16:37 +03:00
30 lines
1.0 KiB
Python
30 lines
1.0 KiB
Python
|
import datetime
|
||
|
|
||
|
from django.test import TestCase
|
||
|
|
||
|
from tests.clickhouse_models import ClickHouseTestModel
|
||
|
|
||
|
|
||
|
class ClickHouseModelTest(TestCase):
|
||
|
def setUp(self):
|
||
|
self.storage = ClickHouseTestModel.get_storage()
|
||
|
self.storage.flush()
|
||
|
|
||
|
def test_need_sync(self):
|
||
|
# sync is disabled by default
|
||
|
self.assertFalse(ClickHouseTestModel.need_sync())
|
||
|
|
||
|
# There were no syncs. So it should be done
|
||
|
ClickHouseTestModel.sync_enabled = True
|
||
|
self.assertTrue(ClickHouseTestModel.need_sync())
|
||
|
|
||
|
# Time hasn't passed - no sync
|
||
|
self.storage.set_last_sync_time(ClickHouseTestModel.get_import_key(), datetime.datetime.now())
|
||
|
self.assertFalse(ClickHouseTestModel.need_sync())
|
||
|
|
||
|
# Time has passed
|
||
|
sync_delay = ClickHouseTestModel.get_sync_delay()
|
||
|
self.storage.set_last_sync_time(ClickHouseTestModel.get_import_key(),
|
||
|
datetime.datetime.now() - datetime.timedelta(seconds=sync_delay))
|
||
|
self.assertFalse(ClickHouseTestModel.need_sync())
|