Esempio n. 1
0
    def init_ptah(self, *args, **kw):
        self.registry.settings.update(self._settings)
        self.config.include('ptah')

        for pkg in self._includes: # pragma: no cover
            self.config.include(pkg)

        pkg = package_name(sys.modules[self.__class__.__module__])
        if pkg != 'ptah':
            packages = []
            parts = self.__class__.__module__.split('.')
            for l in range(len(parts)):
                pkg = '.'.join(parts[:l+1])
                if pkg == 'ptah' or pkg.startswith('ptah.') or \
                       pkg in self._includes:
                    continue # pragma: no cover
                try:
                    self.config.include(pkg)
                except: # pragma: no cover
                    pass

        self.config.scan(self.__class__.__module__)

        self.config.commit()
        self.config.autocommit = self._auto_commit

        self.config.ptah_init_settings()

        ptah.reset_session()

        if self._init_sqla:
            # create engine
            self.config.ptah_init_sql()

            # create sql tables
            Base = ptah.get_base()
            Base.metadata.create_all()
            transaction.commit()

        if self._trusted_manage:
            def trusted(*args):
                return True
            ptah.manage.set_access_manager(trusted)
Esempio n. 2
0
    def test_jsondict(self):
        import ptah
        ptah.reset_session()

        self.config.ptah_init_sql()

        class Test(ptah.get_base()):
            __tablename__ = 'test14'

            id = sqla.Column('id', sqla.Integer, primary_key=True)
            data = sqla.Column(ptah.JsonDictType())

        Session = ptah.get_session()
        ptah.get_base().metadata.create_all()
        transaction.commit()

        rec = Test()
        rec.data = {'test': 'val'}
        Session.add(rec)
        Session.flush()
        id = rec.id
        transaction.commit()

        rec = Session.query(Test).filter_by(id = id).one()
        self.assertEqual(rec.data, {'test': 'val'})

        rec.data['test2'] = 'val2'
        transaction.commit()

        rec = Session.query(Test).filter_by(id = id).one()
        self.assertEqual(rec.data,
                         {'test': 'val', 'test2': 'val2'})

        del rec.data['test']
        transaction.commit()

        rec = Session.query(Test).filter_by(id = id).one()
        self.assertEqual(rec.data, {'test2': 'val2'})