Example #1
0
 def begin(self, unloading=False):
     """Begin loading data
     
     - creates and stores a connection with engine.connect() if an engine was passed
       
       - binds the connection or engine to fixture's internal session
       
     - uses an unbound internal session if no engine or connection was passed in
     """
     if not unloading:
         # ...then we are loading, so let's *lazily* 
         # clean up after a previous setup/teardown
         Session.remove()
     if self.connection is None and self.engine is None:
         if self.session:
             self.engine = self.session.bind # might be None
     
     if self.engine is not None and self.connection is None:
         self.connection = self.engine.connect()
     
     if self.session is None:
         if self.connection:
             self.session = self.Session(bind=self.connection)
         else:
             self.session = self.Session(bind=None)
         
     DBLoadableFixture.begin(self, unloading=unloading)
Example #2
0
    def begin(self, unloading=False):
        """Begin loading data
        
        - creates and stores a connection with engine.connect() if an engine was passed
          
          - binds the connection or engine to fixture's internal session
          
        - uses an unbound internal session if no engine or connection was passed in
        """
        if not unloading:
            # ...then we are loading, so let's *lazily*
            # clean up after a previous setup/teardown
            Session.remove()
        if self.connection is None and self.engine is None:
            if self.session:
                self.engine = self.session.bind  # might be None

        if self.engine is not None and self.connection is None:
            self.connection = self.engine.connect()

        if self.session is None:
            if self.connection:
                self.session = self.Session(bind=self.connection)
            else:
                self.session = self.Session(bind=None)

        DBLoadableFixture.begin(self, unloading=unloading)
Example #3
0
 def __init__(self,
              connection=None,
              use_transaction=True,
              close_conn=False,
              **kw):
     DBLoadableFixture.__init__(self, **kw)
     self.connection = connection
     self.close_conn = close_conn
     self.use_transaction = use_transaction
Example #4
0
 def __init__(self,
              store=None,
              use_transaction=True,
              close_store=False,
              **kw):
     DBLoadableFixture.__init__(self, **kw)
     self.store = store
     self.close_store = close_store
     self.use_transaction = use_transaction
Example #5
0
 def __init__(self,
              session=None,
              scoped_session=None,
              connection=None,
              **kw):
     DBLoadableFixture.__init__(self, **kw)
     self.session = session
     self.scoped_session = scoped_session
     self.connection = connection
Example #6
0
 def commit(self):
     """Commit the load transaction and flush the session
     """
     if self.connection:
         # note that when not using a connection, calling session.commit() 
         # as the inheirted code does will automatically flush the session
         self.session.flush()
     
     log.debug("transaction.commit() <- %s", self.transaction)
     DBLoadableFixture.commit(self)
Example #7
0
    def commit(self):
        """Commit the load transaction and flush the session
        """
        if self.connection:
            # note that when not using a connection, calling session.commit()
            # as the inheirted code does will automatically flush the session
            self.session.flush()

        log.debug("transaction.commit() <- %s", self.transaction)
        DBLoadableFixture.commit(self)
Example #8
0
 def __init__(self, engine=None, connection=None, session=None, scoped_session=None, **kw):
     # ensure import error by simulating what would happen in the global module :
     from sqlalchemy.orm import sessionmaker, scoped_session as sa_scoped_session 
     
     DBLoadableFixture.__init__(self, **kw)
     self.engine = engine
     self.connection = connection
     self.session = session
     if scoped_session is None:
         scoped_session = Session
     self.Session = scoped_session
Example #9
0
    def __init__(self, engine=None, connection=None, session=None, scoped_session=None, **kw):
        # ensure import error by simulating what would happen in the global module :
        from sqlalchemy.orm import sessionmaker, scoped_session as sa_scoped_session

        DBLoadableFixture.__init__(self, **kw)
        self.engine = engine
        self.connection = connection
        self.session = session
        if scoped_session is None:
            scoped_session = Session
        self.Session = scoped_session
    def commit(self):
        """Commit the load transaction and flush the session
        """
        if self.connection:
            # note that when not using a connection, calling session.commit()
            # as the inheirted code does will automatically flush the session
            self.session.flush()
        # this is a hack because I can't get transaction.commit
        # to actually do anything for me...
        self.session.commit()

        log.debug("transaction.commit() <- %s", self.transaction)
        DBLoadableFixture.commit(self)
Example #11
0
    def begin(self, unloading=False):
        if self.session is None and self.scoped_session is None:
            raise UninitializedError(
                "%s must be assigned either a session or session_context" %
                (self.__class__.__name__))

        if self.scoped_session is not None:
            self.session = self.scoped_session()
        #if self.session is None:
        #    self.session = self.scoped_session()
        if not self.connection and self.session.bind is not None:
            self.connection = self.session.bind.connect()

        DBLoadableFixture.begin(self, unloading=unloading)
Example #12
0
 def commit(self):
     """Commit transaction"""
     if self.use_transaction:
         DBLoadableFixture.commit(self)
Example #13
0
 def commit(self):
     """Commit transaction"""
     if self.use_transaction:
         DBLoadableFixture.commit(self)
Example #14
0
 def __init__(self, **kw):
     if not kw.get('env', None):
         kw['env'] = DjangoEnv
     DBLoadableFixture.__init__(self, **kw)
Example #15
0
 def rollback(self):
     if self.use_transaction:
         DBLoadableFixture.rollback(self)
Example #16
0
 def commit(self):
     if self.use_transaction:
         DBLoadableFixture.commit(self)
Example #17
0
 def commit(self):
     self.session.flush()
     DBLoadableFixture.commit(self)
Example #18
0
 def rollback(self):
     """Rollback load transaction"""
     DBLoadableFixture.rollback(self)
Example #19
0
 def __init__(self, **kw):
     if not kw.get("env", None):
         kw["env"] = DjangoEnv
     DBLoadableFixture.__init__(self, **kw)
Example #20
0
 def __init__(self, **kw):
     if not kw.get('env', None):
         kw['env'] = DjangoEnv
     DBLoadableFixture.__init__(self, **kw)
Example #21
0
 def __init__(self,  store=None, use_transaction=True, 
                     close_store=False, **kw ):
     DBLoadableFixture.__init__(self, **kw)
     self.store = store
     self.close_store = close_store
     self.use_transaction = use_transaction
Example #22
0
 def __init__(self,  connection=None, use_transaction=True, 
                     close_conn=False, **kw ):
     DBLoadableFixture.__init__(self, **kw)
     self.connection = connection
     self.close_conn = close_conn
     self.use_transaction = use_transaction
Example #23
0
 def rollback(self):
     """Rollback the transaction"""
     if self.use_transaction:
         DBLoadableFixture.rollback(self)
Example #24
0
 def rollback(self):
     DBLoadableFixture.rollback(self)
Example #25
0
 def rollback(self):
     """Rollback load transaction"""
     DBLoadableFixture.rollback(self)
Example #26
0
 def rollback(self):
     """Rollback the transaction"""
     if self.use_transaction:
         DBLoadableFixture.rollback(self)