def test_lazy_backrefs_throw_exception(self, hook: RegisterModelsHook): with pytest.raises(Exception) as e: hook.run_hook(None, [BackrefBundle]) error = 'Discovered a lazy-mapped backref `backrefs` on ' \ '`tests._bundles.backref.models.OneRelationship`. Currently ' \ 'this is unsupported; please use `db.relationship` with '\ 'the `back_populates` kwarg on both sides instead.' assert error in str(e)
def test_type_check_materialized_view(self, db, hook: RegisterModelsHook): class MVT(db.Model): name = db.Column(db.Integer, primary_key=True) class MV(db.MaterializedView): @classmethod def selectable(cls): return db.select([MVT.id]) assert hook.type_check(db.MaterializedView) is False assert hook.type_check(MV)
def test_type_check_on_garbage(self, hook: RegisterModelsHook): assert hook.type_check('foo') is False assert hook.type_check(42) is False assert hook.type_check(42.0) is False assert hook.type_check(None) is False assert hook.type_check(lambda x: x) is False assert hook.type_check(unchained) is False assert hook.type_check(VendorOneBundle) is False
def test_type_check_model(self, db, hook: RegisterModelsHook): class M(db.Model): pass assert hook.type_check(db.Model) is False assert hook.type_check(M)
def hook(): store = Store() return RegisterModelsHook(unchained, store)
def test_app_bundle_overrides_others(self, db, hook: RegisterModelsHook): hook.run_hook(None, [VendorOneBundle, VendorTwoBundle, MyAppBundle]) expected = get_app_models() assert hook.store.models == expected assert db.metadata.tables == _to_metadata_tables(expected)
def test_it_works_with_polymorphic(self, db, hook: RegisterModelsHook): hook.run_hook(None, [PolymorphicBundle]) expected = get_polymorphic_models() assert hook.store.models == expected assert db.metadata.tables == _to_metadata_tables(expected)
def test_vendor_bundle_subsubclassing(self, db, hook: RegisterModelsHook): hook.run_hook(None, [ExtExtVendorOneBundle]) expected_ext_ext_one = get_ext_ext_vendor_one_models() assert hook.store.models == expected_ext_ext_one assert db.metadata.tables == _to_metadata_tables(expected_ext_ext_one)
def test_it_works_vendor_one_and_two(self, db, hook: RegisterModelsHook): hook.run_hook(None, [VendorOneBundle, VendorTwoBundle]) expected_both = {**get_vendor_one_models(), **get_vendor_two_models()} assert hook.store.models == expected_both assert db.metadata.tables == _to_metadata_tables(expected_both)
def test_it_works_vendor_two(self, db, hook: RegisterModelsHook): hook.run_hook(None, [VendorTwoBundle]) expected_two = get_vendor_two_models() assert hook.store.models == expected_two assert db.metadata.tables == _to_metadata_tables(expected_two)