Did I find the right examples for you? yes no

All Samples(12)  |  Call(12)  |  Derive(0)  |  Import(0)

src/m/o/mortar_rdb-2.0/mortar_rdb/tests/test_utility.py   mortar_rdb(Download)
    def test_how_to_create(self):
        register_session('sqlite://', transactional=False)
        # at this stage we have no tables
        session = get_session()
        session.add(self.Model(name='foo'))
        self.Base.metadata.create_all(session.bind)
        # now we can commit:
        session.add(self.Model(name='foo'))
        session.commit()
        # ...and get stuff back:
        # this is what you'd do in views:
        session = get_session()
        session.add(self.Model(id=1,name='foo'))
        model1 = session.query(self.Model).one()
        self.assertEqual(model1.id,1)
        self.assertEqual(model1.name,'foo')
 
        # or with a name...
        session = get_session('foo')
        session.add(self.Model(id=1,name='foo'))
        session = getSiteManager().getUtility(ISession)
 
        session.add(self.Model(id=1,name='foo'))
        model = session.query(self.Model).one()
        self.assertEqual(model.id,1)