Skip to content

Commit 69a14be

Browse files
committed
Refactor to use json.loads straightaway
1 parent d7cf679 commit 69a14be

2 files changed

Lines changed: 64 additions & 59 deletions

File tree

tests/integration/nodebalancers/conftest.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import json
2-
31
import pytest
42

53
from tests.integration.conftest import create_vpc_w_subnet
@@ -8,8 +6,6 @@
86
check_attribute_value,
97
delete_target_id,
108
exec_test_command,
11-
get_random_region_with_caps,
12-
get_random_text,
139
wait_for_condition,
1410
)
1511
from tests.integration.linodes.helpers import DEFAULT_TEST_IMAGE

tests/integration/nodebalancers/test_node_balancers.py

Lines changed: 64 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -570,49 +570,54 @@ def test_view_node_for_node_balancer_udp_configuration(
570570
def test_nb_with_backend_vpc_only(get_vpc_with_subnet):
571571
vpc = get_vpc_with_subnet
572572

573-
nb_attrs = exec_test_command(
574-
BASE_CMDS["nodebalancers"]
575-
+ [
576-
"create",
577-
"--region",
578-
vpc["region"],
579-
"--backend_vpcs.subnet_id",
580-
str(vpc["subnets"][0]["id"]),
581-
"--json",
582-
]
573+
nb_attrs = json.loads(
574+
exec_test_command(
575+
BASE_CMDS["nodebalancers"]
576+
+ [
577+
"create",
578+
"--region",
579+
vpc["region"],
580+
"--backend_vpcs.subnet_id",
581+
str(vpc["subnets"][0]["id"]),
582+
"--json",
583+
]
584+
),
583585
)
584-
nb_attrs = json.loads(nb_attrs)
585586
nb_id = str(nb_attrs[0]["id"])
586587
assert isinstance(ipaddress.ip_address(nb_attrs[0]["ipv4"]), ipaddress.IPv4Address)
587588
assert isinstance(ipaddress.ip_address(nb_attrs[0]["ipv6"]), ipaddress.IPv6Address)
588589
assert nb_attrs[0]["frontend_address_type"] == "public"
589590
assert nb_attrs[0]["frontend_vpc_subnet_id"] is None
590591

591-
nb_vpcs = exec_test_command(
592-
BASE_CMDS["nodebalancers"] + ["vpcs-list", nb_id, "--json",]
592+
nb_vpcs = json.loads(
593+
exec_test_command(
594+
BASE_CMDS["nodebalancers"] + ["vpcs-list", nb_id, "--json",]
595+
),
593596
)
594-
nb_vpcs = json.loads(nb_vpcs)
595597
assert len(nb_vpcs) == 1
596598
assert nb_vpcs[0]["purpose"] == "backend"
597599

598-
nb_vpc = exec_test_command(
599-
BASE_CMDS["nodebalancers"] + ["vpc-view", nb_id, str(nb_vpcs[0]["id"]), "--json",]
600+
nb_vpc = json.loads(
601+
exec_test_command(
602+
BASE_CMDS["nodebalancers"] + ["vpc-view", nb_id, str(nb_vpcs[0]["id"]), "--json",]
603+
),
600604
)
601-
nb_vpc = json.loads(nb_vpc)
602605
assert nb_vpc[0]["purpose"] == "backend"
603606

604607
# TODO: Uncomment when API implementation of /backend_vpcs and /frontend_vpcs endpoints is finished
605-
# nb_backend_vpcs = exec_test_command(
606-
# BASE_CMDS["nodebalancers"] + ["backend_vpcs-list", nb_id, "--json",]
608+
# nb_backend_vpcs = json.loads(
609+
# exec_test_command(
610+
# BASE_CMDS["nodebalancers"] + ["backend_vpcs-list", nb_id, "--json",]
611+
# ),
607612
# )
608-
# nb_backend_vpcs = json.loads(nb_backend_vpcs)
609613
# assert len(nb_backend_vpcs) == 1
610614
# assert nb_backend_vpcs[0]["purpose"] == "backend"
611615
#
612-
# nb_frontend_vpcs = exec_test_command(
613-
# BASE_CMDS["nodebalancers"] + ["frontend_vpcs-list", nb_id, "--json",]
616+
# nb_frontend_vpcs = json.loads(
617+
# exec_test_command(
618+
# BASE_CMDS["nodebalancers"] + ["frontend_vpcs-list", nb_id, "--json",]
619+
# ),
614620
# )
615-
# nb_frontend_vpcs = json.loads(nb_frontend_vpcs)
616621
# assert len(nb_frontend_vpcs) == 0
617622

618623
delete_target_id(target="nodebalancers", id=nb_id)
@@ -623,22 +628,23 @@ def test_nb_with_frontend_ipv4_only(get_vpc_with_subnet):
623628
vpc = get_vpc_with_subnet
624629
ipv4_address = "10.0.0.2" # first available address
625630

626-
nb_attrs = exec_test_command(
627-
BASE_CMDS["nodebalancers"]
628-
+ [
629-
"create",
630-
"--region",
631-
vpc["region"],
632-
"--frontend_vpcs.subnet_id",
633-
str(vpc["subnets"][0]["id"]),
634-
"--frontend_vpcs.ipv4_range",
635-
"10.0.0.0/24",
636-
"--type",
637-
"premium",
638-
"--json",
639-
]
631+
nb_attrs = json.loads(
632+
exec_test_command(
633+
BASE_CMDS["nodebalancers"]
634+
+ [
635+
"create",
636+
"--region",
637+
vpc["region"],
638+
"--frontend_vpcs.subnet_id",
639+
str(vpc["subnets"][0]["id"]),
640+
"--frontend_vpcs.ipv4_range",
641+
"10.0.0.0/24",
642+
"--type",
643+
"premium",
644+
"--json",
645+
],
646+
),
640647
)
641-
nb_attrs = json.loads(nb_attrs)
642648
nb_id = str(nb_attrs[0]["id"])
643649

644650
assert nb_attrs[0]["ipv4"] == ipv4_address
@@ -647,17 +653,19 @@ def test_nb_with_frontend_ipv4_only(get_vpc_with_subnet):
647653
assert nb_attrs[0]["frontend_vpc_subnet_id"] == vpc["subnets"][0]["id"]
648654

649655
# TODO: Uncomment when API implementation of /backend_vpcs and /frontend_vpcs endpoints is finished
650-
# nb_frontend_vpcs = exec_test_command(
651-
# BASE_CMDS["nodebalancers"] + ["frontend_vpcs-list", nb_id, "--json",]
656+
# nb_frontend_vpcs = json.loads(
657+
# exec_test_command(
658+
# BASE_CMDS["nodebalancers"] + ["frontend_vpcs-list", nb_id, "--json",]
659+
# ),
652660
# )
653-
# nb_frontend_vpcs = json.loads(nb_frontend_vpcs)
654661
# assert len(nb_frontend_vpcs) == 1
655662
# assert nb_frontend_vpcs[0]["purpose"] == "frontend"
656663
#
657-
# nb_backend_vpcs = exec_test_command(
658-
# BASE_CMDS["nodebalancers"] + ["backend_vpcs-list", nb_id, "--json",]
664+
# nb_backend_vpcs = json.loads(
665+
# exec_test_command(
666+
# BASE_CMDS["nodebalancers"] + ["backend_vpcs-list", nb_id, "--json",]
667+
# ),
659668
# )
660-
# nb_backend_vpcs = json.loads(nb_backend_vpcs)
661669
# assert len(nb_backend_vpcs) == 0
662670

663671
delete_target_id(target="nodebalancers", id=nb_id)
@@ -711,18 +719,19 @@ def test_nb_with_frontend_and_default_type_fail(get_vpc_with_subnet):
711719
def test_nb_with_premium40gb_type(get_vpc_with_subnet):
712720
vpc = get_vpc_with_subnet
713721

714-
nb_attrs = exec_test_command(
715-
BASE_CMDS["nodebalancers"]
716-
+ [
717-
"create",
718-
"--region",
719-
vpc["region"],
720-
"--type",
721-
"premium_40gb",
722-
"--json",
723-
],
722+
nb_attrs = json.loads(
723+
exec_test_command(
724+
BASE_CMDS["nodebalancers"]
725+
+ [
726+
"create",
727+
"--region",
728+
vpc["region"],
729+
"--type",
730+
"premium_40gb",
731+
"--json",
732+
],
733+
),
724734
)
725-
nb_attrs = json.loads(nb_attrs)
726735
assert nb_attrs[0]["type"] == "premium_40gb"
727736

728737
delete_target_id(target="nodebalancers", id=str(nb_attrs[0]["id"]))

0 commit comments

Comments
 (0)