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

    with mocker.patch(
            'Controller.StockAPIController.StockAPIController.get_data_from_api',
            mock):
        model_id = APIc.get_model_id('model_name')

        assert model_id == -1
コード例 #2
0
def test_get_model_id_by_model_name_single(mocker):
    mock = mocker.MagicMock(return_value=SINGLE_MODEL_ID_FOUND)

    with mocker.patch(
            'Controller.StockAPIController.StockAPIController.get_data_from_api',
            mock):
        model_id = APIc.get_model_id(SINGLE_MODEL_ID_FOUND['rows'][0]['name'])

        assert model_id == SINGLE_MODEL_ID_FOUND['rows'][0]['id']
コード例 #3
0
def test_get_model_id_by_model_name_duplicated(mocker):
    mock = mocker.MagicMock(return_value=MODEL_ID_DUPLICATED_FOUND)

    with mocker.patch(
            'Controller.StockAPIController.StockAPIController.get_data_from_api',
            mock):
        model_id = APIc.get_model_id(
            MODEL_ID_DUPLICATED_FOUND['rows'][2]['name'])

        assert model_id == MODEL_ID_DUPLICATED_FOUND['rows'][2]['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()