def test_dict_to_model(self): data = {'extension_id': EXTENSION_ID} expected = LineExtension(line_id=LINE_ID, extension_id=EXTENSION_ID) result = self.formatter.dict_to_model(LINE_ID, data) assert_that(result, equal_to(expected))
def test_build_line_for_device_with_a_sip_line_with_proxy_backup( self, config_manager, find_by_line_id, extension_dao_get): username = '******' secret = 'password' exten = '1250' context = 'default' display_name = 'Francis Dagobert' callerid = '"%s" <%s>' % (display_name, exten) proxy_ip = '10.39.5.1' registrar_ip = proxy_ip proxy_backup = '10.39.5.2' configregistrar = 'default' line = LineSIP(id=1, device_slot=1, context=context, username=username, name=username, secret=secret, callerid=callerid, configregistrar=configregistrar) device = Device(id=self.device_id) provd_base_config = {"raw_config": {}} config_registrar_dict = self._give_me_a_provd_configregistrar( proxy_ip, proxy_backup) config_manager().get.side_effect = (provd_base_config, config_registrar_dict) find_by_line_id.return_value = LineExtension(line_id=line.id, extension_id=3) extension_dao_get.return_value = Extension(exten=exten, context=context) expected_arg = { "raw_config": { "sip_lines": { "1": { 'username': username, 'auth_username': username, 'display_name': display_name, 'number': exten, 'password': secret, 'proxy_ip': proxy_ip, 'registrar_ip': registrar_ip, 'backup_registrar_ip': proxy_backup, 'backup_proxy_ip': proxy_backup } } } } device_services.build_line_for_device(device, line) config_manager().get.assert_any_call(self.device_id) config_manager().get.assert_any_call(configregistrar) config_manager().update.assert_called_with(expected_arg)
def test_dissociate_one_association_without_user(self): user_line_row = self.add_user_line_without_user() line_extension = LineExtension(line_id=user_line_row.line_id, extension_id=user_line_row.extension_id) dao.dissociate(line_extension) self.assert_user_line_deleted(user_line_row)
def test_dissociate_multiple_users(self): main_ule = self.add_user_line_with_exten() secondary_ule = self.prepare_secondary_user_associated(main_ule) line_extension = LineExtension(line_id=secondary_ule.line_id, extension_id=secondary_ule.extension_id) dao.dissociate(line_extension) self.assert_no_extensions_associated(main_ule) self.assert_no_extensions_associated(secondary_ule)
def test_dict_to_model(self): line_id = 1 extension_id = 2 data = {'extension_id': extension_id} expected = LineExtension(line_id=line_id, extension_id=extension_id) formatter = LineExtensionFormatter() result = formatter.dict_to_model(data, line_id) assert_that(result, equal_to(expected))
def test_associate_main_user(self): ule_row = self.add_user_line_without_exten() extension_row = self.add_extension() line_extension = LineExtension(line_id=ule_row.line_id, extension_id=extension_row.id) result = dao.associate(line_extension) self.assert_line_extension_has_ids(result, ule_row.line_id, ule_row.extension_id) self.assert_extension_is_associated(ule_row.line_id, extension_row.id)
def test_associate_no_user(self): line_row = self.add_line() extension_row = self.add_extension() line_extension = LineExtension(line_id=line_row.id, extension_id=extension_row.id) result = dao.associate(line_extension) self.assert_line_extension_has_ids(result, line_row.id, extension_row.id) self.assert_extension_is_associated(line_row.id, extension_row.id)
def test_given_2_incalls_on_same_user_then_returns_two_items(self): user_line_row = self.add_user_line_with_exten(exten='1000', context='default') extension_row = self.add_extension(exten='1000', context='from-extern') second_extension_row = self.add_extension(exten='1001', context='from-extern') self.create_incall_row_for_user(user_line_row.user_id, extension_row.id) self.create_incall_row_for_user(user_line_row.user_id, second_extension_row.id) first_line_extension = LineExtension(line_id=user_line_row.line_id, extension_id=extension_row.id) second_line_extension = LineExtension( line_id=user_line_row.line_id, extension_id=second_extension_row.id) result = dao.find_all_line_extensions_by_line_id(user_line_row.line_id) assert_that(result, has_items(first_line_extension, second_line_extension))
def test_given_incall_associated_to_user_with_line_then_returns_item(self): user_line_row = self.add_user_line_with_exten(exten='1000', context='default') extension_row = self.add_extension(exten='1000', context='from-extern') self.create_incall_row_for_user(user_line_row.user_id, extension_row.id) line_extension = LineExtension(line_id=user_line_row.line_id, extension_id=extension_row.id) result = dao.find_line_extension_by_extension_id( line_extension.extension_id) assert_that(result, equal_to(line_extension))
def test_given_line_with_multiple_users_then_returns_one_item(self): user_line_row = self.add_user_line_with_exten(exten='1000', context='default') extension_row = self.add_extension(exten='1000', context='from-extern') self.create_incall_row_for_user(user_line_row.user_id, extension_row.id) line_extension = LineExtension(line_id=user_line_row.line_id, extension_id=extension_row.id) self.add_secondary_user(line_extension) result = dao.find_all_line_extensions_by_line_id( line_extension.line_id) assert_that(result, contains(line_extension))
def test_associate_main_and_secondary_user(self): main_ule = self.add_user_line_without_exten() secondary_user = self.add_user() secondary_ule = self.associate_secondary_user(main_ule, secondary_user) extension_row = self.add_extension() line_extension = LineExtension(line_id=main_ule.line_id, extension_id=extension_row.id) result = dao.associate(line_extension) self.assert_line_extension_has_ids(result, main_ule.line_id, extension_row.id) self.assert_extension_is_associated(main_ule.line_id, extension_row.id) self.assert_extension_is_associated(secondary_ule.line_id, extension_row.id)
def test_build_line_for_device_with_a_sccp_line_with_proxy_backup( self, config_manager, find_by_line_id): exten = '1250' context = 'default' callerid = 'Francis Dagobert <%s>' % exten proxy_ip = '10.39.5.1' proxy_backup = '10.39.5.2' configregistrar = 'default' line = LineSCCP(id=1, device_slot=1, context=context, callerid=callerid, configregistrar=configregistrar) device = Device(id=self.device_id) provd_base_config = {"raw_config": {}} config_registrar_dict = self._give_me_a_provd_configregistrar( proxy_ip, proxy_backup) config_manager().get.side_effect = (provd_base_config, config_registrar_dict) find_by_line_id.return_value = LineExtension(line_id=line.id, extension_id=3) expected_arg = { "raw_config": { "sccp_call_managers": { 1: { 'ip': proxy_ip }, 2: { 'ip': proxy_backup } } } } device_services.build_line_for_device(device, line) config_manager().get.assert_any_call(self.device_id) config_manager().get.assert_any_call(configregistrar) config_manager().update.assert_called_with(expected_arg)
def test_given_2_lines_then_returns_one_item_with_right_line_id(self): first_user_line_row = self.add_user_line_with_exten(exten='1000', context='default') second_user_line_row = self.add_user_line_with_exten(exten='1001', context='default') first_extension_row = self.add_extension(exten='1000', context='from-extern') second_extension_row = self.add_extension(exten='1001', context='from-extern') self.create_incall_row_for_user(first_user_line_row.user_id, first_extension_row.id) self.create_incall_row_for_user(second_user_line_row.user_id, second_extension_row.id) line_extension = LineExtension(line_id=first_user_line_row.line_id, extension_id=first_extension_row.id) result = dao.find_all_line_extensions_by_line_id( first_user_line_row.line_id) assert_that(result, contains(line_extension))
def setUp(self): super(TestLineExtensionActions, self).setUp() self.line_extension = LineExtension(line_id=1, extension_id=2)
def row_to_line_extension(self, row): return LineExtension(line_id=row.line_id, extension_id=row.extension_id)
def model_from_ids(self, line_id, extension_id): return LineExtension(line_id=line_id, extension_id=extension_id)
def test_validate_model_no_parameters(self): line_extension = LineExtension() self.assertRaises(MissingParametersError, validator.validate_model, line_extension)
def test_model_from_ids(self): expected = LineExtension(line_id=LINE_ID, extension_id=EXTENSION_ID) result = self.formatter.model_from_ids(LINE_ID, EXTENSION_ID) assert_that(result, equal_to(expected))