def _add_extension(exten, context, meetmeid): extension = Extension() extension.exten = exten extension.context = context extension.typeval = meetmeid extension.type = 'meetme' return extension
def test_create(self): exten = Extension() exten.type = 'user' exten.exten = '2000' exten.context = 'default' extensions_dao.create(exten) self.assertTrue(exten.id) self.assertTrue(exten in self._get_all()) self.assertEquals(exten.name, exten.typeval)
def add_extension(self, **kwargs): kwargs.setdefault('exten', '%s' % self._generate_random_exten()) kwargs.setdefault('type', 'user') kwargs.setdefault('context', 'default') extension = Extension(**kwargs) self.add_me(extension) return extension
def add_extension(self, **kwargs): kwargs.setdefault('type', 'user') kwargs.setdefault('context', 'default') kwargs.setdefault('id', self._generate_int()) extension = Extension(**kwargs) self.add_me(extension) return extension
def create(self, fields, tenant_uuid): exten = fields.get('exten') context = fields.get('context') if exten and context: form = self.schema(handle_error=False).load(fields) tenant_uuids = [tenant_uuid] if tenant_uuid is not None else None return self.service.create(Extension(**form), tenant_uuids=tenant_uuids)
def test_create_all_parameters(self): extension = Extension(exten='1000', context='default', commented=1) created_extension = extension_dao.create(extension) row = self.session.query(Extension).filter( Extension.id == created_extension.id).first() assert_that(row.id, equal_to(created_extension.id)) assert_that(row.exten, equal_to('1000')) assert_that(row.context, equal_to('default')) assert_that(row.commented, equal_to(1)) assert_that(row.type, equal_to('user')) assert_that(row.typeval, equal_to('0'))
def create(self, fields, tenant_uuid): exten = fields.get('exten') context = fields.get('context') if exten and context: exten_for_user = fields.get('firstname') if exten_for_user: line_protocol = fields.get('line_protocol') if not line_protocol: raise errors.missing('line_protocol') if line_protocol not in VALID_ENDPOINT_TYPES: raise errors.invalid_choice('line_protocol', VALID_ENDPOINT_TYPES) form = self.schema(handle_error=False).load(fields) tenant_uuids = [tenant_uuid] if tenant_uuid is not None else None return self.service.create(Extension(**form), tenant_uuids=tenant_uuids)
def test_create(self): exten = 'extension' context = 'toto' extension = Extension(exten=exten, context=context) created_extension = extension_dao.create(extension) row = self.session.query(Extension).filter( Extension.id == created_extension.id).first() assert_that(row.id, equal_to(created_extension.id)) assert_that(row.exten, equal_to(exten)) assert_that(row.context, equal_to(context)) assert_that(row.commented, equal_to(0)) assert_that(row.type, equal_to('user')) assert_that(row.typeval, equal_to('0'))
class FuncKeyDestService(Base): DESTINATION_TYPE_ID = 5 __tablename__ = 'func_key_dest_service' __table_args__ = ( PrimaryKeyConstraint('func_key_id', 'destination_type_id', 'extension_id'), ForeignKeyConstraint(['func_key_id', 'destination_type_id'], ['func_key.id', 'func_key.destination_type_id']), CheckConstraint( 'destination_type_id = {}'.format(DESTINATION_TYPE_ID)), ) func_key_id = Column(Integer) destination_type_id = Column( Integer, server_default="{}".format(DESTINATION_TYPE_ID)) extension_id = Column(Integer, ForeignKey('extensions.id')) type = 'service' func_key = relationship(FuncKey, cascade='all,delete-orphan', single_parent=True) extension = relationship(Extension) extension_typeval = association_proxy( 'extension', 'typeval', # Only to keep value persistent in the instance creator=lambda _typeval: Extension(type='extenfeatures', typeval=_typeval)) def to_tuple(self): return (('service', self.service), ) @hybrid_property def service(self): return self.extension_typeval @service.setter def service(self, value): self.extension_typeval = value
def create(self, fields): exten = fields.get('exten') context = fields.get('context') if exten and context: return self.service.create(Extension(**fields))
class FuncKeyDestForward(Base): DESTINATION_TYPE_ID = 6 __tablename__ = 'func_key_dest_forward' __table_args__ = ( PrimaryKeyConstraint('func_key_id', 'destination_type_id', 'extension_id'), ForeignKeyConstraint(['func_key_id', 'destination_type_id'], ['func_key.id', 'func_key.destination_type_id']), CheckConstraint( 'destination_type_id = {}'.format(DESTINATION_TYPE_ID)), ) func_key_id = Column(Integer) destination_type_id = Column( Integer, server_default="{}".format(DESTINATION_TYPE_ID)) extension_id = Column(Integer, ForeignKey('extensions.id')) number = Column(String(40)) type = 'forward' func_key = relationship(FuncKey, cascade='all,delete-orphan', single_parent=True) extension = relationship(Extension) extension_typeval = association_proxy( 'extension', 'typeval', # Only to keep value persistent in the instance creator=lambda _typeval: Extension(type='extenfeatures', typeval=_typeval)) def to_tuple(self): return ( ('exten', self.exten), ('forward', self.forward), ) @hybrid_property def exten(self): return self.number @exten.setter def exten(self, value): self.number = value @hybrid_property def forward(self): FORWARDS = { 'fwdbusy': 'busy', 'fwdrna': 'noanswer', 'fwdunc': 'unconditional' } return FORWARDS.get(self.extension_typeval, self.extension_typeval) @forward.expression def forward(cls): return cls.extension_typeval # only used to pass test @forward.setter def forward(self, value): TYPEVALS = { 'busy': 'fwdbusy', 'noanswer': 'fwdrna', 'unconditional': 'fwdunc' } self.extension_typeval = TYPEVALS.get(value, value)
class FuncKeyDestAgent(Base): DESTINATION_TYPE_ID = 11 __tablename__ = 'func_key_dest_agent' __table_args__ = ( PrimaryKeyConstraint('func_key_id', 'destination_type_id'), ForeignKeyConstraint(['func_key_id', 'destination_type_id'], ['func_key.id', 'func_key.destination_type_id']), UniqueConstraint('agent_id', 'extension_id'), CheckConstraint( 'destination_type_id = {}'.format(DESTINATION_TYPE_ID)), ) func_key_id = Column(Integer) destination_type_id = Column( Integer, server_default="{}".format(DESTINATION_TYPE_ID)) agent_id = Column(Integer, ForeignKey('agentfeatures.id'), nullable=False) extension_id = Column(Integer, ForeignKey('extensions.id'), nullable=False) type = 'agent' func_key = relationship(FuncKey, cascade='all,delete-orphan', single_parent=True) agent = relationship(AgentFeatures) extension = relationship(Extension, viewonly=True) extension_typeval = association_proxy( 'extension', 'typeval', # Only to keep value persistent in the instance creator=lambda _typeval: Extension(type='extenfeatures', typeval=_typeval)) def to_tuple(self): return ( ('action', self.action), ('agent_id', self.agent_id), ) @hybrid_property def action(self): ACTIONS = { 'agentstaticlogin': '******', 'agentstaticlogoff': 'logout', 'agentstaticlogtoggle': 'toggle' } return ACTIONS.get(self.extension_typeval, self.extension_typeval) @action.expression def action(cls): return cls.extension_typeval # only used to pass test @action.setter def action(self, value): TYPEVALS = { 'login': '******', 'logout': 'agentstaticlogoff', 'toggle': 'agentstaticlogtoggle' } self.extension_typeval = TYPEVALS.get(value, value)
def create(self, fields, tenant_uuid): fields = self.extract_extension_fields(fields) if fields: extension = Extension(**fields) return self.service.create(extension)
def test_is_not_pattern(self): extension = Extension(exten='1000') assert_that(extension.is_pattern(), equal_to(False))
def test_is_pattern(self): extension = Extension(exten='_XXXX') assert_that(extension.is_pattern(), equal_to(True))
def test_is_not_feature(self): extension = Extension(context='not-features') assert_that(extension.is_feature, equal_to(False))
def test_is_feature(self): extension = Extension(context='xivo-features') assert_that(extension.is_feature, equal_to(True))