def test_transaction_connection_handling(self): patch = 'peewee.Database' db = SqliteDatabase(':memory:') with mock.patch(patch, wraps=db) as patched_db: with transaction(patched_db): patched_db.begin.assert_called_once_with() self.assertEqual(patched_db.commit.call_count, 0) self.assertEqual(patched_db.rollback.call_count, 0) patched_db.begin.assert_called_once_with() patched_db.commit.assert_called_once_with() self.assertEqual(patched_db.rollback.call_count, 0) with mock.patch(patch, wraps=db) as patched_db: def _test_patched(): patched_db.commit.side_effect = ValueError with transaction(patched_db): pass self.assertRaises(ValueError, _test_patched) patched_db.begin.assert_called_once_with() patched_db.commit.assert_called_once_with() patched_db.rollback.assert_called_once_with()
def _test_patched(): patched_db.commit.side_effect = ValueError with transaction(patched_db): pass
def do_will_succeed(): with transaction(test_db): u = User.create(username='******') Blog.create(title='b1', user=u)
def transaction(self, lock_type='deferred'): return transaction(self, lock_type)
def do_will_succeed(): with transaction(test_db): u = User.create(username="******") Blog.create(title="b1", user=u)