Beispiel #1
0
def test_cannot_create_model_category_or_manufacturer_not_exists(mocker):
    create_data_at_api_mock = mocker.MagicMock(return_value=MODEL_NOT_CREATED)
    get_model_id_mock = mocker.MagicMock(return_value=-1)

    mocker.patch(
        'Controller.StockAPIController.StockAPIController.create_data_at_api',
        create_data_at_api_mock)
    mocker.patch(
        'Controller.StockAPIController.StockAPIController.get_model_id',
        get_model_id_mock)

    assert APIc.create_model('model_name', -1, 1) == -1
    assert APIc.create_model('model_name', 1, -1) == -1
    assert APIc.create_model('model_name', -1, -1) == -1
Beispiel #2
0
def test_created_model_not_exists(mocker):
    create_data_at_api_mock = mocker.MagicMock(return_value=CATEGORY_CREATED)
    get_model_id_mock = mocker.MagicMock(return_value=-1)

    mocker.patch(
        'Controller.StockAPIController.StockAPIController.create_data_at_api',
        create_data_at_api_mock)
    mocker.patch(
        'Controller.StockAPIController.StockAPIController.get_model_id',
        get_model_id_mock)

    assert APIc.create_model(CATEGORY_CREATED['payload']['name'], 1,
                             1) == CATEGORY_CREATED['payload']['id']
    assert APIc.create_model(CATEGORY_CREATED['payload']['name'].upper(), 1,
                             1) == CATEGORY_CREATED['payload']['id']
    assert APIc.create_model(CATEGORY_CREATED['payload']['name'].lower(), 1,
                             1) == CATEGORY_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()