def test_edit_all_fields(self): tenant = self.add_tenant() context = context_dao.create( Context(name='MyContext', tenant_uuid=tenant.uuid, label='My Context Label', type='outcall', user_ranges=[ContextNumbers(start='1000', end='1999')], group_ranges=[ContextNumbers(start='2000', end='2999')], queue_ranges=[ContextNumbers(start='3000', end='3999')], conference_room_ranges=[ ContextNumbers(start='4000', end='4999') ], incall_ranges=[ ContextNumbers(start='1000', end='4999', did_length='2') ], description='context description', enabled=False)) context = context_dao.get(context.id) context.name = 'OtherContext' context.label = 'Other Context Label' context.type = 'incall' context.user_ranges = [ContextNumbers(start='4000', end='4999')] context.group_ranges = [ContextNumbers(start='3000', end='3999')] context.queue_ranges = [ContextNumbers(start='2000', end='2999')] context.conference_room_ranges = [ ContextNumbers(start='1000', end='1999') ] context.incall_ranges = [ ContextNumbers(start='4000', end='6999', did_length='4') ] context.description = 'other context description' context.enabled = True context_dao.edit(context) row = self.session.query(Context).first() assert_that(context, equal_to(row)) assert_that( context, has_properties( id=is_not(none()), tenant_uuid=tenant.uuid, name='OtherContext', label='Other Context Label', type='incall', user_ranges=contains(has_properties(start='4000', end='4999')), group_ranges=contains(has_properties(start='3000', end='3999')), queue_ranges=contains(has_properties(start='2000', end='2999')), conference_room_ranges=contains( has_properties(start='1000', end='1999')), incall_ranges=contains( has_properties(start='4000', end='6999', did_length='4')), description='other context description', enabled=True))
def test_in_range_when_negative(self): context_numbers = ContextNumbers(context='toto', type='incall', start='1000', end='1999', did_length=0) assert_that(context_numbers.in_range('-1500'), equal_to(False))
def test_in_range_with_no_end_when_outside(self): context_numbers = ContextNumbers(context='toto', type='incall', start='1000', numberend='', did_length=0) assert_that(context_numbers.in_range('1001'), equal_to(False))
def test_in_range_with_no_end(self): context_numbers = ContextNumbers(context='toto', type='incall', start='1000', numberend='', did_length=0) assert_that(context_numbers.in_range('1000'))
def test_in_range(self): context_numbers = ContextNumbers(context='toto', type='incall', start='1000', end='1999', did_length=0) assert_that(context_numbers.in_range('1500'))
def create_objects(self, data, **kwargs): for key in [ 'user_ranges', 'group_ranges', 'queue_ranges', 'conference_room_ranges', 'incall_ranges', ]: if data.get(key): data[key] = [ContextNumbers(**d) for d in data[key]] return data
def set_context_internal(context, entity): Session.add( Context(name='default', displayname=context['display_name'], entity=entity, contexttype='internal', description='')) Session.add( ContextNumbers(context='default', type='user', numberbeg=context['number_start'], numberend=context['number_end']))
def _insert_contextnumbers(self, context_name): contextnumbers = ContextNumbers() contextnumbers.context = context_name contextnumbers.type = 'user' contextnumbers.numberbeg = '1000' contextnumbers.numberend = '1999' contextnumbers.didlength = 0 self.session.begin() self.session.add(contextnumbers) self.session.commit()
def test_edit_set_fields_to_null(self): tenant = self.add_tenant() context = context_dao.create( Context(name='MyContext', tenant_uuid=tenant.uuid, label='My Context Label', user_ranges=[ContextNumbers(start='1000', end='1999')], group_ranges=[ContextNumbers(start='2000', end='2999')], queue_ranges=[ContextNumbers(start='3000', end='3999')], conference_room_ranges=[ ContextNumbers(start='4000', end='4999') ], incall_ranges=[ContextNumbers(start='1000', end='4999')], description='context description')) context = context_dao.get(context.id) context.label = None context.user_ranges = [] context.group_ranges = [] context.queue_ranges = [] context.conference_room_ranges = [] context.incall_ranges = [] context.description = None context_dao.edit(context) row = self.session.query(Context).first() assert_that(context, equal_to(row)) assert_that( row, has_properties(label=none(), user_ranges=empty(), group_ranges=empty(), queue_ranges=empty(), conference_room_ranges=empty(), incall_ranges=empty(), description=none()))
def set_context_incall(context, entity): Session.add( Context(name='from-extern', displayname=context['display_name'], entity=entity, contexttype='incall', description='')) if context.get('number_start') and context.get('number_end'): Session.add( ContextNumbers(context='from-extern', type='incall', numberbeg=context['number_start'], numberend=context['number_end'], didlength=context['did_length']))
def add_context_number(self, **kwargs): kwargs.setdefault('type', 'user') context_number = ContextNumbers(**kwargs) self.add_me(context_number) return context_number