Example #1
0
    def test_db_method_with_transaction(self):
        with database.transaction(self._dbsession):
            self.fake_method()
            self.assertTrue(not self._dbsession.has_been_committed)

            # Even if `commit=True`, we don't commit inside a
            # transaction
            self.fake_method(commit=True)
            self.assertTrue(not self._dbsession.has_been_committed)

        self.assertTrue(self._dbsession.has_been_committed)
Example #2
0
    def test_transaction(self):
        self.assertTrue(not self._dbsession.has_been_committed)
        self.assertTrue(
            not getattr(self._dbsession,
                    'mozbase_transaction',
                    False))

        with database.transaction(self._dbsession):
            self.assertTrue(not self._dbsession.has_been_committed)
            self.assertTrue(getattr(
                self._dbsession,
                'mozbase_transaction'))

        self.assertTrue(self._dbsession.has_been_committed)
        self.assertTrue(
            not getattr(self._dbsession,
                    'mozbase_transaction',
                    False))
Example #3
0
    def setUp(self):
        self.engine = create_engine('sqlite:///:memory:', echo=False)
        mozfinance.data.model.Base.metadata.create_all(self.engine)

        Session = sessionmaker(bind=self.engine)
        self.dbsession = Session()

        cache_region = make_region().configure('dogpile.cache.memory')
        setattr(self.dbsession, 'cache', cache_region)


        a_date = datetime.date(year=2012, month=5, day=26)
        self.prestation = Prestation.Prestation(date=a_date)
        self.dbsession.add(self.prestation)
        self.dbsession.flush()

        self.biz = BusinessObject(
            package='mozfinance.data.model',
            dbsession=self.dbsession)

        with transaction(self.dbsession):
            for i in range(12):
                da_date = datetime.date(year=2012, month=i+1, day=1)
                self.biz.month.create(date=da_date)