mirror of
https://github.com/hanzoai/datastore-orm.git
synced 2026-09-30 21:40:30 +00:00
This is our fork, so it should read like it. `import datastore_orm` instead of `from infi.clickhouse_orm import ...`: `infi` was the original vendor's org namespace, and carrying someone else's org name through every import in the consuming codebase is not a fork, it is a vendored copy that never got renamed. The `infi` namespace package is gone entirely (src/infi/__init__.py with it), the distribution is `datastore-orm`, and the metadata points at Hanzo rather than at the upstream repo and author. NOT renamed, deliberately: the migration history tables are still `infi_clickhouse_orm_migrations`. That name is persisted state — 448 rows in production key off it — so changing it is a data migration, not a rename. Doing it carelessly reproduces the exact failure this fork just hit, where a package rename orphaned the history and silently blocked every migration.
45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
import unittest
|
|
|
|
from datastore_orm import *
|
|
from .base_test_with_data import Person
|
|
|
|
|
|
class ConstraintsTest(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
self.database = Database('test-db', log_statements=True)
|
|
if self.database.server_version < (19, 14, 3, 3):
|
|
raise unittest.SkipTest('ClickHouse version too old')
|
|
self.database.create_table(PersonWithConstraints)
|
|
|
|
def tearDown(self):
|
|
self.database.drop_database()
|
|
|
|
def test_insert_valid_values(self):
|
|
self.database.insert([
|
|
PersonWithConstraints(first_name="Mike", last_name="Caruzo", birthday="2000-01-01", height=1.66)
|
|
])
|
|
|
|
def test_insert_invalid_values(self):
|
|
with self.assertRaises(ServerError) as e:
|
|
self.database.insert([
|
|
PersonWithConstraints(first_name="Mike", last_name="Caruzo", birthday="2100-01-01", height=1.66)
|
|
])
|
|
self.assertEqual(e.code, 469)
|
|
self.assertTrue('Constraint `birthday_in_the_past`' in e.message)
|
|
|
|
with self.assertRaises(ServerError) as e:
|
|
self.database.insert([
|
|
PersonWithConstraints(first_name="Mike", last_name="Caruzo", birthday="1970-01-01", height=3)
|
|
])
|
|
self.assertEqual(e.code, 469)
|
|
self.assertTrue('Constraint `max_height`' in e.message)
|
|
|
|
|
|
class PersonWithConstraints(Person):
|
|
|
|
birthday_in_the_past = Constraint(Person.birthday <= F.today())
|
|
max_height = Constraint(Person.height <= 2.75)
|
|
|
|
|