def test_when_number_and_context_have_changed_and_new_number_context_do_not_exist_then_validation_passes( self, ): model = Voicemail(id=1, number='1000', context='context') self.dao.find_by.return_value = model model.number = '1001' model.context = 'default' self.validator.validate(model)
def _insert_voicemail(self, mailbox, context='default'): voicemail = Voicemail() voicemail.mailbox = mailbox voicemail.context = context self.add_me(voicemail) return voicemail.uniqueid
def test_when_number_and_context_have_changed_and_new_number_context_exist_then_validation_fails( self, ): old_model = Voicemail(id=1, number='1000', context='context') new_model = Voicemail(id=2, number='1001', context='context') self.dao.find_by.return_value = old_model assert_that( calling(self.validator.validate).with_args(new_model), raises(ResourceError))
def _insert_voicemail(self, mailbox, context='default'): voicemail = Voicemail() voicemail.mailbox = mailbox voicemail.context = context self.session.begin() self.session.add(voicemail) self.session.commit() return voicemail.uniqueid
def test_add(self): voicemail = Voicemail() voicemail.mailbox = "123" voicemail.context = "default" voicemail_dao.add(voicemail) self.assertTrue(voicemail.uniqueid > 0) returned_voicemail = (self.session.query(Voicemail).filter(Voicemail.uniqueid == voicemail.uniqueid) .first()) self.assertEquals(returned_voicemail, voicemail) contextmember = (self.session.query(ContextMember).filter(ContextMember.type == 'voicemail') .filter(ContextMember.typeval == str(voicemail.uniqueid)) .first()) self.assertEquals(contextmember.context, voicemail.context)
def test_given_voicemail_with_all_parameters_when_generating_then_generates_one_entry(self): generator = VoicemailGenerator([ Voicemail(name='myvoicemail', number='1000', context='default', password='******', email='*****@*****.**', pager='*****@*****.**', language='fr_FR', timezone='eu-fr', attach_audio=True, delete_messages=True, max_messages=5, ask_password=True, options=[ ["volgain", "0.5"], ["saycid", "yes"] ]), ]) expected = textwrap.dedent( """\ [default] 1000 => 1234,myvoicemail,[email protected],[email protected],language=fr_FR|tz=eu-fr|attach=yes|deletevoicemail=yes|maxmsg=5|volgain=0.5|saycid=yes """) output = generator.generate() assert_that(output, equal_to(expected))
def test_when_number_and_context_exist_then_validation_fails(self): model = Voicemail(number='1000', context='context') self.dao.find_by.return_value = model assert_that( calling(self.validator.validate).with_args(model), raises(ResourceError))
def test_create_with_all_fields(self): voicemail = Voicemail( name='myVoicemail', number='1000', context='from-extern', password='******', email='*****@*****.**', pager='12345', timezone='timezone', language='english', options=[['toto', 'tata']], max_messages=999, attach_audio=False, delete_messages=True, ask_password=False, enabled=False, ) created_voicemail = voicemail_dao.create(voicemail) row = self.session.query(Voicemail).first() assert_that( created_voicemail, all_of( equal_to(row), has_properties( id=is_not(none()), name='myVoicemail', fullname='myVoicemail', number='1000', mailbox='1000', context='from-extern', password='******', email='*****@*****.**', pager='12345', timezone='timezone', tz='timezone', language='english', options=[['toto', 'tata']], max_messages=999, maxmsg=999, attach_audio=False, attach=False, delete_messages=True, deletevoicemail=True, ask_password=False, skipcheckpass=True, enabled=False, commented=True, ) ) )
def test_given_two_voicemails_in_same_context_when_generating_then_generates_two_entries(self): generator = VoicemailGenerator([ Voicemail(name='myvoicemail', number='1000', context='default', options=[]), Voicemail(name='othervoicemail', number='1001', context='default', options=[]), ]) expected = textwrap.dedent( """\ [default] 1000 => ,myvoicemail,,,deletevoicemail=no 1001 => ,othervoicemail,,,deletevoicemail=no """) output = generator.generate() assert_that(output, equal_to(expected))
def test_given_voicemail_with_minimal_parameters_when_generating_then_generates_one_entry(self): generator = VoicemailGenerator([ Voicemail(name='myvoicemail', number='1000', context='default', options=[]), ]) expected = textwrap.dedent( """\ [default] 1000 => ,myvoicemail,,,deletevoicemail=no """) output = generator.generate() assert_that(output, equal_to(expected))
def test_given_voicemail_parameter_with_special_characters_when_generating_then_escapes_characters(self): generator = VoicemailGenerator([ Voicemail(name='myvoicemail', number='1000', context='default', options=[ ["emailbody", "howdy\thello\nworld\r|!"], ]), ]) expected = textwrap.dedent( """\ [default] 1000 => ,myvoicemail,,,deletevoicemail=no|emailbody=howdy\\thello\\nworld\\r! """) output = generator.generate() assert_that(output, equal_to(expected))
def test_edit_set_fields_to_null(self): voicemail = voicemail_dao.create( Voicemail( name='MyVoicemail', number='1000', context='default', password='******', email='*****@*****.**', pager='12345', timezone='timezone', language='english', max_messages=999, attach_audio=False, ) ) voicemail = voicemail_dao.get(voicemail.id) voicemail.password = None voicemail.email = None voicemail.pager = None voicemail.timezone = None voicemail.language = None voicemail.max_messages = None voicemail.attach_audio = None voicemail_dao.edit(voicemail) row = self.session.query(Voicemail).first() assert_that(voicemail, equal_to(row)) assert_that( row, has_properties( password=none(), email=none(), pager=none(), timezone=none(), language=none(), max_messages=none(), attach_audio=none(), ) )
def test_create_minimal_fields(self): voicemail = Voicemail(number='1000', context='default') created_voicemail = voicemail_dao.create(voicemail) row = self.session.query(Voicemail).first() assert_that( created_voicemail, all_of( equal_to(row), has_properties( id=is_not(none()), uniqueid=is_not(none()), name='', fullname='', number='1000', mailbox='1000', context='default', password=none(), email=none(), pager=none(), timezone=none(), tz=none(), language=none(), options=empty(), max_messages=none(), maxmsg=none(), attach_audio=none(), attach=none(), delete_messages=False, deletevoicemail=False, ask_password=True, skipcheckpass=False, enabled=True, commented=False), ) )
def _create_voicemail(channel, parameters): from xivo_dao.alchemy.voicemail import Voicemail as VoicemailSchema from xivo_dao.helpers.db_manager import DaoSession voicemail = VoicemailSchema() voicemail.fullname = parameters['name'] voicemail.mailbox = parameters['number'] voicemail.context = parameters['context'] if 'password' in parameters: voicemail.password = parameters['password'] if 'email' in parameters: voicemail.email = parameters['email'] if 'language' in parameters: voicemail.language = parameters['language'] if 'timezone' in parameters: voicemail.tz = parameters['timezone'] if 'max_messages' in parameters: voicemail.maxmsg = int(parameters['max_messages']) if 'attach_audio' in parameters: voicemail.attach = int(parameters['attach_audio']) if 'delete_messages' in parameters: voicemail.deletevoicemail = int(parameters['delete_messages']) if 'ask_password' in parameters: voicemail.skipcheckpass = int(not parameters['ask_password']) DaoSession.begin() DaoSession.add(voicemail) DaoSession.commit()
def create(self, fields, tenant_uuid): number = fields.get('number') context = fields.get('context') if number or context: form = self.schema(handle_error=False).load(fields) return self.service.create(Voicemail(**form), None)
def test_when_number_and_context_have_not_changed_then_validation_passes( self): model = Voicemail(id=1, number='1000', context='context') self.dao.find_by.return_value = model self.validator.validate(model)
def test_edit_all_fields(self): voicemail = voicemail_dao.create( Voicemail( name='MyVoicemail', number='1000', context='from-extern', password='******', email='*****@*****.**', pager='12345', timezone='timezone', language='english', options=[], max_messages=999, attach_audio=False, delete_messages=True, ask_password=False, enabled=False, ) ) voicemail = voicemail_dao.get(voicemail.id) voicemail.name = 'other_name' voicemail.number = '1001' voicemail.context = 'default' voicemail.password = '******' voicemail.email = '*****@*****.**' voicemail.pager = '6789' voicemail.timezone = 'other_timezone' voicemail.language = 'french' voicemail.options = [['option1', 'toto']] voicemail.max_messages = 8888 voicemail.attach_audio = True voicemail.delete_messages = False voicemail.ask_password = True voicemail.enabled = True row = self.session.query(Voicemail).first() assert_that(voicemail, equal_to(row)) assert_that( row, has_properties( id=is_not(none()), name='other_name', fullname='other_name', number='1001', mailbox='1001', context='default', password='******', email='*****@*****.**', pager='6789', timezone='other_timezone', tz='other_timezone', language='french', options=[['option1', 'toto']], max_messages=8888, maxmsg=8888, attach_audio=True, attach=True, delete_messages=False, deletevoicemail=False, ask_password=True, skipcheckpass=False, enabled=True, commented=False, ) )
def test_when_number_and_context_do_not_exist_then_validation_passes(self): model = Voicemail(number='1000', context='context') self.dao.find_by.return_value = None self.validator.validate(model)