Commit 346fff2b authored by Francois Blackburn's avatar Francois Blackburn

add outcall/trunk relationship (many-to-many)

parent 15e5c09f
......@@ -51,6 +51,10 @@ class Outcall(Base):
foreign_keys='DialPattern.typeid',
cascade='all, delete-orphan')
trunks = relationship('TrunkFeatures',
secondary='outcalltrunk',
back_populates='outcalls')
@hybrid_property
def internal_caller_id(self):
return self.internal == 1
......
......@@ -69,6 +69,10 @@ class TrunkFeatures(Base):
foreign_keys=[protocolid],
backref=backref('trunk', uselist=False))
outcalls = relationship('Outcall',
secondary='outcalltrunk',
back_populates='trunks')
@hybrid_property
def endpoint(self):
return self.protocol
......
......@@ -62,6 +62,20 @@ class TestGet(DAOTestCase):
assert_that(outcall, equal_to(outcall_row))
def test_trunks_relationship(self):
outcall_row = self.add_outcall()
trunk1_row = self.add_trunk()
trunk2_row = self.add_trunk()
trunk3_row = self.add_trunk()
self.add_outcall_trunk(outcall_id=outcall_row.id, trunk_id=trunk1_row.id, priority=0)
self.add_outcall_trunk(outcall_id=outcall_row.id, trunk_id=trunk2_row.id, priority=1)
self.add_outcall_trunk(outcall_id=outcall_row.id, trunk_id=trunk3_row.id, priority=2)
outcall = outcall_dao.get(outcall_row.id)
assert_that(outcall, equal_to(outcall_row))
assert_that(outcall.trunks, contains(trunk1_row, trunk2_row, trunk3_row))
class TestFindBy(DAOTestCase):
......
......@@ -19,6 +19,7 @@ from __future__ import unicode_literals
from hamcrest import (assert_that,
contains,
contains_inanyorder,
equal_to,
has_items,
has_properties,
......
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