Esempio n. 1
0
def cli(token, url, no_write, workspace):
    """Store your token and API url of NeoLoad Web. The token is read from stdin if none is set.
    The default API url is "https://neoload-api.saas.neotys.com/" """
    if not token:
        if sys.stdin.isatty():
            token = click.prompt("Enter your token", None, True)
        else:
            token = input()
    url = url.strip()
    if url[-1] != '/':
        url += '/'

    __user_data = user_data.do_login(token, url, no_write)

    if workspace is not None:
        if user_data.is_version_lower_than('2.5.0'):
            print(
                "WARNING: The workspace option works only since Neoload Web 2.5.0. The specified workspace is ignored."
            )
        else:
            is_workspace_id = tools.is_mongodb_id(workspace)
            __id = tools.get_id(workspace, workspaces.__resolver,
                                is_workspace_id)
            tools.use(__id, workspaces.meta_key, workspaces.__resolver)

    if sys.stdin.isatty():
        print(__user_data)
Esempio n. 2
0
def cli(command, name_or_id):
    """
    ls     # Lists workspaces                                                .
    use    # Remember the workspace you want to work on                      .
    """
    rest_crud.set_current_command()
    if not command:
        print("command is mandatory. Please see neoload workspaces --help")
        return
    if user_data.is_version_lower_than('2.5.0'):
        print("ERROR: This commands works only since Neoload Web 2.5.0")
        return
    rest_crud.set_current_sub_command(command)
    if name_or_id == "cur":
        name_or_id = user_data.get_meta(meta_key)
    is_id = tools.is_mongodb_id(name_or_id)
    # avoid to make two requests if we have not id.
    if command == "ls":
        # The endpoint GET /workspaces/{workspaceId} is not yet implemented
        ws_filter = None
        if name_or_id is not None: ws_filter = "id={}".format(name_or_id)
        tools.ls(None, True, __resolver, ws_filter)
        return

    __id = tools.get_id(name_or_id, __resolver, is_id)

    if command == "use":
        tools.use(__id, meta_key, __resolver)
Esempio n. 3
0
def cli(command, name_or_id):
    """
    ls     # Lists workspaces                                                .
    use    # Remember the workspace you want to work on                      .
    """
    if not command:
        print("command is mandatory. Please see neoload workspaces --help")
        return
    if user_data.is_version_lower_than('2.5.0'):
        print("ERROR: This commands works only since Neoload Web 2.5.0")
        return
    rest_crud.set_current_sub_command(command)
    if name_or_id == "cur":
        name_or_id = user_data.get_meta(meta_key)
    is_id = tools.is_mongodb_id(name_or_id)
    # avoid to make two requests if we have not id.
    if command == "ls":
        # The endpoint GET /workspaces/{workspaceId} is not yet implemented
        if name_or_id is not None:
            print(
                "ERROR: Unable to display only one workspace. API endoint not yet implemented. Please use command neoload workspaces ls without name or ID"
            )
        tools.ls(name_or_id, is_id, __resolver)
        return

    __id = tools.get_id(name_or_id, __resolver, is_id)

    if command == "use":
        tools.use(__id, meta_key, __resolver)
Esempio n. 4
0
def cli(name_or_id, return_0):
    """Wait the end of test"""
    if not name_or_id or name_or_id == "cur":
        name_or_id = user_data.get_meta(test_results.meta_key)

    id_ = tools.get_id(name_or_id, test_results.__resolver)

    running_tools.wait(id_, not return_0)
Esempio n. 5
0
def get_id_by_name_or_id(name):
    if name == "cur":
        name = user_data.get_meta(meta_key)
    is_id = tools.is_id(name)

    __id = tools.get_id(name, __resolver, is_id)

    if not __id:
        __id = user_data.get_meta_required(meta_key)

    return __id
Esempio n. 6
0
def get_endpoint(name: str):
    if name == "cur":
        name = user_data.get_meta(meta_key)
    is_id = tools.is_id(name)

    __id = tools.get_id(name, test_results.__resolver, is_id)

    if not __id:
        __id = user_data.get_meta_required(meta_key)

    return '#!result/%s/overview' % __id
Esempio n. 7
0
def cli(command, name, rename, description, scenario, controller_zone_id,
        lg_zone_ids, naming_pattern):
    """
    ls     # Lists test settings                                             .
    create # Create a new test settings                                      .
    put    # Update all fields of a test settings                            .
    patch  # Update only the selected fields of a test settings              .
    delete # Remove a test settings and all associated test results          .
    use    # Remember the test settings you want to work on. Example : neoload
    |        test-settings use MyTest ; neoload test-settings delete         .
    """
    if not command:
        print("command is mandatory. Please see neoload tests-settings --help")
        return
    rest_crud.set_current_sub_command(command)
    if name == "cur":
        name = user_data.get_meta(meta_key)
    is_id = tools.is_id(name)
    # avoid to make two requests if we have not id.
    if command == "ls":
        tools.ls(name, is_id, __resolver)
        return
    elif command == "create":
        id_created = create(
            create_json(name, description, scenario, controller_zone_id,
                        lg_zone_ids, naming_pattern))
        user_data.set_meta(meta_key, id_created)
        return

    __id = tools.get_id(name, __resolver, is_id)

    if command == "use":
        tools.use(__id, meta_key, __resolver)
        return

    if not __id:
        __id = user_data.get_meta_required(meta_key)

    if command == "put":
        put(
            __id,
            create_json(rename, description, scenario, controller_zone_id,
                        lg_zone_ids, naming_pattern))
        user_data.set_meta(meta_key, __id)
    elif command == "patch":
        patch(
            __id,
            create_json(rename, description, scenario, controller_zone_id,
                        lg_zone_ids, naming_pattern))
        user_data.set_meta(meta_key, __id)
    elif command == "delete":
        delete(__id)
        user_data.set_meta(meta_key, None)
Esempio n. 8
0
def parse_to_id(name_or_id):
    val = name_or_id
    if val == "cur":
        val = user_data.get_meta(meta_key)
    is_id = tools.is_id(val)

    __id = tools.get_id(val, __resolver, is_id)

    if not __id:
        __id = user_data.get_meta_required(meta_key)

    return __id
Esempio n. 9
0
def create_or_patch(name, rename, description, scenario, controller_zone_id, lg_zone_ids, naming_pattern, file):
    is_id = tools.is_id(name)

    __id = tools.get_id(name, __resolver, is_id, True)

    if __id is None:
        logging.info('creating test-settings: ' + str(name))
        __id = create(create_json(name, description, scenario, controller_zone_id, lg_zone_ids, naming_pattern, file))
    else:
        logging.info('Patching test-settings: ' + str(__id))
        patch(__id, create_json(rename, description, scenario, controller_zone_id, lg_zone_ids, naming_pattern, file))
    return __id
Esempio n. 10
0
def cli(command, name, rename, description, quality_status, junit_file, file,
        filter):
    """
    ls       # Lists test results                                            .
    summary  # Display a summary of the result : SLAs and statistics         .
    junitsla # Output SLA results to a file with junit format                .
    put      # Update the name, description or quality-status of the result  .
    delete   # Remove a result                                               .
    use      # Remember the test result you want to work on. Example : neoload
    |          test-results use MyTest#1 ; neoload test-results summary      .
    """
    rest_crud.set_current_command()
    if not command:
        print("command is mandatory. Please see neoload tests-results --help")
        return
    rest_crud.set_current_sub_command(command)
    if name == "cur":
        name = user_data.get_meta(meta_key)
    is_id = tools.is_id(name)
    # avoid to make two requests if we have not id.
    if command == "ls":
        tools.ls(name, is_id, __resolver, filter,
                 ['project', 'status', 'author', 'sort'])
        return

    __id = tools.get_id(name, __resolver, is_id)

    if command == "use":
        tools.use(__id, meta_key, __resolver)
        return

    if not __id:
        __id = user_data.get_meta_required(meta_key)

    system_exit = {'message': '', 'code': 0}
    if command == "summary":
        system_exit = summary(__id)
    elif command == "junitsla":
        junit(__id, junit_file)
    elif command == "delete":
        delete(__id)
        user_data.set_meta(meta_key, None)
    else:
        json_data = load_from_file(file) if file else create_json(
            rename, description, quality_status)
        if command == "put":
            put(__id, json_data)
        elif command == "patch":
            patch(__id, json_data)
    if command != "delete":
        user_data.set_meta(meta_key, __id)

    tools.system_exit(system_exit)
Esempio n. 11
0
def get_endpoint(name: str):
    __id = tools.get_id(name, test_results.__resolver)
    return '/#!result/%s/overview' % __id