Commit 829b6cf3 authored by Francois Blackburn's avatar Francois Blackburn

line: fix queue_members

The field 'interface' are another duplicate field, like 'name' in
linefeatures. So we need to update this field too when fixing the line.
parent 6bc0ab70
......@@ -18,15 +18,16 @@
from sqlalchemy.orm import Load
from xivo_dao.alchemy.userfeatures import UserFeatures
from xivo_dao.alchemy.linefeatures import LineFeatures
from xivo_dao.alchemy.user_line import UserLine
from xivo_dao.alchemy.line_extension import LineExtension
from xivo_dao.alchemy.extension import Extension
from xivo_dao.alchemy.usersip import UserSIP
from xivo_dao.alchemy.sccpline import SCCPLine
from xivo_dao.alchemy.line_extension import LineExtension
from xivo_dao.alchemy.linefeatures import LineFeatures
from xivo_dao.alchemy.queuemember import QueueMember
from xivo_dao.alchemy.sccpdevice import SCCPDevice
from xivo_dao.alchemy.sccpline import SCCPLine
from xivo_dao.alchemy.user_line import UserLine
from xivo_dao.alchemy.usercustom import UserCustom
from xivo_dao.alchemy.userfeatures import UserFeatures
from xivo_dao.alchemy.usersip import UserSIP
class LineFixes(object):
......@@ -98,6 +99,9 @@ class LineFixes(object):
def update_usersip(self, row):
row.UserSIP.context = row.LineFeatures.context
if row.UserFeatures:
interface = 'SIP/{}'.format(row.UserSIP.name)
self.fix_queue_member(row.UserFeatures.id, interface)
def remove_endpoint(self, row):
row.LineFeatures.remove_endpoint()
......@@ -106,6 +110,9 @@ class LineFixes(object):
if row.SCCPLine:
self.fix_sccp_device(row)
self.fix_sccp_line(row)
if row.UserFeatures:
interface = 'SCCP/{}'.format(row.SCCPLine.name)
self.fix_queue_member(row.UserFeatures.id, interface)
else:
self.remove_endpoint(row)
......@@ -131,6 +138,8 @@ class LineFixes(object):
def fix_custom(self, row):
if row.UserCustom:
row.UserCustom.context = row.LineFeatures.context
if row.UserFeatures:
self.fix_queue_member(row.UserFeatures.id, row.UserCustom.interface)
else:
self.remove_endpoint(row)
......@@ -140,3 +149,9 @@ class LineFixes(object):
row.UserSIP.update_caller_id(row.UserFeatures, row.Extension)
elif row.LineFeatures.protocol == "sccp":
row.SCCPLine.update_caller_id(row.UserFeatures, row.Extension)
def fix_queue_member(self, user_id, interface):
(self.session.query(QueueMember)
.filter(QueueMember.usertype == 'user')
.filter(QueueMember.userid == user_id)
.update({'interface': interface}))
......@@ -21,10 +21,11 @@ from __future__ import unicode_literals
from hamcrest import assert_that, equal_to, none
from xivo_dao.alchemy.linefeatures import LineFeatures as Line
from xivo_dao.alchemy.usersip import UserSIP
from xivo_dao.alchemy.sccpline import SCCPLine
from xivo_dao.alchemy.queuemember import QueueMember
from xivo_dao.alchemy.sccpdevice import SCCPDevice
from xivo_dao.alchemy.sccpline import SCCPLine
from xivo_dao.alchemy.usercustom import UserCustom
from xivo_dao.alchemy.usersip import UserSIP
from xivo_dao.resources.line.fixes import LineFixes
from xivo_dao.tests.test_dao import DAOTestCase
......@@ -270,6 +271,45 @@ class TestLineFixes(DAOTestCase):
assert_that(custom.context, equal_to('default'))
assert_that(line.name, equal_to('custom/abcdef'))
def test_given_line_has_sip_name_then_queue_member_interface_updated(self):
sip = self.add_usersip(name='abcdef')
line = self.add_line(protocol='sip', protocolid=sip.id)
user = self.add_user()
self.add_user_line(user_id=user.id, line_id=line.id)
self.add_queue_member(usertype='user', userid=user.id, interface='SIP/default')
self.fixes.fix(line.id)
queue_member = self.session.query(QueueMember).first()
assert_that(queue_member.interface, equal_to('SIP/abcdef'))
def test_given_line_has_sccp_name_then_queue_member_interface_updated(self):
sccp = self.add_sccpline(name='abcdef')
line = self.add_line(protocol='sccp', protocolid=sccp.id)
user = self.add_user()
self.add_user_line(user_id=user.id, line_id=line.id)
self.add_queue_member(usertype='user', userid=user.id, interface='SCCP/default')
self.fixes.fix(line.id)
queue_member = self.session.query(QueueMember).first()
assert_that(queue_member.interface, equal_to('SCCP/abcdef'))
def test_given_line_has_custom_interface_then_queue_member_interface_updated(self):
custom = self.add_usercustom(interface='custom/abcdef')
line = self.add_line(protocol='custom', protocolid=custom.id)
user = self.add_user()
self.add_user_line(user_id=user.id, line_id=line.id)
self.add_queue_member(usertype='user', userid=user.id, interface='custom/invalid')
self.fixes.fix(line.id)
queue_member = self.session.query(QueueMember).first()
assert_that(queue_member.interface, equal_to('custom/abcdef'))
def test_given_custom_protocol_is_no_longer_assocaited_then_protocol_removed(self):
line = self.add_line(protocol='custom', protocolid=1234)
......
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