Example #1
0
def header_status(results_id):
    url = logs_url.get_url(results_id)
    print("Results of  : " + results_id)
    print("Logs are available at " + url)
    if tools.is_user_interactive():
        time.sleep(1)
        webbrowser.open_new_tab(url)
Example #2
0
def cli(template, json_in, out_file, filter, report_type, name):
    """Generate builtin or custom Jinja reports based on test results data
    Example: neoload report --template builtin:transactions-csv
    See more templates, examples, filters with "neoload report"
    """

    rest_crud.set_current_command()
    if all(v is None for v in [template, json_in, out_file, filter]):
        print_extended_help()
        tools.system_exit({'code': 1, 'message': ''})
        return

    global gprint

    model = initialize_model(filter, template)

    logger = logging.getLogger()

    # if intent is to produce JSON directly to stdout, hide print statements
    if out_file is None: gprint = lambda msg: logger.info(msg)

    gprint("Export started: {}".format(datetime.now()))

    json_data = parse_source_data_spec(json_in, model, report_type, name)

    json_data['cli'] = {
        'arguments': {
            'template': template,
            'json_in': json_in,
            'out_file': out_file,
            'filter': filter,
            'report_type': report_type,
            'name': name
        },
        'debug': logging.getLogger().level == logging.DEBUG,
        'internals': {
            'version': tools.compute_version()
        }
    }

    final_output = process_final_output(template, model.get("template_text"),
                                        json_data)

    if tools.__is_color_terminal():
        final_output = displayer.colorize_text(final_output)

    if out_file is not None:
        set_file_text(out_file, final_output)

        if tools.is_user_interactive() and (out_file.lower().endswith(".html")
                                            or
                                            out_file.lower().endswith(".htm")):
            webbrowser.open_new_tab("file://" + out_file)

    else:
        print(final_output)

    gprint("Export ended: {}".format(datetime.now()))
Example #3
0
def multipart_progress(path, filename):
    encoder = MultipartEncoder(
        {'file': (filename, path, 'application/octet-stream')})
    if tools.is_user_interactive():
        bar = tqdm(desc=filename,
                   total=encoder.len,
                   leave=False,
                   dynamic_ncols=True,
                   unit='B',
                   unit_scale=True,
                   unit_divisor=1024)
        multipart_monitor = MultipartEncoderMonitor(
            encoder, lambda monitor: bar.update(monitor.bytes_read - bar.n))
        return multipart_monitor, bar
    else:
        return encoder, None
Example #4
0
def cli():
    """get status of NeoLoad cli Settings"""
    login = user_data.get_user_data(False)
    if login is None:
        print("No settings is stored. Please use \"neoload login\" to start.")
    else:
        print(login)

        logging.debug({
            "interactive_environment_variable":
            os.getenv(tools.__nl_interactive_env_var),
            "interactive_tty":
            sys.__stdin__.isatty(),
            "interactive_effective":
            tools.is_user_interactive()
        })
Example #5
0
    def test_is_user_interactive(self, monkeypatch):
        mocks = {}
        monkeypatch.setattr(
            os,
            'getenv',
            lambda var, default=None: mock_get_env(mocks, var, default))
        assert tools.is_user_interactive() is False

        mocks = {'NL_INTERACTIVE': 'some value'}
        monkeypatch.setattr(
            os,
            'getenv',
            lambda var, default=None: mock_get_env(mocks, var, default))
        assert tools.is_user_interactive() is False

        mocks = {'NL_INTERACTIVE': 'false'}
        monkeypatch.setattr(
            os,
            'getenv',
            lambda var, default=None: mock_get_env(mocks, var, default))
        assert tools.is_user_interactive() is False

        mocks = {'NL_INTERACTIVE': 'False'}
        monkeypatch.setattr(
            os,
            'getenv',
            lambda var, default=None: mock_get_env(mocks, var, default))
        assert tools.is_user_interactive() is False

        mocks = {'NL_INTERACTIVE': '0'}
        monkeypatch.setattr(
            os,
            'getenv',
            lambda var, default=None: mock_get_env(mocks, var, default))
        assert tools.is_user_interactive() is False

        mocks = {'NL_INTERACTIVE': '1'}
        monkeypatch.setattr(
            os,
            'getenv',
            lambda var, default=None: mock_get_env(mocks, var, default))
        assert tools.is_user_interactive() is True

        mocks = {'NL_INTERACTIVE': 'True'}
        monkeypatch.setattr(
            os,
            'getenv',
            lambda var, default=None: mock_get_env(mocks, var, default))
        assert tools.is_user_interactive() is True

        mocks = {'NL_INTERACTIVE': 'trUe'}
        monkeypatch.setattr(
            os,
            'getenv',
            lambda var, default=None: mock_get_env(mocks, var, default))
        assert tools.is_user_interactive() is True

        mocks = {'NL_INTERACTIVE': 'yes'}
        monkeypatch.setattr(
            os,
            'getenv',
            lambda var, default=None: mock_get_env(mocks, var, default))
        assert tools.is_user_interactive() is True

        mocks = {'NL_INTERACTIVE': 'yEs'}
        monkeypatch.setattr(
            os,
            'getenv',
            lambda var, default=None: mock_get_env(mocks, var, default))
        assert tools.is_user_interactive() is True

        mocks = {'NL_INTERACTIVE': 'Y'}
        monkeypatch.setattr(
            os,
            'getenv',
            lambda var, default=None: mock_get_env(mocks, var, default))
        assert tools.is_user_interactive() is True