Commit 9d0e6e6d authored by Pascal Cadotte Michaud's avatar Pascal Cadotte Michaud

Merge remote-tracking branch 'origin/remove-incall-from-line-extension'

parents 21a61a34 045a84b7
......@@ -15,12 +15,6 @@
# 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 sqlalchemy import Integer, cast, and_
from xivo_dao.alchemy.dialaction import Dialaction
from xivo_dao.alchemy.extension import Extension
from xivo_dao.alchemy.incall import Incall
from xivo_dao.alchemy.user_line import UserLine
from xivo_dao.resources.incall.persistor import IncallPersistor
from xivo_dao.resources.incall.search import incall_search
......@@ -71,22 +65,3 @@ def edit(session, incall):
@daosession
def delete(session, incall):
IncallPersistor(session, incall_search).delete(incall)
@daosession
def find_line_extension_by_extension_id(session, extension_id):
query = (session.query(UserLine.line_id,
Extension.id.label('extension_id'))
.join(Dialaction,
and_(Dialaction.action == 'user',
cast(Dialaction.actionarg1, Integer) == UserLine.user_id,
UserLine.main_line == True)) # noqa
.join(Incall,
and_(Dialaction.category == 'incall',
cast(Dialaction.categoryval, Integer) == Incall.id))
.join(Extension,
and_(Incall.exten == Extension.exten,
Incall.context == Extension.context))
.filter(Extension.id == extension_id))
return query.first()
......@@ -31,7 +31,6 @@ from xivo_dao.alchemy.incall import Incall
from xivo_dao.alchemy.rightcallmember import RightCallMember
from xivo_dao.tests.test_dao import DAOTestCase
from xivo_dao.resources.incall import dao as incall_dao
from xivo_dao.resources.extension import dao as extension_dao
from xivo_dao.helpers.exception import NotFoundError, InputError
from xivo_dao.resources.utils.search import SearchResult
......@@ -392,43 +391,3 @@ class TestDelete(DAOTestCase):
extension = self.session.query(Extension).filter(Extension.id == extension.id).first()
assert_that(extension, has_properties(type='user', typeval='0'))
class TestFindLineExtensionByExtensionId(DAOTestCase):
def test_given_no_incalls_then_returns_nothing(self):
result = incall_dao.find_line_extension_by_extension_id(1)
assert_that(result, none())
def test_given_user_with_internal_extension_then_returns_nothing(self):
user_line = self.add_user_line_with_exten(exten='1000', context='default')
result = incall_dao.find_line_extension_by_extension_id(user_line.extension.id)
assert_that(result, none())
def test_given_incall_associated_to_user_with_line_then_returns_item(self):
user_line = self.add_user_line_with_exten(exten='1000', context='default')
extension = self.add_extension(exten='1000', context='from-extern')
incall = self.add_incall(destination=Dialaction(action='user', actionarg1=user_line.user_id))
extension_dao.associate_incall(incall, extension)
result = incall_dao.find_line_extension_by_extension_id(extension.id)
assert_that(result, has_properties(line_id=user_line.line_id,
extension_id=extension.id))
def test_given_2_incalls_on_same_user_then_returns_correct_item(self):
user_line = self.add_user_line_with_exten(exten='1000', context='default')
extension1 = self.add_extension(exten='1000', context='from-extern')
extension2 = self.add_extension(exten='1001', context='from-extern')
incall1 = self.add_incall(destination=Dialaction(action='user', actionarg1=user_line.user_id))
extension_dao.associate_incall(incall1, extension1)
incall2 = self.add_incall(destination=Dialaction(action='user', actionarg1=user_line.user_id))
extension_dao.associate_incall(incall2, extension2)
result = incall_dao.find_line_extension_by_extension_id(extension1.id)
assert_that(result, has_properties(line_id=user_line.line_id,
extension_id=extension1.id))
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