Changeset 83

Show
Ignore:
Timestamp:
03/31/08 14:55:37 (5 months ago)
Author:
njriley
Message:

partially resolve SQLAlchemy confusion; enable SQL echoing in test harness

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sucrose/trunk/python/api/sucrose.py

    r77 r83  
    3535 
    3636                return self.trays.filter_by(machine_tray_id=int(location)).first() 
    37                  
     37 
    3838        def vend(self, location, uin): 
    3939                transaction = self.session.begin() 
     
    4242                        if not user: 
    4343                                raise ValueError('no such user') 
    44                                  
     44 
    4545                        tray = self.tray_from_location(location) 
    4646                        if not tray: 
     
    5050                        if tray.quantity <= 0: 
    5151                                raise ValueError('no product in tray') 
    52                          
     52 
    5353                        # comparing Decimal with float will otherwise behave strangely 
    5454                        if tray.cur_price * 100 > int(user.balance * 100): 
    5555                                raise ValueError('not enough money') 
    56                          
     56 
    5757                        tray.quantity -= 1 
    5858                        tray.num_consumed += 1 
     
    6262                        if hasattr(self, 'pic'): 
    6363                                self.pic.vendItem(location) 
    64                         # XXX committing the session should commit the transaction? 
    65                         transaction.commit() 
    6664                        self.session.commit() 
    67                         self.session.close() 
    6865                except: 
    69                         self.session.close() 
     66                        self.session.rollback() 
    7067                        raise 
    7168 
  • sucrose/trunk/python/mysql/db.py

    r82 r83  
    4949mapper(Tray, _trays, properties={'item': relation(Item, uselist=False)}) 
    5050 
    51 _Session = sessionmaker(autoflush=True, twophase=True, transactional=True) 
     51_Session = sessionmaker(transactional=False, autoflush=False, twophase=True) 
    5252session = _Session() 
  • sucrose/trunk/python/tests/test_sucrose.py

    r72 r83  
    2121    from api.sucrose import Sucrose 
    2222    from mysql import db 
     23    # echo SQL statements as they are executed 
     24    db._acm.echo = True 
     25    db._sucrose.echo = True 
    2326    self = Sucrose(db, dbonly=True) 
    2427    from IPython.Shell import IPShellEmbed