def delete(session, line): session.begin() try: nb_row_affected = session.query(LineSchema).filter( LineSchema.id == line.id).delete() _delete_line(session, line) session.commit() except IntegrityError as e: session.rollback() raise ElementDeletionError('Line', 'line still has a link') except SQLAlchemyError, e: session.rollback() raise ElementDeletionError('Line', e)
def delete(session, user): session.begin() try: _delete_user(session, user.id) session.commit() except SQLAlchemyError as e: session.rollback() raise ElementDeletionError('User', e)
def test_delete_with_error(self, ine_dao_reset, device_dao_delete, device_notifier_deleted): device = Device(id=self.device_id, ip='10.0.0.1') device_dao_delete.side_effect = ElementDeletionError( 'Device', 'Not Exist') self.assertRaises(ElementDeletionError, device_services.delete, device) self.assertEquals(device_notifier_deleted.call_count, 0)
def delete_all(session): session.begin() session.query(CallLogSchema).delete() try: session.commit() except SQLAlchemyError as e: session.rollback() raise ElementDeletionError('CallLog', e)
def test_when_element_deletion_error_is_raised(self): expected_status_code = 400 expected_message = ["Error while deleting user: error message"] exception = ElementDeletionError('user', 'error message') response = make_error_response(exception) self.assertResponse(response, expected_status_code, expected_message)
def delete(session, voicemail): session.begin() try: _delete_voicemail(session, voicemail.id) _unlink_dialactions(session, voicemail.id) session.commit() except SQLAlchemyError as e: session.rollback() raise ElementDeletionError('voicemail', e)
def dissociate(session, user_line): session.begin() try: _dissasociate_user_line(session, user_line) ule_dao.delete_association_if_necessary(session) session.commit() except SQLAlchemyError as e: session.rollback() raise ElementDeletionError('UserLine', e)
def delete(session, extension): session.begin() try: session.query(ExtensionSchema).filter( ExtensionSchema.id == extension.id).delete() session.commit() except SQLAlchemyError, e: session.rollback() raise ElementDeletionError('Extension', e)
def _delete_provd_device(device): provd_device_manager = provd_connector.device_manager() try: provd_device_manager.remove(device.id) except HTTPError as e: if e.code == 404: raise ElementNotExistsError('Device', id=device.id) raise e except Exception as e: raise ElementDeletionError('Device', e)
def delete_from_list(session, call_log_ids): session.begin() for call_log_id in call_log_ids: (session.query(CallLogSchema).filter( CallLogSchema.id == call_log_id).delete()) try: session.commit() except SQLAlchemyError as e: session.rollback() raise ElementDeletionError('CallLog', e)
def test_delete_associated(self, device_validate, device_dao_delete, line_dao_reset_device, device_notifier_deleted): device = Device(id=self.device_id, ip='10.0.0.1') device_validate.side_effect = ElementDeletionError( 'Device', 'device is still linked') self.assertRaises(ElementDeletionError, device_services.delete, device) assert_that(device_dao_delete.call_count, equal_to(0)) assert_that(line_dao_reset_device.call_count, equal_to(0)) assert_that(device_notifier_deleted.call_count, equal_to(0))
def test_delete_raises_exception(self, sysconf_delete_voicemail, voicemail_dao_delete, voicemail_notifier_deleted, validate_delete): voicemail = Mock(Voicemail) voicemail_dao_delete.side_effect = ElementDeletionError('voicemail', '') self.assertRaises(ElementDeletionError, voicemail_services.delete, voicemail) validate_delete.assert_called_once_with(voicemail) self.assertEquals(voicemail_notifier_deleted.call_count, 0) self.assertEquals(sysconf_delete_voicemail.call_count, 0)
def validate_not_associated_to_line(user): user_lines = user_line_dao.find_all_by_user_id(user.id) if user_lines: raise ElementDeletionError('User', 'user still associated to a line')
def validate_not_associated_to_line(extension): line_extension = line_extension_dao.find_by_extension_id(extension.id) if line_extension: raise ElementDeletionError('Extension', 'extension still has a link')
def _check_if_voicemail_linked_on_delete(voicemail): if voicemail_dao.is_voicemail_linked(voicemail): raise ElementDeletionError('voicemail', 'Cannot delete a voicemail associated to a user')
def delete(session, line): session.begin() try: nb_row_affected = session.query(LineSchema).filter( LineSchema.id == line.id).delete() _delete_line(session, line) session.commit() except IntegrityError as e: session.rollback() raise ElementDeletionError('Line', 'line still has a link') except SQLAlchemyError, e: session.rollback() raise ElementDeletionError('Line', e) if nb_row_affected == 0: raise ElementDeletionError('Line', 'line_id %s not exist' % line.id) return nb_row_affected def _delete_line(session, line): protocolid = int(line.protocolid) protocol = line.protocol.lower() if protocol == 'sip': _delete_sip_line(session, protocolid) elif protocol == 'iax': _delete_iax_line(session, protocolid) elif protocol == 'sccp': _delete_sccp_line(session, protocolid) elif protocol == 'custom': _delete_custom_line(session, protocolid)
def _check_device_is_not_linked_to_line(device): linked_lines = line_dao.find_all_by_device_id(device.id) if linked_lines: raise ElementDeletionError('device', 'device is still linked to a line')
def validate_not_associated_to_voicemail(user): user_voicemail = user_voicemail_dao.find_by_user_id(user.id) if user_voicemail: raise ElementDeletionError('User', 'user still associated to a voicemail')