Skip to content
Closed
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
307 changes: 110 additions & 197 deletions tests/integration/account/test_account.py

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions tests/integration/beta/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from tests.integration.helpers import (
BASE_CMDS,
exec_test_command,
)


def get_beta_id():
beta_ids = exec_test_command(
BASE_CMDS["betas"]
+ [
"list",
"--text",
"--no-headers",
"--delimiter",
",",
"--format",
"id",
]
).splitlines()
if not beta_ids or beta_ids == [""]:
pytest.skip("No betas available to test.")

return beta_ids[0] if beta_ids else None
59 changes: 14 additions & 45 deletions tests/integration/beta/test_beta_program.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import pytest

from tests.integration.helpers import assert_headers_in_lines, exec_test_command

BASE_CMD = ["linode-cli", "betas"]
from tests.integration.beta.helpers import get_beta_id
from tests.integration.helpers import (
BASE_CMDS,
assert_headers_in_lines,
exec_test_command,
)


def test_beta_list():
res = (
exec_test_command(BASE_CMD + ["list", "--text", "--delimiter=,"])
.stdout.decode()
.rstrip()
res = exec_test_command(
BASE_CMDS["betas"] + ["list", "--text", "--delimiter=,"]
)
lines = res.splitlines()

Expand All @@ -20,54 +21,22 @@ def test_beta_list():
assert_headers_in_lines(headers, lines)


@pytest.fixture
def get_beta_id():
beta_ids = (
exec_test_command(
BASE_CMD
+ [
"list",
"--text",
"--no-headers",
"--delimiter",
",",
"--format",
"id",
]
)
.stdout.decode()
.rstrip()
.splitlines()
)
if not beta_ids or beta_ids == [""]:
pytest.skip("No betas available to test.")

first_id = beta_ids[0]
yield first_id


def test_beta_view(get_beta_id):
beta_id = get_beta_id
def test_beta_view():
beta_id = get_beta_id()
if beta_id is None:
pytest.skip("No beta program available to test")
else:
res = (
exec_test_command(
BASE_CMD + ["view", beta_id, "--text", "--delimiter=,"]
)
.stdout.decode()
.rstrip()
res = exec_test_command(
BASE_CMDS["betas"] + ["view", beta_id, "--text", "--delimiter=,"]
)
lines = res.splitlines()
headers = ["label", "description"]
assert_headers_in_lines(headers, lines)


def test_beta_enrolled():
res = (
exec_test_command(BASE_CMD + ["enrolled", "--text", "--delimiter=,"])
.stdout.decode()
.rstrip()
res = exec_test_command(
BASE_CMDS["betas"] + ["enrolled", "--text", "--delimiter=,"]
)
lines = res.splitlines()

Expand Down
16 changes: 7 additions & 9 deletions tests/integration/cli/test_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

@pytest.mark.smoke
def test_help_page_for_non_aliased_actions():
process = exec_test_command(["linode-cli", "linodes", "list", "--help"])
output = process.stdout.decode()
output = exec_test_command(["linode-cli", "linodes", "list", "--help"])
wrapped_output = textwrap.fill(output, width=180).replace("\n", "")

assert contains_at_least_one_of(
Expand All @@ -22,8 +21,8 @@ def test_help_page_for_non_aliased_actions():
assert contains_at_least_one_of(
wrapped_output,
[
"API Documentation: https://www.linode.com/docs/api/linode-instances/#linodes-list",
"API Documentation: https://techdocs.akamai.com/linode-api/reference/get-linode-instances",
"API Documentation:",
"https://techdocs.akamai.com/linode-api/reference/",
],
)

Expand All @@ -33,8 +32,7 @@ def test_help_page_for_non_aliased_actions():

@pytest.mark.smoke
def test_help_page_for_aliased_actions():
process = exec_test_command(["linode-cli", "linodes", "ls", "--help"])
output = process.stdout.decode()
output = exec_test_command(["linode-cli", "linodes", "ls", "--help"])
wrapped_output = textwrap.fill(output, width=180).replace("\n", "")

assert contains_at_least_one_of(
Expand All @@ -44,8 +42,8 @@ def test_help_page_for_aliased_actions():
assert contains_at_least_one_of(
wrapped_output,
[
"API Documentation: https://www.linode.com/docs/api/linode-instances/#linodes-list",
"API Documentation: https://techdocs.akamai.com/linode-api/reference/get-linode-instances",
"API Documentation:",
"https://techdocs.akamai.com/linode-api/reference/",
],
)

Expand All @@ -72,7 +70,7 @@ def test_debug_output_contains_request_url(monkeypatch: pytest.MonkeyPatch):
"12345",
"--debug",
]
).stderr.decode()
)
wrapped_output = textwrap.fill(output, width=180).replace("\n", "")

assert (
Expand Down
6 changes: 2 additions & 4 deletions tests/integration/cli/test_host_overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
def test_cli_command_fails_to_access_invalid_host(monkeypatch: MonkeyPatch):
monkeypatch.setenv("LINODE_CLI_API_HOST", INVALID_HOST)

process = exec_failing_test_command(
output = exec_failing_test_command(
["linode-cli", "linodes", "ls"], ExitCodes.UNRECOGNIZED_COMMAND
)
output = process.stderr.decode()

expected_output = ["Max retries exceeded with url:", "wrongapi.linode.com"]

Expand All @@ -32,9 +31,8 @@ def test_cli_command_fails_to_access_invalid_api_scheme(
monkeypatch: MonkeyPatch,
):
monkeypatch.setenv("LINODE_CLI_API_SCHEME", "ssh")
process = exec_failing_test_command(
output = exec_failing_test_command(
["linode-cli", "linodes", "ls"], ExitCodes.UNRECOGNIZED_COMMAND
)
output = process.stderr.decode()

assert "ssh://" in output
64 changes: 1 addition & 63 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def create_inbound_rule(ipv4_address, ipv6_address):
if is_valid_ipv4(ipv4_address) or is_valid_ipv6(ipv6_address):
command.extend(["--rules.inbound", inbound_rule])

firewall_id = exec_test_command(command).stdout.decode().rstrip()
firewall_id = exec_test_command(command)

yield firewall_id

Expand Down Expand Up @@ -201,68 +201,6 @@ def _generate_test_files(
return _generate_test_files


# test helper specific to Domains test suite
@pytest.fixture
def master_domain():
timestamp = str(time.time_ns())

domain_id = (
exec_test_command(
DOMAIN_BASE_CMD
+ [
"create",
"--type",
"master",
"--domain",
timestamp + "example.com",
"--soa_email",
"pthiel_test@linode.com",
"--text",
"--no-header",
"--format",
"id",
]
)
.stdout.decode()
.rstrip()
)

yield domain_id

delete_target_id("domains", id=domain_id)


@pytest.fixture
def slave_domain():
timestamp = str(time.time_ns())

domain_id = (
exec_test_command(
DOMAIN_BASE_CMD
+ [
"create",
"--type",
"slave",
"--domain",
timestamp + "-example.com",
"--master_ips",
"1.1.1.1",
"--text",
"--no-header",
"--delimiter",
",",
"--format=id",
]
)
.stdout.decode()
.rstrip()
)

yield domain_id

delete_target_id("domains", domain_id)


# Test helpers specific to Linodes test suite
@pytest.fixture
def linode_with_label(linode_cloud_firewall):
Expand Down
78 changes: 78 additions & 0 deletions tests/integration/database/fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import pytest

from tests.integration.helpers import (
BASE_CMDS,
delete_target_id,
exec_test_command,
get_random_text,
)


@pytest.fixture(scope="module")
def postgresql_cluster():
postgresql_database_label = get_random_text(5) + "_postgresql"

database_id = exec_test_command(
BASE_CMDS["databases"]
+ [
"postgresql-create",
"--type",
"g6-nanode-1",
"--region",
"us-ord",
"--label",
postgresql_database_label,
"--engine",
"postgresql/16",
"--text",
"--delimiter",
",",
"--no-headers",
"--format",
"id",
"--no-defaults",
"--format",
"id",
]
)

yield database_id

delete_target_id(
target="databases", delete_command="postgresql-delete", id=database_id
)


@pytest.fixture(scope="module")
def mysql_cluster():
mysql_database_label = get_random_text(5) + "_mysql"

database_id = exec_test_command(
BASE_CMDS["databases"]
+ [
"mysql-create",
"--type",
"g6-nanode-1",
"--region",
"us-ord",
"--label",
mysql_database_label,
"--engine",
"mysql/8",
"--text",
"--delimiter",
",",
"--no-headers",
"--format",
"id",
"--no-defaults",
"--format",
"id",
]
)

yield database_id

delete_target_id(
target="databases", delete_command="mysql-delete", id=database_id
)
36 changes: 36 additions & 0 deletions tests/integration/database/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from tests.integration.helpers import (
BASE_CMDS,
exec_test_command,
)


def get_db_type_id():
db_type_ids = exec_test_command(
BASE_CMDS["databases"]
+ [
"types",
"--text",
"--no-headers",
"--delimiter",
",",
"--format",
"id",
]
).splitlines()
return db_type_ids[0] if db_type_ids else None


def get_engine_id():
engine_ids = exec_test_command(
BASE_CMDS["databases"]
+ [
"engines",
"--text",
"--no-headers",
"--delimiter",
",",
"--format",
"id",
]
).splitlines()
return engine_ids[0] if engine_ids else None
Loading
Loading