Commit 160bf7f2 authored by Cedric Abunar's avatar Cedric Abunar

new unittest for rollback

parent 239c67bb
# -*- coding: UTF-8 -*-
# Copyright (C) 2013 Avencall
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from xivo_dao.alchemy.agentfeatures import AgentFeatures
from xivo_dao.tests.test_dao import DAOTestCase
from sqlalchemy.exc import IntegrityError
class TestSession(DAOTestCase):
tables = [AgentFeatures]
def setUp(self):
self.empty_tables()
def _insert_valid_agent(self):
agent = AgentFeatures()
agent.numgroup = 6
agent.number = '15'
agent.passwd = ''
agent.context = 'default'
agent.language = ''
self.session.add(agent)
def _insert_inalid_agent(self):
agent = AgentFeatures()
agent.numgroup = 6
agent.number = '15'
agent.passwd = ''
agent.context = 'default'
self.session.add(agent)
def test_commit(self):
self.session.begin()
try:
self._insert_valid_agent()
self.session.commit()
except IntegrityError:
self.session.rollback()
res = self.session.query(AgentFeatures).all()
self.assertEqual(len(res), 1)
def test_rollback(self):
self.session.begin()
try:
self._insert_valid_agent()
self._insert_inalid_agent()
self.session.commit()
except IntegrityError:
self.session.rollback()
res = self.session.query(AgentFeatures).all()
self.assertEqual(len(res), 0)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment