Commit 7577b21b authored by Pascal Cadotte Michaud's avatar Pascal Cadotte Michaud

Merge remote-tracking branch 'origin/add-trunk-endpoint-relations'

parents b75b5750 e9314cf9
......@@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.orm import relationship
from sqlalchemy.orm import relationship, backref
from sqlalchemy.schema import Column, PrimaryKeyConstraint, UniqueConstraint, Index
from sqlalchemy.types import Integer, Text, String
......@@ -45,26 +45,29 @@ class TrunkFeatures(Base):
description = Column(Text)
context = Column(String(39))
sip_endpoint = relationship(UserSIP,
endpoint_sip = relationship(UserSIP,
primaryjoin="""and_(
TrunkFeatures.protocol == 'sip',
TrunkFeatures.protocolid == UserSIP.id
)""",
foreign_keys=[protocolid])
foreign_keys=[protocolid],
backref=backref('trunk', uselist=False))
iax_endpoint = relationship(UserIAX,
endpoint_iax = relationship(UserIAX,
primaryjoin="""and_(
TrunkFeatures.protocol == 'iax',
TrunkFeatures.protocolid == UserIAX.id
)""",
foreign_keys=[protocolid])
foreign_keys=[protocolid],
backref=backref('trunk_rel', uselist=False))
custom_endpoint = relationship(UserCustom,
endpoint_custom = relationship(UserCustom,
primaryjoin="""and_(
TrunkFeatures.protocol == 'custom',
TrunkFeatures.protocolid == UserCustom.id
)""",
foreign_keys=[protocolid])
foreign_keys=[protocolid],
backref=backref('trunk', uselist=False))
@hybrid_property
def endpoint(self):
......
......@@ -49,6 +49,15 @@ class TestCustomEndpointDaoGet(TestCustomDao):
assert_that(custom.interface, equal_to(row.interface))
assert_that(custom.enabled, equal_to(True))
def test_trunk_relationship(self):
custom_row = self.add_usercustom()
trunk_row = self.add_trunk()
trunk_row.associate_endpoint(custom_row)
custom = dao.get(custom_row.id)
assert_that(custom, equal_to(custom_row))
assert_that(custom.trunk, equal_to(trunk_row))
class TestCustomEndpointDaoFindBy(TestCustomDao):
......
......@@ -29,8 +29,6 @@ from hamcrest import has_items
from hamcrest import has_property
from hamcrest import has_properties
from hamcrest import has_length
from hamcrest import all_of
from hamcrest import contains_string
from xivo_dao.alchemy.usersip import UserSIP as SIPEndpoint
from xivo_dao.alchemy.linefeatures import LineFeatures as Line
......@@ -195,6 +193,15 @@ class TestSipEndpointDaoGet(TestSipEndpointDAO):
sip = dao.get(row.id)
assert_that(sip.options, has_items(["language", "fr_FR"], ["foo", "bar"]))
def test_trunk_relationship(self):
sip_row = self.add_usersip()
trunk_row = self.add_trunk()
trunk_row.associate_endpoint(sip_row)
sip = dao.get(sip_row.id)
assert_that(sip, equal_to(sip_row))
assert_that(sip.trunk, equal_to(trunk_row))
class TestSipEndpointDaoSearch(DAOTestCase):
......@@ -537,6 +544,7 @@ class TestSipEndpointDaoEdit(DAOTestCase):
["spam", "neweggs"],
))
class TestSipEndpointDaoDelete(TestSipEndpointDAO):
def test_delete(self):
......
......@@ -39,9 +39,9 @@ class TrunkFixes(object):
UserSIP,
UserIAX,
UserCustom)
.outerjoin(TrunkFeatures.sip_endpoint)
.outerjoin(TrunkFeatures.iax_endpoint)
.outerjoin(TrunkFeatures.custom_endpoint)
.outerjoin(TrunkFeatures.endpoint_sip)
.outerjoin(TrunkFeatures.endpoint_iax)
.outerjoin(TrunkFeatures.endpoint_custom)
.options(
Load(TrunkFeatures).load_only("id", "context"),
Load(UserSIP).load_only("id", "category", "context"),
......
......@@ -66,6 +66,39 @@ class TestGet(DAOTestCase):
assert_that(trunk, equal_to(trunk_row))
def test_endpoint_sip_relationship(self):
sip_row = self.add_usersip()
trunk_row = self.add_trunk()
trunk_row.associate_endpoint(sip_row)
trunk = trunk_dao.get(trunk_row.id)
assert_that(trunk, equal_to(trunk_row))
assert_that(trunk.endpoint_sip, equal_to(sip_row))
assert_that(trunk.endpoint_iax, none())
assert_that(trunk.endpoint_custom, none())
def test_endpoint_iax_relationship(self):
iax_row = self.add_useriax()
trunk_row = self.add_trunk()
trunk_row.associate_endpoint(iax_row)
trunk = trunk_dao.get(trunk_row.id)
assert_that(trunk, equal_to(trunk_row))
assert_that(trunk.endpoint_sip, none())
assert_that(trunk.endpoint_iax, equal_to(iax_row))
assert_that(trunk.endpoint_custom, none())
def test_endpoint_custom_relationship(self):
custom_row = self.add_usercustom()
trunk_row = self.add_trunk()
trunk_row.associate_endpoint(custom_row)
trunk = trunk_dao.get(trunk_row.id)
assert_that(trunk, equal_to(trunk_row))
assert_that(trunk.endpoint_sip, none())
assert_that(trunk.endpoint_iax, none())
assert_that(trunk.endpoint_custom, equal_to(custom_row))
class TestFindBy(DAOTestCase):
......
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