Ejemplo n.º 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.sqlalchemy._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)
Ejemplo n.º 2
0
 def test_app_bundle_overrides_others(self, db, hook: RegisterModelsHook):
     hook.run_hook(None,
                   [VendorOneBundle(),
                    VendorTwoBundle(),
                    MyAppBundle()])
     expected = get_app_models()
     assert hook.bundle.models == expected
     assert db.metadata.tables == _to_metadata_tables(expected)
Ejemplo n.º 3
0
    def test_type_check_materialized_view(self, db, hook: RegisterModelsHook):
        class MVT(db.Model):
            id = 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)
Ejemplo n.º 4
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
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
def hook():
    return RegisterModelsHook(unchained, SQLAlchemyBundle())
Ejemplo n.º 7
0
 def test_it_works_with_polymorphic(self, db, hook: RegisterModelsHook):
     hook.run_hook(None, [PolymorphicBundle()])
     expected = get_polymorphic_models()
     assert hook.bundle.models == expected
     assert db.metadata.tables == _to_metadata_tables(expected)
Ejemplo n.º 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.bundle.models == expected_ext_ext_one
     assert db.metadata.tables == _to_metadata_tables(expected_ext_ext_one)
Ejemplo n.º 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.bundle.models == expected_both
     assert db.metadata.tables == _to_metadata_tables(expected_both)
Ejemplo n.º 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.bundle.models == expected_two
     assert db.metadata.tables == _to_metadata_tables(expected_two)