django-clickhouse/tests/test_clickhouse_models.py
M1ha Shvn 244b4fbd37
Added latest software versions to testing in GitHub actions (#48)
1. Added latest software versions to testing in GitHub actions
2. Fixed timezone mistakes in tests
3. Fixed naive datetime warnings
2024-01-05 15:20:10 +05:00

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())