Ejemplo n.º 1
0
def templates(subcommand, profile_name, template_id, test_file, test_name):

    payload = {}
    if subcommand in ["remove", "get", "list"]:
        if template_id is not None:
            payload["template_id"] = template_id

    if subcommand in ["add"]:
        try:
            test_file = json.load(test_file)
            for key in test_file:
                payload[key] = test_file[key]
        except Exception as e:
            print(e)
            exit(1)

    if test_name is not None:
        payload["test_name"] = test_name

    templates_path = path("templates", subcommand)

    response = send_request(
        templates_path,
        payload,
        auth(profile_name)
    )
    if response["success"]:
        print_message(response["response_json"])
        exit(0)
    else:
        print_message(response["error"])
        exit(1)
Ejemplo n.º 2
0
def notifications(subcommand, profile_name, notification_id,
                  notification_channel, notification_destination, error_type,
                  error_threshold):

    payload = {}
    if subcommand in ["remove"]:
        payload["notification_id"] = notification_id

    if subcommand in ["add"]:
        payload["notification_channel"] = notification_channel
        payload[error_type] = error_threshold

        if notification_channel == "SLACK":
            payload["notification_webhook"] = notification_destination
        if notification_channel == "EMAIL":
            payload["notification_email"] = notification_destination

    notifications_path = path("notifications", subcommand)

    response = send_request(notifications_path, payload, auth(profile_name))
    if response["success"]:
        print_message(response["response_json"])
        exit(0)
    else:
        print_message(response["error"])
        exit(1)
Ejemplo n.º 3
0
def crons(subcommand, profile_name, cron_id, test_file, cron_enabled,
          test_name, schedule_type, schedule_hour, schedule_minute,
          schedule_weekday, schedule_day_of_month):

    payload = {}
    if subcommand in ["remove", "get", "set-status", "list"]:
        if cron_id is not None:
            payload["cron_id"] = cron_id

    if subcommand in ["set-status"]:
        payload["cron_enabled"] = cron_enabled

    if subcommand in ["add", "preview-credits"]:
        try:
            test_file = json.load(test_file)
            for key in test_file:
                payload[key] = test_file[key]
            payload["test_type"] = "CRON"
        except Exception as e:
            print(e)
            exit(1)

    if test_name is not None:
        payload["test_name"] = test_name

    if schedule_type is not None:
        payload["schedule_type"] = schedule_type

    if schedule_hour is not None:
        payload["schedule_hour"] = schedule_hour

    if schedule_minute is not None:
        payload["schedule_minute"] = schedule_minute

    if schedule_weekday is not None:
        payload["schedule_weekday"] = schedule_weekday

    if schedule_day_of_month is not None:
        payload["schedule_day_of_month"] = schedule_day_of_month

    crons_path = path("crons", subcommand)

    response = send_request(crons_path, payload, auth(profile_name))
    if response["success"]:
        print_message(response["response_json"])
        exit(0)
    else:
        print_message(response["error"])
        exit(1)
Ejemplo n.º 4
0
def domains(subcommand, profile_name, domain_name):

    payload = {}
    if subcommand != "list":
        payload["domain_name"] = domain_name

    domain_path = path("domains", subcommand)

    response = send_request(domain_path, payload, auth(profile_name))
    if response["success"]:
        print_message(response["response_json"])
        exit(0)
    else:
        print_message(response["error"])
        exit(1)
Ejemplo n.º 5
0
def csv(subcommand, profile_name, csv_id):

    payload = {}
    if subcommand in ["get", "list", "remove"]:
        if csv_id is not None:
            payload["csv_id"] = csv_id

    csv_path = path("csv", subcommand)

    response = send_request(csv_path, payload, auth(profile_name))
    if response["success"]:
        print_message(response["response_json"])
        exit(0)
    else:
        print_message(response["error"])
        exit(1)
Ejemplo n.º 6
0
def results(subcommand, profile_name, test_id, results_region):

    payload = {}
    if subcommand in ["get"]:
        payload["test_id"] = test_id

    if subcommand in ["get"]:
        payload["results_region"] = results_region

    results_path = path("results", subcommand)

    response = send_request(results_path, payload, auth(profile_name))
    if response["success"]:
        print_message(response["response_json"])
        exit(0)
    else:
        print_message(response["error"])
        exit(1)
Ejemplo n.º 7
0
def vault(subcommand, profile_name, vault_id, key_storage_type, key_name,
          key_value):

    payload = {}
    if subcommand in ["remove", "get", "edit", "list"]:
        if vault_id is not None:
            payload["vault_id"] = vault_id

    if subcommand in ["add", "edit"]:
        payload["key_storage_type"] = key_storage_type
        payload["key_name"] = key_name
        payload["key_value"] = key_value

    vault_path = path("vault", subcommand)

    response = send_request(vault_path, payload, auth(profile_name))
    if response["success"]:
        print_message(response["response_json"])
        exit(0)
    else:
        print_message(response["error"])
        exit(1)
Ejemplo n.º 8
0
def team(subcommand, profile_name, member_email, member_role):

    payload = {}
    if subcommand in ["change", "remove", "add"]:
        payload["member_email"] = member_email

    if subcommand in ["change", "add"]:
        payload["member_role"] = member_role

    team_path = path("team", subcommand)

    response = send_request(
        team_path,
        payload,
        auth(profile_name)
    )
    if response["success"]:
        print_message(response["response_json"])
        exit(0)
    else:
        print_message(response["error"])
        exit(1)
Ejemplo n.º 9
0
def raw_results(subcommand, profile_name, test_id, results_region,
                results_type, results_path, results_method, min_timestamp,
                max_timestamp):

    payload = {}
    if subcommand in ["get"]:
        payload["test_id"] = test_id
        payload["results_region"] = results_region
        payload["results_type"] = results_type
        payload["results_path"] = results_path
        payload["results_method"] = results_method
        payload["min_timestamp"] = min_timestamp
        payload["max_timestamp"] = max_timestamp

    results_path = path("raw_results", subcommand)

    response = send_request(results_path, payload, auth(profile_name))
    if response["success"]:
        print_message(response["response_json"])
        exit(0)
    else:
        print_message(response["error"])
        exit(1)
Ejemplo n.º 10
0
def tests(subcommand, profile_name, test_id, test_file, template_id,
          test_public, test_name, wait_to_finish):

    payload = {}
    if subcommand in ["cancel", "get", "set-sharing", "list", "remove"]:
        if test_id is not None:
            payload["test_id"] = test_id

    if subcommand in ["set-sharing"]:
        payload["test_public"] = test_public

    if subcommand in ["add", "preview-credits"]:
        if template_id is None:
            try:
                test_file = json.load(test_file)
                for key in test_file:
                    payload[key] = test_file[key]
            except Exception as e:
                print(e)
                exit(1)
        else:
            payload_template = {"template_id": template_id}
            templates_path = path("templates", "get")
            templates_response = send_request(templates_path, payload_template,
                                              auth(profile_name))
            if templates_response["success"]:
                for key in templates_response["response_json"]["TestData"]:
                    payload[key] = templates_response["response_json"][
                        "TestData"][key]
            else:
                print_message(templates_response["error"])
                exit(1)

    if test_name is not None:
        payload["test_name"] = test_name

    tests_path = path("tests", subcommand)

    response = send_request(tests_path, payload, auth(profile_name))
    if response["success"]:
        print_message(response["response_json"])

        if wait_to_finish and subcommand in ["add"]:
            still_running = True
            print("Waiting for test to finish...")
            test_id = response["response_json"]["test_id"]

            # Wait for completion
            test_status = None
            while still_running:
                tests_path = path("tests", "list")
                response = send_request(tests_path, {"test_id": test_id},
                                        auth(profile_name))
                if "Tests" in response["response_json"]:
                    test_status = str(response["response_json"]['Tests'][0]
                                      ["test_status"]).upper()
                    if test_status in test_running_status():
                        time.sleep(sleep_timeout())
                    elif test_status in test_error_status():
                        print(
                            "Test with ID {} has finished running with status {}"
                            .format(test_id, test_status))
                        exit(1)
                    else:
                        print(
                            "Test with ID {} has finished running with status {}"
                            .format(test_id, test_status))
                        still_running = False

            # Print summary results
            if test_status in test_completed_status():
                results_path = path("results", "get")
                response = send_request(results_path, {
                    "test_id": test_id,
                    "results_region": "overall"
                }, auth(profile_name))
                if response["success"]:
                    print_message(response["response_json"])
                    exit(0)
                else:
                    print_message(response["error"])
                    exit(1)
            else:
                print(
                    "Summary results are only available for non-cancelled tests.\n"
                    "Please see web-platform for raw results captured before cancelling the test."
                )

        exit(0)
    else:
        print_message(response["error"])
        exit(1)