From c843a0b430ffeb47baf68c45840bc294b03fd76d Mon Sep 17 00:00:00 2001 From: vshanthe Date: Fri, 6 Jun 2025 18:19:32 +0530 Subject: [PATCH 1/2] added_tests --- tests/integration/account/test_account.py | 75 +++++++++++++++++-- .../integration/networking/test_networking.py | 30 ++++++-- 2 files changed, 93 insertions(+), 12 deletions(-) diff --git a/tests/integration/account/test_account.py b/tests/integration/account/test_account.py index fb173d2a2..a3245ce66 100644 --- a/tests/integration/account/test_account.py +++ b/tests/integration/account/test_account.py @@ -1,3 +1,5 @@ +import json + import pytest from tests.integration.helpers import assert_headers_in_lines, exec_test_command @@ -250,16 +252,79 @@ def test_account_login_view(get_login_id): assert_headers_in_lines(headers, lines) +@pytest.fixture def test_account_setting_view(): - res = ( + expected_headers = [ + "longview_subscription", + "network_helper", + "interfaces_for_new_linodes", + ] + + settings_text = ( exec_test_command(BASE_CMD + ["settings", "--text", "--delimiter=,"]) .stdout.decode() - .rstrip() + .strip() + ) + lines = settings_text.splitlines() + headers = lines[0].split(",") + + for expected in expected_headers: + assert ( + expected in headers + ), f"Expected header '{expected}' not found in CLI output" + + # Fetch current interfaces setting + settings_json = exec_test_command( + BASE_CMD + ["settings", "--json"] + ).stdout.decode() + original_value = json.loads(settings_json)[0]["interfaces_for_new_linodes"] + + yield original_value + + # Restore original setting after test + exec_test_command( + BASE_CMD + + [ + "settings-update", + "--interfaces_for_new_linodes", + original_value, + ] ) - lines = res.splitlines() - headers = ["longview_subscription", "network_helper"] - assert_headers_in_lines(headers, lines) + +def test_update_interfaces_setting(test_account_setting_view): + original_value = test_account_setting_view + + # Define valid values different from the original + valid_options = [ + "legacy_config_only", + "legacy_config_default_but_linode_allowed", + "linode_default_but_legacy_config_allowed", + "linode_only", + ] + + # Select a different value for testing + new_value = next(val for val in valid_options if val != original_value) + + # Update the setting + exec_test_command( + BASE_CMD + + [ + "settings-update", + "--interfaces_for_new_linodes", + new_value, + ] + ) + + # Verify the setting was updated + updated_json = exec_test_command( + BASE_CMD + ["settings", "--json"] + ).stdout.decode() + updated_value = json.loads(updated_json)[0]["interfaces_for_new_linodes"] + + assert ( + updated_value == new_value + ), f"Expected {new_value}, got {updated_value}" def test_user_list(): diff --git a/tests/integration/networking/test_networking.py b/tests/integration/networking/test_networking.py index 2d29dd166..846b151c9 100644 --- a/tests/integration/networking/test_networking.py +++ b/tests/integration/networking/test_networking.py @@ -47,9 +47,16 @@ def has_shared_ip(linode_id: int, ip: str) -> bool: ["linode-cli", "linodes", "ips-list", "--json", linode_id] ).stdout.decode() )[0]["ipv4"]["shared"] + for entry in shared_ips: + if entry["address"] == ip: + # Validate presence and type of interface_id + assert "interface_id" in entry + assert entry["interface_id"] is None or isinstance( + entry["interface_id"], int + ) + return True - # Ensure there is a matching shared IP - return len([v for v in shared_ips if v["address"] == ip]) > 0 + return False def test_display_ips_for_available_linodes(test_linode_id): @@ -89,15 +96,24 @@ def test_view_an_ip_address(test_linode_id): BASE_CMD + [ "ip-view", - "--text", - "--no-headers", - "--delimiter", - ",", + "--json", linode_ipv4, ] ).stdout.decode() - assert re.search(r"^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}", result) + data = json.loads(result) + if isinstance(data, list): + data = data[0] + # Validate that the address is a proper IPv4 address + assert re.match(r"^[0-9]{1,3}(\.[0-9]{1,3}){3}$", data["address"]) + + # Validate that interface_id is present and either None or int + assert ( + "interface_id" in data + ), "`interface_id` field missing in IP view response" + assert data["interface_id"] is None or isinstance( + data["interface_id"], int + ), f"`interface_id` is not None or int: {data['interface_id']}" def test_allocate_additional_private_ipv4_address(test_linode_id): From 544f639e8396e938742eccf3d5c4b86cde3f44b9 Mon Sep 17 00:00:00 2001 From: vshanthe Date: Fri, 27 Jun 2025 12:01:50 +0530 Subject: [PATCH 2/2] fix --- tests/integration/account/test_account.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/tests/integration/account/test_account.py b/tests/integration/account/test_account.py index 33103391e..c9d5399d4 100644 --- a/tests/integration/account/test_account.py +++ b/tests/integration/account/test_account.py @@ -212,10 +212,8 @@ def test_account_setting_view(): "interfaces_for_new_linodes", ] - settings_text = ( - exec_test_command(BASE_CMDS + ["settings", "--text", "--delimiter=,"]) - .stdout.decode() - .strip() + settings_text = exec_test_command( + BASE_CMDS["account"] + ["settings", "--text", "--delimiter=,"] ) lines = settings_text.splitlines() headers = lines[0].split(",") @@ -227,15 +225,15 @@ def test_account_setting_view(): # Fetch current interfaces setting settings_json = exec_test_command( - BASE_CMDS + ["settings", "--json"] - ).stdout.decode() + BASE_CMDS["account"] + ["settings", "--json"] + ) original_value = json.loads(settings_json)[0]["interfaces_for_new_linodes"] yield original_value # Restore original setting after test exec_test_command( - BASE_CMDS + BASE_CMDS["account"] + [ "settings-update", "--interfaces_for_new_linodes", @@ -260,7 +258,7 @@ def test_update_interfaces_setting(test_account_setting_view): # Update the setting exec_test_command( - BASE_CMDS + BASE_CMDS["account"] + [ "settings-update", "--interfaces_for_new_linodes", @@ -270,8 +268,8 @@ def test_update_interfaces_setting(test_account_setting_view): # Verify the setting was updated updated_json = exec_test_command( - BASE_CMDS + ["settings", "--json"] - ).stdout.decode() + BASE_CMDS["account"] + ["settings", "--json"] + ) updated_value = json.loads(updated_json)[0]["interfaces_for_new_linodes"] assert (