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.
54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
import unittest
|
|
import datetime
|
|
import pytz
|
|
|
|
from datastore_orm.database import Database
|
|
from datastore_orm.models import Model
|
|
from datastore_orm.fields import *
|
|
from datastore_orm.engines import *
|
|
|
|
|
|
class InheritanceTestCase(unittest.TestCase):
|
|
|
|
def assertFieldNames(self, model_class, names):
|
|
self.assertEqual(names, list(model_class.fields()))
|
|
|
|
def test_field_inheritance(self):
|
|
self.assertFieldNames(ParentModel, ['date_field', 'int_field'])
|
|
self.assertFieldNames(Model1, ['date_field', 'int_field', 'string_field'])
|
|
self.assertFieldNames(Model2, ['date_field', 'int_field', 'float_field'])
|
|
|
|
def test_create_table_sql(self):
|
|
default_db = Database('default')
|
|
sql1 = ParentModel.create_table_sql(default_db)
|
|
sql2 = Model1.create_table_sql(default_db)
|
|
sql3 = Model2.create_table_sql(default_db)
|
|
self.assertNotEqual(sql1, sql2)
|
|
self.assertNotEqual(sql1, sql3)
|
|
self.assertNotEqual(sql2, sql3)
|
|
|
|
def test_get_field(self):
|
|
self.assertIsNotNone(ParentModel().get_field('date_field'))
|
|
self.assertIsNone(ParentModel().get_field('string_field'))
|
|
self.assertIsNotNone(Model1().get_field('date_field'))
|
|
self.assertIsNotNone(Model1().get_field('string_field'))
|
|
self.assertIsNone(Model1().get_field('float_field'))
|
|
|
|
|
|
class ParentModel(Model):
|
|
|
|
date_field = DateField()
|
|
int_field = Int32Field()
|
|
|
|
engine = MergeTree('date_field', ('int_field', 'date_field'))
|
|
|
|
|
|
class Model1(ParentModel):
|
|
|
|
string_field = StringField()
|
|
|
|
|
|
class Model2(ParentModel):
|
|
|
|
float_field = Float32Field()
|