Example #1
0
def test_execute_report_fail(mocker):
    mocker.patch('connect.cli.plugins.report.helpers.get_report_inputs')
    mocker.patch('connect.cli.plugins.report.helpers.get_renderer')
    ep_mock = mocker.MagicMock()
    mocker.patch(
        'connect.cli.plugins.report.helpers.get_report_entrypoint',
        return_value=ep_mock,
    )
    ep_mock.side_effect = Exception('this is an error')
    mocked_handle_exc = mocker.patch(
        'connect.cli.plugins.report.helpers.handle_report_exception')
    config = Config()
    config.add_account(
        'VA-000',
        'Account 1',
        'ApiKey XXXX:YYYY',
    )
    config.activate('VA-000')

    execute_report(
        config,
        './tests/fixtures/reports/basic_report',
        'entrypoint',
        'out_file',
        None,
    )

    mocked_handle_exc.assert_called_once()
Example #2
0
def test_execute_report_v2(mocker):
    report_data = [('a', 'b', 'c')]
    param_inputs = {'param_id': 'param_value'}
    mocked_input = mocker.patch(
        'connect.cli.plugins.report.helpers.get_report_inputs',
        return_value=param_inputs,
    )
    ex_ctx_callback = mocker.MagicMock()
    renderer_mock = mocker.MagicMock()
    renderer_mock.type = 'pdf'
    renderer_mock.render.return_value = 'outfile.pdf'
    renderer_mock.set_extra_context = ex_ctx_callback
    mocker.patch(
        'connect.cli.plugins.report.helpers.get_renderer',
        return_value=renderer_mock,
    )
    ep_mock = mocker.MagicMock()
    mocker.patch(
        'connect.cli.plugins.report.helpers.get_report_entrypoint',
        return_value=ep_mock,
    )
    ep_mock.return_value = report_data
    config = Config()
    config.add_account(
        'PA-000',
        'Account 1',
        'ApiKey XXXX:YYYY',
    )
    config.activate('PA-000')

    execute_report(
        config,
        './tests/fixtures/reports/report_v2',
        'test_v2',
        'out_file',
        None,
    )

    assert mocked_input.mock_calls[0].args[0] == config
    assert isinstance(mocked_input.mock_calls[0].args[1], ConnectClient)
    assert mocked_input.mock_calls[0].args[2] == []

    assert renderer_mock.render.mock_calls[0].args[0] == report_data
    assert renderer_mock.render.mock_calls[0].args[1] == 'out_file'
    assert isinstance(ep_mock.mock_calls[0].args[0], ConnectClient)
    assert ep_mock.mock_calls[0].args[1] == param_inputs
    assert isinstance(ep_mock.mock_calls[0].args[2], Progress)
    assert ep_mock.mock_calls[0].args[3] == 'pdf'
    assert ep_mock.mock_calls[0].args[4] == ex_ctx_callback
def test_sync_general_sync(fs, get_general_env, mocked_responses, ccli):
    config = Config()
    config.load(fs.root_path)
    config.add_account(
        'VA-000',
        'Account 1',
        'ApiKey XXXX:YYYY',
        endpoint='https://localhost/public/v1',
    )
    config.activate('VA-000')
    config.store()
    assert os.path.isfile(f'{fs.root_path}/config.json') is True

    with open('./tests/fixtures/units_response.json') as units_response:
        mocked_responses.add(
            method='GET',
            url='https://localhost/public/v1/settings/units',
            json=json.load(units_response),
        )

        with open('./tests/fixtures/product_response.json') as prod_response:
            mocked_responses.add(
                method='PUT',
                url='https://localhost/public/v1/products/PRD-276-377-545',
                json=json.load(prod_response),
            )
            get_general_env.save(f'{fs.root_path}/test.xlsx')

            runner = CliRunner()
            result = runner.invoke(
                ccli,
                [
                    '-c',
                    fs.root_path,
                    'product',
                    'sync',
                    '--yes',
                    f'{fs.root_path}/test.xlsx',
                ],
            )

            assert result.exit_code == 0