Changeset 3406

Show
Ignore:
Timestamp:
08/16/07 16:01:16 (1 year ago)
Author:
paj
Message:

Merge recent SQLAlchemy work into 1.1 branch

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/turbogears/database.py

    r3382 r3406  
    341341def sa_rwt(func, *args, **kw): 
    342342    log.debug("New SA transaction") 
    343     del session.context.current 
    344343    req = cherrypy.request 
    345344    req.sa_transaction = session.create_transaction() 
  • branches/1.1/turbogears/tests/test_sqlalchemy.py

    r3367 r3406  
    121121    assert "SQLError" in output 
    122122    assert cherrypy.response.code == 501 
     123 
     124 
     125#-- 
     126# Check for session freshness, ticket #1419 
     127# It checks that changes made to the data in thread B are reflected in thread A. 
     128#-- 
     129fresh_md = MetaData() 
     130test_table = Table("test", fresh_md, 
     131    Column("id", Integer, primary_key=True), 
     132    Column("val", String(40)) 
     133    ) 
     134class Test(object): 
     135    pass 
     136mapper(Test, test_table) 
     137 
     138class FreshRoot(RootController): 
     139    def test1(self): 
     140        assert session.query(Test).get(1).val == 'a' 
     141        return dict() 
     142    test1 = expose()(test1) 
     143    def test2(self): 
     144        session.query(Test).get(1).val = 'b' 
     145        return dict() 
     146    test2 = expose()(test2)         
     147    def test3(self): 
     148        assert session.query(Test).get(1).val == 'b' 
     149        return dict() 
     150    test3 = expose()(test3) 
     151 
     152def test_session_freshness(): 
     153    if os.path.exists('freshtest.db'): 
     154        os.unlink('freshtest.db') 
     155    fresh_md.bind = 'sqlite:///freshtest.db' # :memory: can't be used in multiple threads 
     156    test_table.create() 
     157    fresh_md.engine.execute(test_table.insert(), dict(id=1, val='a')) 
     158 
     159    cherrypy.root = FreshRoot() 
     160 
     161    create_request("/test1") 
     162 
     163    # Call test2 in a different thread 
     164    class ThreadB(threading.Thread): 
     165        def run(self): 
     166            create_request("/test2") 
     167    thrdb = ThreadB() 
     168    thrdb.start() 
     169    thrdb.join() 
     170     
     171    create_request("/test3") 
     172 
     173    assert 'AssertionError' not in cherrypy.response.body[0]