mirror of
https://github.com/Infinidat/infi.clickhouse_orm.git
synced 2025-08-04 04:00:08 +03:00
Chore: isort tests
This commit is contained in:
parent
9ccaacc640
commit
bec70d15db
|
@ -1,12 +1,11 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
import logging
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from clickhouse_orm.database import Database
|
from clickhouse_orm.database import Database
|
||||||
from clickhouse_orm.models import Model
|
|
||||||
from clickhouse_orm.fields import *
|
|
||||||
from clickhouse_orm.engines import *
|
from clickhouse_orm.engines import *
|
||||||
|
from clickhouse_orm.fields import *
|
||||||
import logging
|
from clickhouse_orm.models import Model
|
||||||
|
|
||||||
logging.getLogger("requests").setLevel(logging.WARNING)
|
logging.getLogger("requests").setLevel(logging.WARNING)
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from clickhouse_orm import migrations
|
from clickhouse_orm import migrations
|
||||||
|
|
||||||
from ..test_migrations import *
|
from ..test_migrations import *
|
||||||
|
|
||||||
operations = [migrations.CreateTable(Model1)]
|
operations = [migrations.CreateTable(Model1)]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from clickhouse_orm import migrations
|
from clickhouse_orm import migrations
|
||||||
|
|
||||||
from ..test_migrations import *
|
from ..test_migrations import *
|
||||||
|
|
||||||
operations = [migrations.DropTable(Model1)]
|
operations = [migrations.DropTable(Model1)]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from clickhouse_orm import migrations
|
from clickhouse_orm import migrations
|
||||||
|
|
||||||
from ..test_migrations import *
|
from ..test_migrations import *
|
||||||
|
|
||||||
operations = [migrations.CreateTable(Model1)]
|
operations = [migrations.CreateTable(Model1)]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from clickhouse_orm import migrations
|
from clickhouse_orm import migrations
|
||||||
|
|
||||||
from ..test_migrations import *
|
from ..test_migrations import *
|
||||||
|
|
||||||
operations = [migrations.AlterTable(Model2)]
|
operations = [migrations.AlterTable(Model2)]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from clickhouse_orm import migrations
|
from clickhouse_orm import migrations
|
||||||
|
|
||||||
from ..test_migrations import *
|
from ..test_migrations import *
|
||||||
|
|
||||||
operations = [migrations.AlterTable(Model3)]
|
operations = [migrations.AlterTable(Model3)]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from clickhouse_orm import migrations
|
from clickhouse_orm import migrations
|
||||||
|
|
||||||
from ..test_migrations import *
|
from ..test_migrations import *
|
||||||
|
|
||||||
operations = [migrations.CreateTable(EnumModel1)]
|
operations = [migrations.CreateTable(EnumModel1)]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from clickhouse_orm import migrations
|
from clickhouse_orm import migrations
|
||||||
|
|
||||||
from ..test_migrations import *
|
from ..test_migrations import *
|
||||||
|
|
||||||
operations = [migrations.AlterTable(EnumModel2)]
|
operations = [migrations.AlterTable(EnumModel2)]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from clickhouse_orm import migrations
|
from clickhouse_orm import migrations
|
||||||
|
|
||||||
from ..test_migrations import *
|
from ..test_migrations import *
|
||||||
|
|
||||||
operations = [migrations.CreateTable(MaterializedModel)]
|
operations = [migrations.CreateTable(MaterializedModel)]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from clickhouse_orm import migrations
|
from clickhouse_orm import migrations
|
||||||
|
|
||||||
from ..test_migrations import *
|
from ..test_migrations import *
|
||||||
|
|
||||||
operations = [migrations.CreateTable(AliasModel)]
|
operations = [migrations.CreateTable(AliasModel)]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from clickhouse_orm import migrations
|
from clickhouse_orm import migrations
|
||||||
|
|
||||||
from ..test_migrations import *
|
from ..test_migrations import *
|
||||||
|
|
||||||
operations = [migrations.CreateTable(Model4Buffer)]
|
operations = [migrations.CreateTable(Model4Buffer)]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from clickhouse_orm import migrations
|
from clickhouse_orm import migrations
|
||||||
|
|
||||||
from ..test_migrations import *
|
from ..test_migrations import *
|
||||||
|
|
||||||
operations = [migrations.AlterTableWithBuffer(Model4Buffer_changed)]
|
operations = [migrations.AlterTableWithBuffer(Model4Buffer_changed)]
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from clickhouse_orm import migrations
|
|
||||||
from test_migrations import Model3
|
from test_migrations import Model3
|
||||||
|
|
||||||
|
from clickhouse_orm import migrations
|
||||||
|
|
||||||
|
|
||||||
def forward(database):
|
def forward(database):
|
||||||
database.insert([Model3(date=datetime.date(2016, 1, 4), f1=4, f3=1, f4="test4")])
|
database.insert([Model3(date=datetime.date(2016, 1, 4), f1=4, f3=1, f4="test4")])
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from clickhouse_orm import migrations
|
from clickhouse_orm import migrations
|
||||||
|
|
||||||
from ..test_migrations import *
|
from ..test_migrations import *
|
||||||
|
|
||||||
operations = [migrations.AlterTable(MaterializedModel1), migrations.AlterTable(AliasModel1)]
|
operations = [migrations.AlterTable(MaterializedModel1), migrations.AlterTable(AliasModel1)]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from clickhouse_orm import migrations
|
from clickhouse_orm import migrations
|
||||||
|
|
||||||
from ..test_migrations import *
|
from ..test_migrations import *
|
||||||
|
|
||||||
operations = [migrations.AlterTable(Model4_compressed), migrations.AlterTable(Model2LowCardinality)]
|
operations = [migrations.AlterTable(Model4_compressed), migrations.AlterTable(Model2LowCardinality)]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from clickhouse_orm import migrations
|
from clickhouse_orm import migrations
|
||||||
|
|
||||||
from ..test_migrations import *
|
from ..test_migrations import *
|
||||||
|
|
||||||
operations = [migrations.CreateTable(ModelWithConstraints)]
|
operations = [migrations.CreateTable(ModelWithConstraints)]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from clickhouse_orm import migrations
|
from clickhouse_orm import migrations
|
||||||
|
|
||||||
from ..test_migrations import *
|
from ..test_migrations import *
|
||||||
|
|
||||||
operations = [migrations.AlterConstraints(ModelWithConstraints2)]
|
operations = [migrations.AlterConstraints(ModelWithConstraints2)]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from clickhouse_orm import migrations
|
from clickhouse_orm import migrations
|
||||||
|
|
||||||
from ..test_migrations import *
|
from ..test_migrations import *
|
||||||
|
|
||||||
operations = [migrations.CreateTable(ModelWithIndex)]
|
operations = [migrations.CreateTable(ModelWithIndex)]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from clickhouse_orm import migrations
|
from clickhouse_orm import migrations
|
||||||
|
|
||||||
from ..test_migrations import *
|
from ..test_migrations import *
|
||||||
|
|
||||||
operations = [migrations.AlterIndexes(ModelWithIndex2, reindex=True)]
|
operations = [migrations.AlterIndexes(ModelWithIndex2, reindex=True)]
|
||||||
|
|
|
@ -1,75 +1,75 @@
|
||||||
import unittest
|
import unittest
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
||||||
from clickhouse_orm.database import Database
|
from clickhouse_orm.database import Database
|
||||||
from clickhouse_orm.models import Model, NO_VALUE
|
from clickhouse_orm.engines import *
|
||||||
from clickhouse_orm.fields import *
|
from clickhouse_orm.fields import *
|
||||||
from clickhouse_orm.engines import *
|
from clickhouse_orm.funcs import F
|
||||||
from clickhouse_orm.funcs import F
|
from clickhouse_orm.models import NO_VALUE, Model
|
||||||
|
|
||||||
|
|
||||||
class AliasFieldsTest(unittest.TestCase):
|
class AliasFieldsTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.database = Database("test-db", log_statements=True)
|
self.database = Database("test-db", log_statements=True)
|
||||||
self.database.create_table(ModelWithAliasFields)
|
self.database.create_table(ModelWithAliasFields)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.database.drop_database()
|
self.database.drop_database()
|
||||||
|
|
||||||
def test_insert_and_select(self):
|
def test_insert_and_select(self):
|
||||||
instance = ModelWithAliasFields(date_field="2016-08-30", int_field=-10, str_field="TEST")
|
instance = ModelWithAliasFields(date_field="2016-08-30", int_field=-10, str_field="TEST")
|
||||||
self.database.insert([instance])
|
self.database.insert([instance])
|
||||||
# We can't select * from table, as it doesn't select materialized and alias fields
|
# We can't select * from table, as it doesn't select materialized and alias fields
|
||||||
query = (
|
query = (
|
||||||
"SELECT date_field, int_field, str_field, alias_int, alias_date, alias_str, alias_func"
|
"SELECT date_field, int_field, str_field, alias_int, alias_date, alias_str, alias_func"
|
||||||
" FROM $db.%s ORDER BY alias_date" % ModelWithAliasFields.table_name()
|
" FROM $db.%s ORDER BY alias_date" % ModelWithAliasFields.table_name()
|
||||||
)
|
)
|
||||||
for model_cls in (ModelWithAliasFields, None):
|
for model_cls in (ModelWithAliasFields, None):
|
||||||
results = list(self.database.select(query, model_cls))
|
results = list(self.database.select(query, model_cls))
|
||||||
self.assertEqual(len(results), 1)
|
self.assertEqual(len(results), 1)
|
||||||
self.assertEqual(results[0].date_field, instance.date_field)
|
self.assertEqual(results[0].date_field, instance.date_field)
|
||||||
self.assertEqual(results[0].int_field, instance.int_field)
|
self.assertEqual(results[0].int_field, instance.int_field)
|
||||||
self.assertEqual(results[0].str_field, instance.str_field)
|
self.assertEqual(results[0].str_field, instance.str_field)
|
||||||
self.assertEqual(results[0].alias_int, instance.int_field)
|
self.assertEqual(results[0].alias_int, instance.int_field)
|
||||||
self.assertEqual(results[0].alias_str, instance.str_field)
|
self.assertEqual(results[0].alias_str, instance.str_field)
|
||||||
self.assertEqual(results[0].alias_date, instance.date_field)
|
self.assertEqual(results[0].alias_date, instance.date_field)
|
||||||
self.assertEqual(results[0].alias_func, 201608)
|
self.assertEqual(results[0].alias_func, 201608)
|
||||||
|
|
||||||
def test_assignment_error(self):
|
def test_assignment_error(self):
|
||||||
# I can't prevent assigning at all, in case db.select statements with model provided sets model fields.
|
# I can't prevent assigning at all, in case db.select statements with model provided sets model fields.
|
||||||
instance = ModelWithAliasFields()
|
instance = ModelWithAliasFields()
|
||||||
for value in ("x", [date.today()], ["aaa"], [None]):
|
for value in ("x", [date.today()], ["aaa"], [None]):
|
||||||
with self.assertRaises(ValueError):
|
with self.assertRaises(ValueError):
|
||||||
instance.alias_date = value
|
instance.alias_date = value
|
||||||
|
|
||||||
def test_wrong_field(self):
|
def test_wrong_field(self):
|
||||||
with self.assertRaises(AssertionError):
|
with self.assertRaises(AssertionError):
|
||||||
StringField(alias=123)
|
StringField(alias=123)
|
||||||
|
|
||||||
def test_duplicate_default(self):
|
def test_duplicate_default(self):
|
||||||
with self.assertRaises(AssertionError):
|
with self.assertRaises(AssertionError):
|
||||||
StringField(alias="str_field", default="with default")
|
StringField(alias="str_field", default="with default")
|
||||||
|
|
||||||
with self.assertRaises(AssertionError):
|
with self.assertRaises(AssertionError):
|
||||||
StringField(alias="str_field", materialized="str_field")
|
StringField(alias="str_field", materialized="str_field")
|
||||||
|
|
||||||
def test_default_value(self):
|
def test_default_value(self):
|
||||||
instance = ModelWithAliasFields()
|
instance = ModelWithAliasFields()
|
||||||
self.assertEqual(instance.alias_str, NO_VALUE)
|
self.assertEqual(instance.alias_str, NO_VALUE)
|
||||||
# Check that NO_VALUE can be assigned to a field
|
# Check that NO_VALUE can be assigned to a field
|
||||||
instance.str_field = NO_VALUE
|
instance.str_field = NO_VALUE
|
||||||
# Check that NO_VALUE can be assigned when creating a new instance
|
# Check that NO_VALUE can be assigned when creating a new instance
|
||||||
instance2 = ModelWithAliasFields(**instance.to_dict())
|
instance2 = ModelWithAliasFields(**instance.to_dict())
|
||||||
|
|
||||||
|
|
||||||
class ModelWithAliasFields(Model):
|
class ModelWithAliasFields(Model):
|
||||||
int_field = Int32Field()
|
int_field = Int32Field()
|
||||||
date_field = DateField()
|
date_field = DateField()
|
||||||
str_field = StringField()
|
str_field = StringField()
|
||||||
|
|
||||||
alias_str = StringField(alias=u"str_field")
|
alias_str = StringField(alias=u"str_field")
|
||||||
alias_int = Int32Field(alias="int_field")
|
alias_int = Int32Field(alias="int_field")
|
||||||
alias_date = DateField(alias="date_field")
|
alias_date = DateField(alias="date_field")
|
||||||
alias_func = Int32Field(alias=F.toYYYYMM(date_field))
|
alias_func = Int32Field(alias=F.toYYYYMM(date_field))
|
||||||
|
|
||||||
engine = MergeTree("date_field", ("date_field",))
|
engine = MergeTree("date_field", ("date_field",))
|
||||||
|
|
|
@ -2,9 +2,9 @@ import unittest
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
||||||
from clickhouse_orm.database import Database
|
from clickhouse_orm.database import Database
|
||||||
from clickhouse_orm.models import Model
|
|
||||||
from clickhouse_orm.fields import *
|
|
||||||
from clickhouse_orm.engines import *
|
from clickhouse_orm.engines import *
|
||||||
|
from clickhouse_orm.fields import *
|
||||||
|
from clickhouse_orm.models import Model
|
||||||
|
|
||||||
|
|
||||||
class ArrayFieldsTest(unittest.TestCase):
|
class ArrayFieldsTest(unittest.TestCase):
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from clickhouse_orm.models import BufferModel
|
|
||||||
from clickhouse_orm.engines import *
|
from clickhouse_orm.engines import *
|
||||||
|
from clickhouse_orm.models import BufferModel
|
||||||
|
|
||||||
from .base_test_with_data import *
|
from .base_test_with_data import *
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import unittest
|
|
||||||
import datetime
|
import datetime
|
||||||
|
import unittest
|
||||||
|
|
||||||
import pytz
|
import pytz
|
||||||
|
|
||||||
from clickhouse_orm.database import Database
|
from clickhouse_orm.database import Database
|
||||||
from clickhouse_orm.models import Model, NO_VALUE
|
|
||||||
from clickhouse_orm.fields import *
|
|
||||||
from clickhouse_orm.engines import *
|
from clickhouse_orm.engines import *
|
||||||
|
from clickhouse_orm.fields import *
|
||||||
|
from clickhouse_orm.models import NO_VALUE, Model
|
||||||
from clickhouse_orm.utils import parse_tsv
|
from clickhouse_orm.utils import parse_tsv
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from clickhouse_orm import *
|
from clickhouse_orm import *
|
||||||
|
|
||||||
from .base_test_with_data import Person
|
from .base_test_with_data import Person
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from clickhouse_orm.database import Database
|
from clickhouse_orm.database import Database
|
||||||
|
from clickhouse_orm.engines import Memory
|
||||||
from clickhouse_orm.fields import Field, Int16Field
|
from clickhouse_orm.fields import Field, Int16Field
|
||||||
from clickhouse_orm.models import Model
|
from clickhouse_orm.models import Model
|
||||||
from clickhouse_orm.engines import Memory
|
|
||||||
|
|
||||||
|
|
||||||
class CustomFieldsTest(unittest.TestCase):
|
class CustomFieldsTest(unittest.TestCase):
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import unittest
|
|
||||||
import datetime
|
import datetime
|
||||||
|
import unittest
|
||||||
|
|
||||||
from clickhouse_orm.database import ServerError, DatabaseException
|
from clickhouse_orm.database import DatabaseException, ServerError
|
||||||
from clickhouse_orm.models import Model
|
|
||||||
from clickhouse_orm.engines import Memory
|
from clickhouse_orm.engines import Memory
|
||||||
from clickhouse_orm.fields import *
|
from clickhouse_orm.fields import *
|
||||||
from clickhouse_orm.funcs import F
|
from clickhouse_orm.funcs import F
|
||||||
|
from clickhouse_orm.models import Model
|
||||||
from clickhouse_orm.query import Q
|
from clickhouse_orm.query import Q
|
||||||
|
|
||||||
from .base_test_with_data import *
|
from .base_test_with_data import *
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import unittest
|
|
||||||
import datetime
|
import datetime
|
||||||
|
import unittest
|
||||||
|
|
||||||
import pytz
|
import pytz
|
||||||
|
|
||||||
from clickhouse_orm.database import Database
|
from clickhouse_orm.database import Database
|
||||||
from clickhouse_orm.models import Model
|
|
||||||
from clickhouse_orm.fields import *
|
|
||||||
from clickhouse_orm.engines import *
|
from clickhouse_orm.engines import *
|
||||||
|
from clickhouse_orm.fields import *
|
||||||
|
from clickhouse_orm.models import Model
|
||||||
|
|
||||||
|
|
||||||
class DateFieldsTest(unittest.TestCase):
|
class DateFieldsTest(unittest.TestCase):
|
||||||
|
|
|
@ -3,9 +3,9 @@ import unittest
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
from clickhouse_orm.database import Database, ServerError
|
from clickhouse_orm.database import Database, ServerError
|
||||||
from clickhouse_orm.models import Model
|
|
||||||
from clickhouse_orm.fields import *
|
|
||||||
from clickhouse_orm.engines import *
|
from clickhouse_orm.engines import *
|
||||||
|
from clickhouse_orm.fields import *
|
||||||
|
from clickhouse_orm.models import Model
|
||||||
|
|
||||||
|
|
||||||
class DecimalFieldsTest(unittest.TestCase):
|
class DecimalFieldsTest(unittest.TestCase):
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import unittest
|
|
||||||
import logging
|
import logging
|
||||||
|
import unittest
|
||||||
|
|
||||||
from clickhouse_orm import *
|
from clickhouse_orm import *
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
import unittest
|
|
||||||
import datetime
|
import datetime
|
||||||
|
import logging
|
||||||
|
import unittest
|
||||||
|
|
||||||
from clickhouse_orm import *
|
from clickhouse_orm import *
|
||||||
|
|
||||||
import logging
|
|
||||||
|
|
||||||
logging.getLogger("requests").setLevel(logging.WARNING)
|
logging.getLogger("requests").setLevel(logging.WARNING)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
import unittest
|
import unittest
|
||||||
|
from enum import Enum
|
||||||
|
|
||||||
from clickhouse_orm.database import Database
|
from clickhouse_orm.database import Database
|
||||||
from clickhouse_orm.models import Model
|
|
||||||
from clickhouse_orm.fields import *
|
|
||||||
from clickhouse_orm.engines import *
|
from clickhouse_orm.engines import *
|
||||||
|
from clickhouse_orm.fields import *
|
||||||
from enum import Enum
|
from clickhouse_orm.models import Model
|
||||||
|
|
||||||
|
|
||||||
class EnumFieldsTest(unittest.TestCase):
|
class EnumFieldsTest(unittest.TestCase):
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from clickhouse_orm.database import Database
|
from clickhouse_orm.database import Database
|
||||||
from clickhouse_orm.models import Model
|
|
||||||
from clickhouse_orm.fields import *
|
|
||||||
from clickhouse_orm.engines import *
|
from clickhouse_orm.engines import *
|
||||||
|
from clickhouse_orm.fields import *
|
||||||
|
from clickhouse_orm.models import Model
|
||||||
|
|
||||||
|
|
||||||
class FixedStringFieldsTest(unittest.TestCase):
|
class FixedStringFieldsTest(unittest.TestCase):
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
import unittest
|
|
||||||
from .base_test_with_data import *
|
|
||||||
from .test_querysets import SampleModel
|
|
||||||
from datetime import date, datetime, tzinfo, timedelta
|
|
||||||
import pytz
|
|
||||||
from ipaddress import IPv4Address, IPv6Address
|
|
||||||
import logging
|
import logging
|
||||||
|
import unittest
|
||||||
|
from datetime import date, datetime, timedelta, tzinfo
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
from ipaddress import IPv4Address, IPv6Address
|
||||||
|
|
||||||
|
import pytz
|
||||||
|
|
||||||
from clickhouse_orm.database import ServerError
|
from clickhouse_orm.database import ServerError
|
||||||
from clickhouse_orm.utils import NO_VALUE
|
|
||||||
from clickhouse_orm.funcs import F
|
from clickhouse_orm.funcs import F
|
||||||
|
from clickhouse_orm.utils import NO_VALUE
|
||||||
|
|
||||||
|
from .base_test_with_data import *
|
||||||
|
from .test_querysets import SampleModel
|
||||||
|
|
||||||
|
|
||||||
class FuncsTestCase(TestCaseWithData):
|
class FuncsTestCase(TestCaseWithData):
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import unittest
|
|
||||||
import datetime
|
import datetime
|
||||||
|
import unittest
|
||||||
|
|
||||||
import pytz
|
import pytz
|
||||||
|
|
||||||
from clickhouse_orm.database import Database
|
from clickhouse_orm.database import Database
|
||||||
from clickhouse_orm.models import Model
|
|
||||||
from clickhouse_orm.fields import *
|
|
||||||
from clickhouse_orm.engines import *
|
from clickhouse_orm.engines import *
|
||||||
|
from clickhouse_orm.fields import *
|
||||||
|
from clickhouse_orm.models import Model
|
||||||
|
|
||||||
|
|
||||||
class InheritanceTestCase(unittest.TestCase):
|
class InheritanceTestCase(unittest.TestCase):
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
import unittest
|
import unittest
|
||||||
from ipaddress import IPv4Address, IPv6Address
|
from ipaddress import IPv4Address, IPv6Address
|
||||||
|
|
||||||
from clickhouse_orm.database import Database
|
from clickhouse_orm.database import Database
|
||||||
|
from clickhouse_orm.engines import Memory
|
||||||
from clickhouse_orm.fields import Int16Field, IPv4Field, IPv6Field
|
from clickhouse_orm.fields import Int16Field, IPv4Field, IPv6Field
|
||||||
from clickhouse_orm.models import Model
|
from clickhouse_orm.models import Model
|
||||||
from clickhouse_orm.engines import Memory
|
|
||||||
|
|
||||||
|
|
||||||
class IPFieldsTest(unittest.TestCase):
|
class IPFieldsTest(unittest.TestCase):
|
||||||
|
|
|
@ -1,48 +1,48 @@
|
||||||
import unittest
|
import json
|
||||||
import json
|
import unittest
|
||||||
|
|
||||||
from clickhouse_orm import database, engines, fields, models
|
from clickhouse_orm import database, engines, fields, models
|
||||||
|
|
||||||
|
|
||||||
class JoinTest(unittest.TestCase):
|
class JoinTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.database = database.Database("test-db", log_statements=True)
|
self.database = database.Database("test-db", log_statements=True)
|
||||||
self.database.create_table(Foo)
|
self.database.create_table(Foo)
|
||||||
self.database.create_table(Bar)
|
self.database.create_table(Bar)
|
||||||
self.database.insert([Foo(id=i) for i in range(3)])
|
self.database.insert([Foo(id=i) for i in range(3)])
|
||||||
self.database.insert([Bar(id=i, b=i * i) for i in range(3)])
|
self.database.insert([Bar(id=i, b=i * i) for i in range(3)])
|
||||||
|
|
||||||
def print_res(self, query):
|
def print_res(self, query):
|
||||||
print(query)
|
print(query)
|
||||||
print(json.dumps([row.to_dict() for row in self.database.select(query)]))
|
print(json.dumps([row.to_dict() for row in self.database.select(query)]))
|
||||||
|
|
||||||
def test_without_db_name(self):
|
def test_without_db_name(self):
|
||||||
self.print_res("SELECT * FROM {}".format(Foo.table_name()))
|
self.print_res("SELECT * FROM {}".format(Foo.table_name()))
|
||||||
self.print_res("SELECT * FROM {}".format(Bar.table_name()))
|
self.print_res("SELECT * FROM {}".format(Bar.table_name()))
|
||||||
self.print_res("SELECT b FROM {} ALL LEFT JOIN {} USING id".format(Foo.table_name(), Bar.table_name()))
|
self.print_res("SELECT b FROM {} ALL LEFT JOIN {} USING id".format(Foo.table_name(), Bar.table_name()))
|
||||||
|
|
||||||
def test_with_db_name(self):
|
def test_with_db_name(self):
|
||||||
self.print_res("SELECT * FROM $db.{}".format(Foo.table_name()))
|
self.print_res("SELECT * FROM $db.{}".format(Foo.table_name()))
|
||||||
self.print_res("SELECT * FROM $db.{}".format(Bar.table_name()))
|
self.print_res("SELECT * FROM $db.{}".format(Bar.table_name()))
|
||||||
self.print_res("SELECT b FROM $db.{} ALL LEFT JOIN $db.{} USING id".format(Foo.table_name(), Bar.table_name()))
|
self.print_res("SELECT b FROM $db.{} ALL LEFT JOIN $db.{} USING id".format(Foo.table_name(), Bar.table_name()))
|
||||||
|
|
||||||
def test_with_subquery(self):
|
def test_with_subquery(self):
|
||||||
self.print_res(
|
self.print_res(
|
||||||
"SELECT b FROM {} ALL LEFT JOIN (SELECT * from {}) subquery USING id".format(
|
"SELECT b FROM {} ALL LEFT JOIN (SELECT * from {}) subquery USING id".format(
|
||||||
Foo.table_name(), Bar.table_name()
|
Foo.table_name(), Bar.table_name()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.print_res(
|
self.print_res(
|
||||||
"SELECT b FROM $db.{} ALL LEFT JOIN (SELECT * from $db.{}) subquery USING id".format(
|
"SELECT b FROM $db.{} ALL LEFT JOIN (SELECT * from $db.{}) subquery USING id".format(
|
||||||
Foo.table_name(), Bar.table_name()
|
Foo.table_name(), Bar.table_name()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class Foo(models.Model):
|
class Foo(models.Model):
|
||||||
id = fields.UInt8Field()
|
id = fields.UInt8Field()
|
||||||
engine = engines.Memory()
|
engine = engines.Memory()
|
||||||
|
|
||||||
|
|
||||||
class Bar(Foo):
|
class Bar(Foo):
|
||||||
b = fields.UInt8Field()
|
b = fields.UInt8Field()
|
||||||
|
|
|
@ -1,71 +1,71 @@
|
||||||
import unittest
|
import unittest
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
||||||
from clickhouse_orm.database import Database
|
from clickhouse_orm.database import Database
|
||||||
from clickhouse_orm.models import Model, NO_VALUE
|
from clickhouse_orm.engines import *
|
||||||
from clickhouse_orm.fields import *
|
from clickhouse_orm.fields import *
|
||||||
from clickhouse_orm.engines import *
|
from clickhouse_orm.funcs import F
|
||||||
from clickhouse_orm.funcs import F
|
from clickhouse_orm.models import NO_VALUE, Model
|
||||||
|
|
||||||
|
|
||||||
class MaterializedFieldsTest(unittest.TestCase):
|
class MaterializedFieldsTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.database = Database("test-db", log_statements=True)
|
self.database = Database("test-db", log_statements=True)
|
||||||
self.database.create_table(ModelWithMaterializedFields)
|
self.database.create_table(ModelWithMaterializedFields)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.database.drop_database()
|
self.database.drop_database()
|
||||||
|
|
||||||
def test_insert_and_select(self):
|
def test_insert_and_select(self):
|
||||||
instance = ModelWithMaterializedFields(date_time_field="2016-08-30 11:00:00", int_field=-10, str_field="TEST")
|
instance = ModelWithMaterializedFields(date_time_field="2016-08-30 11:00:00", int_field=-10, str_field="TEST")
|
||||||
self.database.insert([instance])
|
self.database.insert([instance])
|
||||||
# We can't select * from table, as it doesn't select materialized and alias fields
|
# We can't select * from table, as it doesn't select materialized and alias fields
|
||||||
query = (
|
query = (
|
||||||
"SELECT date_time_field, int_field, str_field, mat_int, mat_date, mat_str, mat_func"
|
"SELECT date_time_field, int_field, str_field, mat_int, mat_date, mat_str, mat_func"
|
||||||
" FROM $db.%s ORDER BY mat_date" % ModelWithMaterializedFields.table_name()
|
" FROM $db.%s ORDER BY mat_date" % ModelWithMaterializedFields.table_name()
|
||||||
)
|
)
|
||||||
for model_cls in (ModelWithMaterializedFields, None):
|
for model_cls in (ModelWithMaterializedFields, None):
|
||||||
results = list(self.database.select(query, model_cls))
|
results = list(self.database.select(query, model_cls))
|
||||||
self.assertEqual(len(results), 1)
|
self.assertEqual(len(results), 1)
|
||||||
self.assertEqual(results[0].date_time_field, instance.date_time_field)
|
self.assertEqual(results[0].date_time_field, instance.date_time_field)
|
||||||
self.assertEqual(results[0].int_field, instance.int_field)
|
self.assertEqual(results[0].int_field, instance.int_field)
|
||||||
self.assertEqual(results[0].str_field, instance.str_field)
|
self.assertEqual(results[0].str_field, instance.str_field)
|
||||||
self.assertEqual(results[0].mat_int, abs(instance.int_field))
|
self.assertEqual(results[0].mat_int, abs(instance.int_field))
|
||||||
self.assertEqual(results[0].mat_str, instance.str_field.lower())
|
self.assertEqual(results[0].mat_str, instance.str_field.lower())
|
||||||
self.assertEqual(results[0].mat_date, instance.date_time_field.date())
|
self.assertEqual(results[0].mat_date, instance.date_time_field.date())
|
||||||
self.assertEqual(results[0].mat_func, instance.str_field.lower())
|
self.assertEqual(results[0].mat_func, instance.str_field.lower())
|
||||||
|
|
||||||
def test_assignment_error(self):
|
def test_assignment_error(self):
|
||||||
# I can't prevent assigning at all, in case db.select statements with model provided sets model fields.
|
# I can't prevent assigning at all, in case db.select statements with model provided sets model fields.
|
||||||
instance = ModelWithMaterializedFields()
|
instance = ModelWithMaterializedFields()
|
||||||
for value in ("x", [date.today()], ["aaa"], [None]):
|
for value in ("x", [date.today()], ["aaa"], [None]):
|
||||||
with self.assertRaises(ValueError):
|
with self.assertRaises(ValueError):
|
||||||
instance.mat_date = value
|
instance.mat_date = value
|
||||||
|
|
||||||
def test_wrong_field(self):
|
def test_wrong_field(self):
|
||||||
with self.assertRaises(AssertionError):
|
with self.assertRaises(AssertionError):
|
||||||
StringField(materialized=123)
|
StringField(materialized=123)
|
||||||
|
|
||||||
def test_duplicate_default(self):
|
def test_duplicate_default(self):
|
||||||
with self.assertRaises(AssertionError):
|
with self.assertRaises(AssertionError):
|
||||||
StringField(materialized="str_field", default="with default")
|
StringField(materialized="str_field", default="with default")
|
||||||
|
|
||||||
with self.assertRaises(AssertionError):
|
with self.assertRaises(AssertionError):
|
||||||
StringField(materialized="str_field", alias="str_field")
|
StringField(materialized="str_field", alias="str_field")
|
||||||
|
|
||||||
def test_default_value(self):
|
def test_default_value(self):
|
||||||
instance = ModelWithMaterializedFields()
|
instance = ModelWithMaterializedFields()
|
||||||
self.assertEqual(instance.mat_str, NO_VALUE)
|
self.assertEqual(instance.mat_str, NO_VALUE)
|
||||||
|
|
||||||
|
|
||||||
class ModelWithMaterializedFields(Model):
|
class ModelWithMaterializedFields(Model):
|
||||||
int_field = Int32Field()
|
int_field = Int32Field()
|
||||||
date_time_field = DateTimeField()
|
date_time_field = DateTimeField()
|
||||||
str_field = StringField()
|
str_field = StringField()
|
||||||
|
|
||||||
mat_str = StringField(materialized="lower(str_field)")
|
mat_str = StringField(materialized="lower(str_field)")
|
||||||
mat_int = Int32Field(materialized="abs(int_field)")
|
mat_int = Int32Field(materialized="abs(int_field)")
|
||||||
mat_date = DateField(materialized=u"toDate(date_time_field)")
|
mat_date = DateField(materialized=u"toDate(date_time_field)")
|
||||||
mat_func = StringField(materialized=F.lower(str_field))
|
mat_func = StringField(materialized=F.lower(str_field))
|
||||||
|
|
||||||
engine = MergeTree("mat_date", ("mat_date",))
|
engine = MergeTree("mat_date", ("mat_date",))
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
import unittest
|
import os
|
||||||
|
|
||||||
from clickhouse_orm.database import Database, ServerError
|
|
||||||
from clickhouse_orm.models import Model, BufferModel, Constraint, Index
|
|
||||||
from clickhouse_orm.fields import *
|
|
||||||
from clickhouse_orm.engines import *
|
|
||||||
from clickhouse_orm.migrations import MigrationHistory
|
|
||||||
|
|
||||||
from enum import Enum
|
|
||||||
|
|
||||||
# Add tests to path so that migrations will be importable
|
# Add tests to path so that migrations will be importable
|
||||||
import sys, os
|
import sys
|
||||||
|
import unittest
|
||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
from clickhouse_orm.database import Database, ServerError
|
||||||
|
from clickhouse_orm.engines import *
|
||||||
|
from clickhouse_orm.fields import *
|
||||||
|
from clickhouse_orm.migrations import MigrationHistory
|
||||||
|
from clickhouse_orm.models import BufferModel, Constraint, Index, Model
|
||||||
|
|
||||||
sys.path.append(os.path.dirname(__file__))
|
sys.path.append(os.path.dirname(__file__))
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import unittest
|
|
||||||
import datetime
|
import datetime
|
||||||
|
import unittest
|
||||||
|
|
||||||
import pytz
|
import pytz
|
||||||
|
|
||||||
from clickhouse_orm.models import Model, NO_VALUE
|
|
||||||
from clickhouse_orm.fields import *
|
|
||||||
from clickhouse_orm.engines import *
|
from clickhouse_orm.engines import *
|
||||||
|
from clickhouse_orm.fields import *
|
||||||
from clickhouse_orm.funcs import F
|
from clickhouse_orm.funcs import F
|
||||||
|
from clickhouse_orm.models import NO_VALUE, Model
|
||||||
|
|
||||||
|
|
||||||
class ModelTestCase(unittest.TestCase):
|
class ModelTestCase(unittest.TestCase):
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
import unittest
|
import unittest
|
||||||
from clickhouse_orm import F
|
|
||||||
from .base_test_with_data import *
|
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
|
from clickhouse_orm import F
|
||||||
|
|
||||||
|
from .base_test_with_data import *
|
||||||
|
|
||||||
|
|
||||||
class MutationsTestCase(TestCaseWithData):
|
class MutationsTestCase(TestCaseWithData):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
import unittest
|
import unittest
|
||||||
|
from datetime import date, datetime
|
||||||
|
|
||||||
import pytz
|
import pytz
|
||||||
|
|
||||||
from clickhouse_orm.database import Database
|
from clickhouse_orm.database import Database
|
||||||
from clickhouse_orm.models import Model
|
|
||||||
from clickhouse_orm.fields import *
|
|
||||||
from clickhouse_orm.engines import *
|
from clickhouse_orm.engines import *
|
||||||
|
from clickhouse_orm.fields import *
|
||||||
|
from clickhouse_orm.models import Model
|
||||||
from clickhouse_orm.utils import comma_join
|
from clickhouse_orm.utils import comma_join
|
||||||
|
|
||||||
from datetime import date, datetime
|
|
||||||
|
|
||||||
|
|
||||||
class NullableFieldsTest(unittest.TestCase):
|
class NullableFieldsTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import unittest
|
import unittest
|
||||||
from clickhouse_orm.database import Database
|
|
||||||
from clickhouse_orm.query import Q
|
|
||||||
from clickhouse_orm.funcs import F
|
|
||||||
from .base_test_with_data import *
|
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from enum import Enum
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
from enum import Enum
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
|
||||||
|
from clickhouse_orm.database import Database
|
||||||
|
from clickhouse_orm.funcs import F
|
||||||
|
from clickhouse_orm.query import Q
|
||||||
|
|
||||||
|
from .base_test_with_data import *
|
||||||
|
|
||||||
logger = getLogger("tests")
|
logger = getLogger("tests")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from clickhouse_orm.database import DatabaseException, ServerError
|
from clickhouse_orm.database import DatabaseException, ServerError
|
||||||
|
|
||||||
from .base_test_with_data import *
|
from .base_test_with_data import *
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
import unittest
|
import unittest
|
||||||
from clickhouse_orm.fields import *
|
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
|
|
||||||
import pytz
|
import pytz
|
||||||
|
|
||||||
|
from clickhouse_orm.fields import *
|
||||||
|
|
||||||
|
|
||||||
class SimpleFieldsTest(unittest.TestCase):
|
class SimpleFieldsTest(unittest.TestCase):
|
||||||
|
|
||||||
|
|
|
@ -1,128 +1,127 @@
|
||||||
import unittest
|
import os
|
||||||
from datetime import date
|
import unittest
|
||||||
|
from datetime import date
|
||||||
import os
|
|
||||||
|
from clickhouse_orm.database import Database, DatabaseException
|
||||||
from clickhouse_orm.database import Database, DatabaseException
|
from clickhouse_orm.engines import *
|
||||||
from clickhouse_orm.engines import *
|
from clickhouse_orm.fields import *
|
||||||
from clickhouse_orm.fields import *
|
from clickhouse_orm.models import Model
|
||||||
from clickhouse_orm.models import Model
|
from clickhouse_orm.system_models import SystemPart
|
||||||
from clickhouse_orm.system_models import SystemPart
|
|
||||||
|
|
||||||
|
class SystemTest(unittest.TestCase):
|
||||||
class SystemTest(unittest.TestCase):
|
def setUp(self):
|
||||||
def setUp(self):
|
self.database = Database("test-db", log_statements=True)
|
||||||
self.database = Database("test-db", log_statements=True)
|
|
||||||
|
def tearDown(self):
|
||||||
def tearDown(self):
|
self.database.drop_database()
|
||||||
self.database.drop_database()
|
|
||||||
|
def test_insert_system(self):
|
||||||
def test_insert_system(self):
|
m = SystemPart()
|
||||||
m = SystemPart()
|
with self.assertRaises(DatabaseException):
|
||||||
with self.assertRaises(DatabaseException):
|
self.database.insert([m])
|
||||||
self.database.insert([m])
|
|
||||||
|
def test_create_readonly_table(self):
|
||||||
def test_create_readonly_table(self):
|
with self.assertRaises(DatabaseException):
|
||||||
with self.assertRaises(DatabaseException):
|
self.database.create_table(SystemTestModel)
|
||||||
self.database.create_table(SystemTestModel)
|
|
||||||
|
def test_drop_readonly_table(self):
|
||||||
def test_drop_readonly_table(self):
|
with self.assertRaises(DatabaseException):
|
||||||
with self.assertRaises(DatabaseException):
|
self.database.drop_table(SystemTestModel)
|
||||||
self.database.drop_table(SystemTestModel)
|
|
||||||
|
|
||||||
|
class SystemPartTest(unittest.TestCase):
|
||||||
class SystemPartTest(unittest.TestCase):
|
|
||||||
|
BACKUP_DIRS = ["/var/lib/clickhouse/shadow", "/opt/clickhouse/shadow/"]
|
||||||
BACKUP_DIRS = ["/var/lib/clickhouse/shadow", "/opt/clickhouse/shadow/"]
|
|
||||||
|
def setUp(self):
|
||||||
def setUp(self):
|
self.database = Database("test-db", log_statements=True)
|
||||||
self.database = Database("test-db", log_statements=True)
|
self.database.create_table(TestTable)
|
||||||
self.database.create_table(TestTable)
|
self.database.create_table(CustomPartitionedTable)
|
||||||
self.database.create_table(CustomPartitionedTable)
|
self.database.insert([TestTable(date_field=date.today())])
|
||||||
self.database.insert([TestTable(date_field=date.today())])
|
self.database.insert([CustomPartitionedTable(date_field=date.today(), group_field=13)])
|
||||||
self.database.insert([CustomPartitionedTable(date_field=date.today(), group_field=13)])
|
|
||||||
|
def tearDown(self):
|
||||||
def tearDown(self):
|
self.database.drop_database()
|
||||||
self.database.drop_database()
|
|
||||||
|
def _get_backups(self):
|
||||||
def _get_backups(self):
|
for dir in self.BACKUP_DIRS:
|
||||||
for dir in self.BACKUP_DIRS:
|
if os.path.exists(dir):
|
||||||
if os.path.exists(dir):
|
_, dirnames, _ = next(os.walk(dir))
|
||||||
_, dirnames, _ = next(os.walk(dir))
|
return dirnames
|
||||||
return dirnames
|
raise unittest.SkipTest("Cannot find backups dir")
|
||||||
raise unittest.SkipTest("Cannot find backups dir")
|
|
||||||
|
def test_is_read_only(self):
|
||||||
def test_is_read_only(self):
|
self.assertTrue(SystemPart.is_read_only())
|
||||||
self.assertTrue(SystemPart.is_read_only())
|
|
||||||
|
def test_is_system_model(self):
|
||||||
def test_is_system_model(self):
|
self.assertTrue(SystemPart.is_system_model())
|
||||||
self.assertTrue(SystemPart.is_system_model())
|
|
||||||
|
def test_get_all(self):
|
||||||
def test_get_all(self):
|
parts = SystemPart.get(self.database)
|
||||||
parts = SystemPart.get(self.database)
|
self.assertEqual(len(list(parts)), 2)
|
||||||
self.assertEqual(len(list(parts)), 2)
|
|
||||||
|
def test_get_active(self):
|
||||||
def test_get_active(self):
|
parts = list(SystemPart.get_active(self.database))
|
||||||
parts = list(SystemPart.get_active(self.database))
|
self.assertEqual(len(parts), 2)
|
||||||
self.assertEqual(len(parts), 2)
|
parts[0].detach()
|
||||||
parts[0].detach()
|
parts = list(SystemPart.get_active(self.database))
|
||||||
parts = list(SystemPart.get_active(self.database))
|
self.assertEqual(len(parts), 1)
|
||||||
self.assertEqual(len(parts), 1)
|
|
||||||
|
def test_get_conditions(self):
|
||||||
def test_get_conditions(self):
|
parts = list(SystemPart.get(self.database, conditions="table='testtable'"))
|
||||||
parts = list(SystemPart.get(self.database, conditions="table='testtable'"))
|
self.assertEqual(len(parts), 1)
|
||||||
self.assertEqual(len(parts), 1)
|
parts = list(SystemPart.get(self.database, conditions=u"table='custompartitionedtable'"))
|
||||||
parts = list(SystemPart.get(self.database, conditions=u"table='custompartitionedtable'"))
|
self.assertEqual(len(parts), 1)
|
||||||
self.assertEqual(len(parts), 1)
|
parts = list(SystemPart.get(self.database, conditions=u"table='invalidtable'"))
|
||||||
parts = list(SystemPart.get(self.database, conditions=u"table='invalidtable'"))
|
self.assertEqual(len(parts), 0)
|
||||||
self.assertEqual(len(parts), 0)
|
|
||||||
|
def test_attach_detach(self):
|
||||||
def test_attach_detach(self):
|
parts = list(SystemPart.get_active(self.database))
|
||||||
parts = list(SystemPart.get_active(self.database))
|
self.assertEqual(len(parts), 2)
|
||||||
self.assertEqual(len(parts), 2)
|
for p in parts:
|
||||||
for p in parts:
|
p.detach()
|
||||||
p.detach()
|
self.assertEqual(len(list(SystemPart.get_active(self.database))), 0)
|
||||||
self.assertEqual(len(list(SystemPart.get_active(self.database))), 0)
|
for p in parts:
|
||||||
for p in parts:
|
p.attach()
|
||||||
p.attach()
|
self.assertEqual(len(list(SystemPart.get_active(self.database))), 2)
|
||||||
self.assertEqual(len(list(SystemPart.get_active(self.database))), 2)
|
|
||||||
|
def test_drop(self):
|
||||||
def test_drop(self):
|
parts = list(SystemPart.get_active(self.database))
|
||||||
parts = list(SystemPart.get_active(self.database))
|
for p in parts:
|
||||||
for p in parts:
|
p.drop()
|
||||||
p.drop()
|
self.assertEqual(len(list(SystemPart.get_active(self.database))), 0)
|
||||||
self.assertEqual(len(list(SystemPart.get_active(self.database))), 0)
|
|
||||||
|
def test_freeze(self):
|
||||||
def test_freeze(self):
|
parts = list(SystemPart.get(self.database))
|
||||||
parts = list(SystemPart.get(self.database))
|
# There can be other backups in the folder
|
||||||
# There can be other backups in the folder
|
prev_backups = set(self._get_backups())
|
||||||
prev_backups = set(self._get_backups())
|
for p in parts:
|
||||||
for p in parts:
|
p.freeze()
|
||||||
p.freeze()
|
backups = set(self._get_backups())
|
||||||
backups = set(self._get_backups())
|
self.assertEqual(len(backups), len(prev_backups) + 2)
|
||||||
self.assertEqual(len(backups), len(prev_backups) + 2)
|
|
||||||
|
def test_fetch(self):
|
||||||
def test_fetch(self):
|
# TODO Not tested, as I have no replication set
|
||||||
# TODO Not tested, as I have no replication set
|
pass
|
||||||
pass
|
|
||||||
|
def test_query(self):
|
||||||
def test_query(self):
|
SystemPart.objects_in(self.database).count()
|
||||||
SystemPart.objects_in(self.database).count()
|
list(SystemPart.objects_in(self.database).filter(table="testtable"))
|
||||||
list(SystemPart.objects_in(self.database).filter(table="testtable"))
|
|
||||||
|
|
||||||
|
class TestTable(Model):
|
||||||
class TestTable(Model):
|
date_field = DateField()
|
||||||
date_field = DateField()
|
|
||||||
|
engine = MergeTree("date_field", ("date_field",))
|
||||||
engine = MergeTree("date_field", ("date_field",))
|
|
||||||
|
|
||||||
|
class CustomPartitionedTable(Model):
|
||||||
class CustomPartitionedTable(Model):
|
date_field = DateField()
|
||||||
date_field = DateField()
|
group_field = UInt32Field()
|
||||||
group_field = UInt32Field()
|
|
||||||
|
engine = MergeTree(order_by=("date_field", "group_field"), partition_key=("toYYYYMM(date_field)", "group_field"))
|
||||||
engine = MergeTree(order_by=("date_field", "group_field"), partition_key=("toYYYYMM(date_field)", "group_field"))
|
|
||||||
|
|
||||||
|
class SystemTestModel(Model):
|
||||||
class SystemTestModel(Model):
|
_system = True
|
||||||
_system = True
|
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
import unittest
|
import unittest
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
|
||||||
from clickhouse_orm.database import Database
|
from clickhouse_orm.database import Database
|
||||||
|
from clickhouse_orm.engines import Memory
|
||||||
from clickhouse_orm.fields import Int16Field, UUIDField
|
from clickhouse_orm.fields import Int16Field, UUIDField
|
||||||
from clickhouse_orm.models import Model
|
from clickhouse_orm.models import Model
|
||||||
from clickhouse_orm.engines import Memory
|
|
||||||
|
|
||||||
|
|
||||||
class UUIDFieldsTest(unittest.TestCase):
|
class UUIDFieldsTest(unittest.TestCase):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user