def test_when_creating_a_template_with_name_then_row_has_name(self): template = FuncKeyTemplate(name='foobar', tenant_uuid=self.default_tenant.uuid) result = dao.create(template) template_row = self.session.query(FuncKeyTemplate).first() assert_that(template_row.name, equal_to(template.name)) assert_that(result.name, equal_to(template.name))
def test_when_template_has_two_func_keys_with_different_destination_then_validation_passes( self, ): template = FuncKeyTemplate( keys={ 1: FuncKey(destination=FuncKeyDestCustom(exten='1234')), 2: FuncKey(destination=FuncKeyDestService( service='enablednd')), }) self.validator.validate(template)
def test_given_func_key_mapping_when_validating_then_validates_each_func_key( self): first_funckey = Mock(FuncKey) second_funckey = Mock(FuncKey) template = FuncKeyTemplate(keys={1: first_funckey, 2: second_funckey}) self.validator.validate(template) self.funckey_validator.validate.assert_any_call(first_funckey) self.funckey_validator.validate.assert_any_call(second_funckey)
def test_when_template_has_two_func_keys_with_same_destination_then_raises_error( self, ): destination = FuncKeyDestCustom(exten='1234') template = FuncKeyTemplate( keys={ 1: FuncKey(destination=destination), 2: FuncKey(destination=destination), }) assert_that( calling(self.validator.validate).with_args(template), raises(ResourceError))
def test_when_creating_an_empty_template_then_template_row(self): template = FuncKeyTemplate(tenant_uuid=self.default_tenant.uuid) result = dao.create(template) template_row = self.session.query(FuncKeyTemplate).first() assert_that(template_row.name, none()) assert_that(result.name, none()) assert_that(result.id, equal_to(template_row.id)) assert_that(result.tenant_uuid, self.default_tenant.uuid) assert_that(result.keys, equal_to({}))
def test_given_func_key_mapping_when_validating_then_validates_each_func_key( self): first_funckey = Mock(FuncKey) second_funckey = Mock(FuncKey) template = FuncKeyTemplate(keys={1: first_funckey, 2: second_funckey}) self.validator.validate_with_tenant_uuids(template, self.tenant_uuids) self.funckey_validator.validate_with_tenant_uuids.assert_any_call( first_funckey, None) self.funckey_validator.validate_with_tenant_uuids.assert_any_call( second_funckey, None)
def setUp(self): self.validator = Mock() self.validator_bsfilter = Mock() self.template_dao = Mock() self.user_dao = Mock() self.user_dao.find_all_by.return_value = [] self.notifier = Mock() self.device_updater = Mock(DeviceUpdater) self.template = FuncKeyTemplate(id=sentinel.template_id, name=sentinel.name) self.service = TemplateService( self.template_dao, self.user_dao, self.validator, self.validator_bsfilter, self.notifier, self.device_updater, )
def test_when_validating_public_template_then_validation_passes(self): template = FuncKeyTemplate(private=False) self.validator.validate(template)
def test_when_validating_private_template_then_raises_error(self): template = FuncKeyTemplate(private=True) assert_that( calling(self.validator.validate).with_args(template), raises(ResourceError))
def test_when_template_has_a_single_func_key_then_validation_passes(self): funckey = FuncKey(destination=FuncKeyDestCustom(exten='1234')) template = FuncKeyTemplate(keys={1: funckey}) self.validator.validate(template)
def test_when_template_empty_then_validation_passes(self): template = FuncKeyTemplate() self.validator.validate(template)
def add_func_key_template(self, **kwargs): func_key_template = FuncKeyTemplate(**kwargs) self.add_me(func_key_template) return func_key_template
def add_func_key_template(self, **kwargs): kwargs.setdefault('tenant_uuid', self.default_tenant.uuid) func_key_template = FuncKeyTemplate(**kwargs) self.add_me(func_key_template) return func_key_template
def prepare_template(self, user): if not user.func_key_private_template_id: template = FuncKeyTemplate(tenant_uuid=user.tenant_uuid, private=True) user.func_key_template_private = template
def build_template_with_key(self, destination, position=1): return FuncKeyTemplate( tenant_uuid=self.default_tenant.uuid, keys={position: FuncKeyMapping(destination=destination)}, )