2018-11-20 15:24:15 +03:00
|
|
|
import datetime
|
|
|
|
|
2018-11-14 10:52:01 +03:00
|
|
|
from django.test import TestCase
|
|
|
|
|
2018-11-15 11:02:05 +03:00
|
|
|
from django_clickhouse.storages import RedisStorage
|
2018-11-14 10:52:01 +03:00
|
|
|
|
|
|
|
|
|
|
|
class StorageTest(TestCase):
|
|
|
|
storage = RedisStorage()
|
|
|
|
|
|
|
|
def setUp(self):
|
2018-11-15 11:02:05 +03:00
|
|
|
self.storage.flush()
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
self.storage.flush()
|
2018-11-14 10:52:01 +03:00
|
|
|
|
|
|
|
def test_operation_pks(self):
|
2018-11-14 13:18:06 +03:00
|
|
|
self.storage.register_operations_wrapped('test', 'insert', 100500)
|
|
|
|
self.storage.register_operations_wrapped('test', 'insert', 100501)
|
|
|
|
self.storage.register_operations_wrapped('test', 'insert', 100502)
|
2018-11-14 10:52:01 +03:00
|
|
|
self.assertListEqual([
|
|
|
|
('insert', '100500'),
|
|
|
|
('insert', '100501'),
|
|
|
|
('insert', '100502'),
|
|
|
|
], self.storage.get_operations('test', 10))
|
|
|
|
|
|
|
|
def test_operation_types(self):
|
2018-11-14 13:18:06 +03:00
|
|
|
self.storage.register_operations_wrapped('test', 'insert', 100500)
|
|
|
|
self.storage.register_operations_wrapped('test', 'update', 100500)
|
|
|
|
self.storage.register_operations_wrapped('test', 'delete', 100500)
|
2018-11-14 10:52:01 +03:00
|
|
|
self.assertListEqual([
|
|
|
|
('insert', '100500'),
|
|
|
|
('update', '100500'),
|
|
|
|
('delete', '100500'),
|
|
|
|
], self.storage.get_operations('test', 10))
|
|
|
|
|
|
|
|
def test_operation_import_keys(self):
|
2018-11-14 13:18:06 +03:00
|
|
|
self.storage.register_operations_wrapped('test1', 'insert', 100500)
|
|
|
|
self.storage.register_operations_wrapped('test2', 'insert', 100500)
|
|
|
|
self.storage.register_operations_wrapped('test2', 'insert', 100501)
|
2018-11-14 10:52:01 +03:00
|
|
|
self.assertListEqual([
|
|
|
|
('insert', '100500')
|
|
|
|
], self.storage.get_operations('test1', 10))
|
|
|
|
self.assertListEqual([
|
|
|
|
('insert', '100500'),
|
|
|
|
('insert', '100501'),
|
|
|
|
], self.storage.get_operations('test2', 10))
|
|
|
|
|
2018-11-14 11:02:33 +03:00
|
|
|
def test_post_sync(self):
|
2018-11-20 15:24:15 +03:00
|
|
|
self.storage.pre_sync('test')
|
2018-11-14 13:18:06 +03:00
|
|
|
self.storage.register_operations_wrapped('test', 'insert', 100500)
|
|
|
|
self.storage.register_operations_wrapped('test', 'insert', 100501)
|
2018-11-14 11:02:33 +03:00
|
|
|
self.storage.get_operations('test', 10)
|
2018-11-14 13:18:06 +03:00
|
|
|
self.storage.register_operations_wrapped('test', 'insert', 100502)
|
2018-11-14 11:02:33 +03:00
|
|
|
|
|
|
|
self.storage.post_sync('test')
|
|
|
|
self.assertListEqual([
|
|
|
|
('insert', '100502')
|
|
|
|
], self.storage.get_operations('test', 10))
|
2018-11-20 15:24:15 +03:00
|
|
|
|
|
|
|
def test_last_sync(self):
|
|
|
|
dt = datetime.datetime.now()
|
|
|
|
self.storage.set_last_sync_time('test', dt)
|
|
|
|
self.assertEqual(dt, self.storage.get_last_sync_time('test'))
|