コード例 #1
0
 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)
コード例 #2
0
    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)
コード例 #3
0
 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
コード例 #4
0
    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)
コード例 #5
0
def hook():
    store = Store()
    return RegisterModelsHook(unchained, store)
コード例 #6
0
 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)
コード例 #7
0
 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)
コード例 #8
0
 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)
コード例 #9
0
 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)
コード例 #10
0
 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)