mirror of
https://github.com/carrotquest/django-clickhouse.git
synced 2024-11-10 19:36:38 +03:00
244b4fbd37
1. Added latest software versions to testing in GitHub actions 2. Fixed timezone mistakes in tests 3. Fixed naive datetime warnings
32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
import datetime
|
|
|
|
from django.test import TestCase
|
|
from django.utils.timezone import now
|
|
|
|
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
|
|
ClickHouseTestModel.sync_enabled = False
|
|
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(), 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(),
|
|
now() - datetime.timedelta(seconds=sync_delay + 1))
|
|
self.assertTrue(ClickHouseTestModel.need_sync())
|