Add a couple of small tests

This commit is contained in:
Itai Shirav 2017-05-05 15:22:16 +03:00
parent 3f8434fe50
commit b3437dae7e
2 changed files with 14 additions and 1 deletions

View File

@ -2,7 +2,7 @@
import unittest
from infi.clickhouse_orm.database import Database
from infi.clickhouse_orm.database import Database, DatabaseException
from .base_test_with_data import *
@ -108,6 +108,11 @@ class DatabaseTestCase(TestCaseWithData):
with self.assertRaises(ValueError):
self.database.paginate(Person, 'first_name, last_name', page_num, 100)
def test_pagination_with_conditions(self):
self._insert_and_check(self._sample_data(), len(data))
page = self.database.paginate(Person, 'first_name, last_name', 1, 100, conditions="first_name < 'Ava'")
self.assertEquals(page.number_of_objects, 10)
def test_special_chars(self):
s = u'אבגד \\\'"`,.;éåäöšž\n\t\0\b\r'
p = Person(first_name=s)
@ -121,3 +126,6 @@ class DatabaseTestCase(TestCaseWithData):
results = self.database.raw(query)
self.assertEqual(results, "Whitney\tDurham\t1977-09-15\t1.72\nWhitney\tScott\t1971-07-04\t1.7\n")
def test_invalid_user(self):
with self.assertRaises(DatabaseException):
Database(self.database.db_name, username='default', password='wrong')

View File

@ -38,6 +38,11 @@ class EnginesTestCase(unittest.TestCase):
engine = MergeTree('date', ('date', 'event_id', 'event_group'), index_granularity=4096)
self._create_and_insert(TestModel)
def test_replicated_merge_tree(self):
engine = MergeTree('date', ('date', 'event_id', 'event_group'), replica_table_path='/clickhouse/tables/{layer}-{shard}/hits', replica_name='{replica}')
expected = "ReplicatedMergeTree('/clickhouse/tables/{layer}-{shard}/hits', '{replica}', date, (date, event_id, event_group), 8192)"
self.assertEquals(engine.create_table_sql(), expected)
def test_collapsing_merge_tree(self):
class TestModel(SampleModel):
engine = CollapsingMergeTree('date', ('date', 'event_id', 'event_group'), 'event_version')