コード例 #1
0
def test_get_category_id_by_category_name_not_found(mocker):
    mock = mocker.MagicMock(return_value={'total': 0, 'rows': []})

    with mocker.patch(
            'Controller.StockAPIController.StockAPIController.get_data_from_api',
            mock):
        category_id = APIc.get_category_id('category_name')

        assert category_id == -1
コード例 #2
0
def test_get_category_id_by_category_name_duplicated(mocker):
    mock = mocker.MagicMock(return_value=CATEGORY_ID_FOUND_DUPLICATED)

    with mocker.patch(
            'Controller.StockAPIController.StockAPIController.get_data_from_api',
            mock):
        category_id = APIc.get_category_id(
            CATEGORY_ID_FOUND_DUPLICATED['rows'][2]['name'])

        assert category_id == CATEGORY_ID_FOUND_DUPLICATED['rows'][2]['id']
コード例 #3
0
def test_get_category_id_by_category_name_single(mocker):
    mock = mocker.MagicMock(return_value=SINGLE_CATEGORY_ID_FOUND)

    with mocker.patch(
            'Controller.StockAPIController.StockAPIController.get_data_from_api',
            mock):
        category_id = APIc.get_category_id(
            SINGLE_CATEGORY_ID_FOUND['rows'][0]['name'])

        assert category_id == SINGLE_CATEGORY_ID_FOUND['rows'][0]['id']
コード例 #4
0
    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()