Пример #1
0
def test_vpc_by_id():
    vpc_id = _adapter.vpc_id
    res = session.get(
        f"{API_ENDPOINT}/v1/vpcs/{vpc_id}?version=2021-05-06&generation=2")

    check_required_params(res)

    # testing response
    check_valid_vpc(res.json())
Пример #2
0
def test_get_subnet_by_id():
    subnet_id = _adapter.subnet_id

    res = session.get(
        f"{API_ENDPOINT}/v1/subnets/{subnet_id}?version=2021-05-06&generation=2"
    )

    check_required_params(res)
    check_valid_subnet(res.json())
Пример #3
0
def test_key_by_id():
    key_id = _adapter.key_id

    res = session.get(
        f"{API_ENDPOINT}/v1/keys/{key_id}?version=2021-05-06&generation=2")

    check_required_params(res)

    # testing response
    check_valid_key(res.json())
Пример #4
0
def test_floating_ips_by_id():
    floating_ips_id = _adapter.floating_ips_id

    res = session.get(
        f"{API_ENDPOINT}/v1/floating_ips/{floating_ips_id}?version=2021-05-06&generation=2"
    )

    check_required_params(res)

    # testing response
    check_valid_floating_ip(res.json())
Пример #5
0
def test_get_vpcs():
    res = session.get(
        f"{API_ENDPOINT}/v1/vpcs?version=2021-05-06&generation=2")
    query_params = dict(parse_qsl(urlparse(res.url).query))

    optional_params = ["start", "limit", "resource_group.id", "classic_access"]

    # -- testing request params
    check_required_params(res)

    for k, v in query_params.items():
        # check that query has the correct params
        assert k in (REQUIRED_PARAMS + optional_params)
        # check if query params has any value
        assert v

        if k == "limit":
            assert v.isdigit()
            assert 1 <= v <= 100

        elif k == "classic_access":
            assert v in ["true", "false"]

    # -- testing response
    required_response_keys = ["limit", "first", "total_count", "vpcs"]
    response_keys = required_response_keys + ["next"]
    data = res.json()

    for k in required_response_keys:
        assert k in data.keys()

    for k, v in data.items():
        assert k in response_keys

        if k == "total_count":
            assert v >= 0

        elif k == "vpcs" and v:
            for vpc in v:
                check_valid_vpc(vpc)

        elif k == "limit":
            assert 1 <= v <= 100

        elif k == "next":
            assert re.match(URL_REGEX, v.get("href", ""))

        else:
            assert v
Пример #6
0
def test_get_subnets():
    res = session.get(
        f"{API_ENDPOINT}/v1/subnets?version=2021-05-06&generation=2")
    query_params = dict(parse_qsl(urlparse(res.url).query))

    optional_params = [
        "start",
        "limit",
        "resource_group.id",
        "routing_table.id",
        "routing_table.name",
        "ipv4_cidr_block",
    ]

    check_required_params(res)

    for k, v in query_params.items():
        assert k in (optional_params + REQUIRED_PARAMS)
        # check if query contains optional params
        if k in optional_params:
            # check if query params has any value
            assert v

        if k == "limit":
            assert v.isdigit()
            assert 1 <= v <= 100

    data = res.json()
    required_response_keys = ["first", "limit", "subnets", "total_count"]

    optional_response_key = ["next"]

    for k, v in data.items():
        assert k in (required_response_keys + optional_response_key)

        if k == "limit":
            assert 1 <= v <= 100

        if k == "total_count":
            assert v >= 0

        if k == "next":
            assert re.match(URL_REGEX, v.get("href"))

    subnets = data.get("subnets", [])
    for subnet in subnets:
        check_valid_subnet(subnet)
Пример #7
0
def test_get_keys():
    res = session.get(
        f"{API_ENDPOINT}/v1/keys?version=2021-05-06&generation=2")
    query_params = dict(parse_qsl(urlparse(res.url).query))

    optional_params = ["resource_group.id"]
    response = res.json()["keys"]

    # -- testing request params
    check_required_params(res)

    for k, v in query_params.items():
        # check that query has the correct params
        assert k in (REQUIRED_PARAMS + optional_params)
        # check if query params has any value
        assert v

    # -- testing response

    for data in response:
        check_valid_key(data)
Пример #8
0
def test_get_instances():
    res = session.get(
        f"{API_ENDPOINT}/v1/instances?version=2021-05-06&generation=2")
    query_params = dict(parse_qsl(urlparse(res.url).query))

    optional_params = [
        "start",
        "limit",
        "resource_group.id",
        "name",
        "vpc.id",
        "vpc.crn",
        "vpc.name",
    ]

    data = res.json()
    required_response_keys = ["first", "limit", "instances", "total_count"]

    instance_keys = [
        "bandwidth",
        "boot_volume_attachment",
        "created_at",
        "crn",
        "href",
        "id",
        "image",
        "memory",
        "name",
        "network_interfaces",
        "primary_network_interface",
        "profile",
        "resource_group",
        "status",
        "vcpu",
        "volume_attachments",
        "vpc",
        "zone",
    ]

    old_allowed_instance_keys = instance_keys + ["gpu"]

    allowed_instance_keys = instance_keys + [
        "placement_target",
        "dedicated_host",
        "disks",
        "status_reasons",
    ]

    optional_response_key = ["next"]

    for k, v in data.items():
        assert k in (required_response_keys + optional_response_key)

        if k == "limit":
            assert 1 <= v <= 100

        if k == "total_count":
            assert v >= 0

        if k == "next":
            assert re.match(URL_REGEX, v.get("href"))

    instances = data.get("instances", [])

    for k, v in query_params.items():
        # check that query has the correct params
        assert k in (REQUIRED_PARAMS + optional_params)
        # check if query params has any value
        assert v

    # -- testing response
    for instance in instances:
        for k, v in instance.items():
            assert k in allowed_instance_keys

        check_valid_instance(instance)