Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 69 additions & 4 deletions tests/integration/account/test_account.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

import pytest

from tests.integration.helpers import (
Expand Down Expand Up @@ -202,14 +204,77 @@ def test_account_login_view(get_login_id):
assert_headers_in_lines(headers, lines)


@pytest.fixture
def test_account_setting_view():
res = exec_test_command(
expected_headers = [
"longview_subscription",
"network_helper",
"interfaces_for_new_linodes",
]

settings_text = exec_test_command(
BASE_CMDS["account"] + ["settings", "--text", "--delimiter=,"]
)
lines = res.splitlines()
lines = settings_text.splitlines()
headers = lines[0].split(",")

headers = ["longview_subscription", "network_helper"]
assert_headers_in_lines(headers, lines)
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_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["account"]
+ [
"settings-update",
"--interfaces_for_new_linodes",
original_value,
]
)


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_CMDS["account"]
+ [
"settings-update",
"--interfaces_for_new_linodes",
new_value,
]
)

# Verify the setting was updated
updated_json = exec_test_command(
BASE_CMDS["account"] + ["settings", "--json"]
)
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():
Expand Down
30 changes: 23 additions & 7 deletions tests/integration/networking/test_networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,16 @@ def has_shared_ip(linode_id: int, ip: str) -> bool:
["linode-cli", "linodes", "ips-list", "--json", linode_id]
)
)[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):
Expand Down Expand Up @@ -92,15 +99,24 @@ def test_view_an_ip_address(test_linode_id):
BASE_CMDS["networking"]
+ [
"ip-view",
"--text",
"--no-headers",
"--delimiter",
",",
"--json",
linode_ipv4,
]
)

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):
Expand Down