def test_created_hardware(mocker): mock = mocker.MagicMock(return_value=HARDWARE_CREATED) asset = Asset() asset.id = HARDWARE_CREATED['payload']['id'] asset.name = HARDWARE_CREATED['payload']['name'] asset.tag = HARDWARE_CREATED['payload']['asset_tag'] asset.model_id = HARDWARE_CREATED['payload']['model_id'] asset.serial_number = HARDWARE_CREATED['payload']['serial'] with mocker.patch( 'Controller.StockAPIController.StockAPIController.create_data_at_api', mock): asset_id = APIc.create_hardware(asset, 1) assert asset_id == HARDWARE_CREATED['payload']['id']
def __auto_add(self): for asset in self.assets_to_add: category_id = StockAPIController.get_category_id( asset.category_name) if category_id == -1: category_id = StockAPIController.create_category( asset.category_name) asset.category_id = category_id if category_id == -1: logging.error( 'Error. Cannot create category in auto-add process for asset: {}' .format(str(asset))) continue model_id = StockAPIController.get_model_id(asset.model_name) if model_id == -1: model_id = StockAPIController.create_model( asset.model_name, category_id) asset.model_id = model_id if model_id == -1: logging.error( 'Error. Cannot create model in auto-add process for asset: {}' .format(str(asset))) continue asset_id = StockAPIController.create_hardware(asset, 1) if asset_id == -1: logging.error( 'Error. Cannot create asset in auto-add process for asset: {}' .format(str(asset))) else: logging.info('Created asset with id: {}, asset: {}'.format( asset_id, str(asset))) self.main_view.btn_auto_add.config(state='disable') self.__refresh_assets()
def test_cannot_create_hardware_duplicated(mocker): response = { 'status': 'error', 'messages': { 'asset_tag': ['The asset tag must be unique.'] }, 'payload': None } mock = mocker.MagicMock(return_value=response) asset = Asset() asset.id = HARDWARE_CREATED['payload']['id'] asset.name = HARDWARE_CREATED['payload']['name'] asset.tag = HARDWARE_CREATED['payload']['asset_tag'] asset.model_id = HARDWARE_CREATED['payload']['model_id'] asset.serial_number = HARDWARE_CREATED['payload']['serial'] with mocker.patch( 'Controller.StockAPIController.StockAPIController.create_data_at_api', mock): asset_id = APIc.create_hardware(asset, -1) assert asset_id == -1