def test_cannot_create_category(mocker): mock = mocker.MagicMock(return_value=CATEGORY_NOT_CREATED) with mocker.patch( 'Controller.StockAPIController.StockAPIController.create_data_at_api', mock): category_id = APIc.create_category('category_name') assert category_id == -1
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()