Commit e9314cf9 authored by Francois Blackburn's avatar Francois Blackburn

add trunk/endpoint relationship

parent 41efdb32
......@@ -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
......@@ -50,21 +50,24 @@ class TrunkFeatures(Base):
TrunkFeatures.protocol == 'sip',
TrunkFeatures.protocolid == UserSIP.id
)""",
foreign_keys=[protocolid])
foreign_keys=[protocolid],
backref=backref('trunk', uselist=False))
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))
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):
......
......@@ -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