Skip to content

Commit 35d3835

Browse files
authored
Restructure integration files and Refactor test fixtures and helpers (#786)
1 parent 0f7fc3f commit 35d3835

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+4016
-5065
lines changed

tests/integration/account/test_account.py

Lines changed: 110 additions & 197 deletions
Large diffs are not rendered by default.

tests/integration/beta/helpers.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import pytest
2+
3+
from tests.integration.helpers import (
4+
BASE_CMDS,
5+
exec_test_command,
6+
)
7+
8+
9+
def get_beta_id():
10+
beta_ids = exec_test_command(
11+
BASE_CMDS["betas"]
12+
+ [
13+
"list",
14+
"--text",
15+
"--no-headers",
16+
"--delimiter",
17+
",",
18+
"--format",
19+
"id",
20+
]
21+
).splitlines()
22+
if not beta_ids or beta_ids == [""]:
23+
pytest.skip("No betas available to test.")
24+
25+
return beta_ids[0] if beta_ids else None

tests/integration/beta/test_beta_program.py

Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import pytest
22

3-
from tests.integration.helpers import assert_headers_in_lines, exec_test_command
4-
5-
BASE_CMD = ["linode-cli", "betas"]
3+
from tests.integration.beta.helpers import get_beta_id
4+
from tests.integration.helpers import (
5+
BASE_CMDS,
6+
assert_headers_in_lines,
7+
exec_test_command,
8+
)
69

710

811
def test_beta_list():
9-
res = (
10-
exec_test_command(BASE_CMD + ["list", "--text", "--delimiter=,"])
11-
.stdout.decode()
12-
.rstrip()
12+
res = exec_test_command(
13+
BASE_CMDS["betas"] + ["list", "--text", "--delimiter=,"]
1314
)
1415
lines = res.splitlines()
1516

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

2223

23-
@pytest.fixture
24-
def get_beta_id():
25-
beta_ids = (
26-
exec_test_command(
27-
BASE_CMD
28-
+ [
29-
"list",
30-
"--text",
31-
"--no-headers",
32-
"--delimiter",
33-
",",
34-
"--format",
35-
"id",
36-
]
37-
)
38-
.stdout.decode()
39-
.rstrip()
40-
.splitlines()
41-
)
42-
if not beta_ids or beta_ids == [""]:
43-
pytest.skip("No betas available to test.")
44-
45-
first_id = beta_ids[0]
46-
yield first_id
47-
48-
49-
def test_beta_view(get_beta_id):
50-
beta_id = get_beta_id
24+
def test_beta_view():
25+
beta_id = get_beta_id()
5126
if beta_id is None:
5227
pytest.skip("No beta program available to test")
5328
else:
54-
res = (
55-
exec_test_command(
56-
BASE_CMD + ["view", beta_id, "--text", "--delimiter=,"]
57-
)
58-
.stdout.decode()
59-
.rstrip()
29+
res = exec_test_command(
30+
BASE_CMDS["betas"] + ["view", beta_id, "--text", "--delimiter=,"]
6031
)
6132
lines = res.splitlines()
6233
headers = ["label", "description"]
6334
assert_headers_in_lines(headers, lines)
6435

6536

6637
def test_beta_enrolled():
67-
res = (
68-
exec_test_command(BASE_CMD + ["enrolled", "--text", "--delimiter=,"])
69-
.stdout.decode()
70-
.rstrip()
38+
res = exec_test_command(
39+
BASE_CMDS["betas"] + ["enrolled", "--text", "--delimiter=,"]
7140
)
7241
lines = res.splitlines()
7342

tests/integration/cli/test_help.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

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

1817
assert contains_at_least_one_of(
@@ -22,8 +21,8 @@ def test_help_page_for_non_aliased_actions():
2221
assert contains_at_least_one_of(
2322
wrapped_output,
2423
[
25-
"API Documentation: https://techdocs.akamai.com/linode-api/reference/get-linode",
26-
"API Documentation: https://techdocs.akamai.com/linode-api/reference/get-linode-instances",
24+
"API Documentation:",
25+
"https://techdocs.akamai.com/linode-api/reference/",
2726
],
2827
)
2928

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

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

4038
assert contains_at_least_one_of(
@@ -44,8 +42,8 @@ def test_help_page_for_aliased_actions():
4442
assert contains_at_least_one_of(
4543
wrapped_output,
4644
[
47-
"API Documentation: https://techdocs.akamai.com/linode-api/reference/get-linode",
48-
"API Documentation: https://techdocs.akamai.com/linode-api/reference/get-linode-instances",
45+
"API Documentation:",
46+
"https://techdocs.akamai.com/linode-api/reference/",
4947
],
5048
)
5149

@@ -72,7 +70,7 @@ def test_debug_output_contains_request_url(monkeypatch: pytest.MonkeyPatch):
7270
"12345",
7371
"--debug",
7472
]
75-
).stderr.decode()
73+
)
7674
wrapped_output = textwrap.fill(output, width=180).replace("\n", "")
7775

7876
assert (

tests/integration/cli/test_host_overrides.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
def test_cli_command_fails_to_access_invalid_host(monkeypatch: MonkeyPatch):
1010
monkeypatch.setenv("LINODE_CLI_API_HOST", INVALID_HOST)
1111

12-
process = exec_failing_test_command(
12+
output = exec_failing_test_command(
1313
["linode-cli", "linodes", "ls"], ExitCodes.UNRECOGNIZED_COMMAND
1414
)
15-
output = process.stderr.decode()
1615

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

@@ -32,9 +31,8 @@ def test_cli_command_fails_to_access_invalid_api_scheme(
3231
monkeypatch: MonkeyPatch,
3332
):
3433
monkeypatch.setenv("LINODE_CLI_API_SCHEME", "ssh")
35-
process = exec_failing_test_command(
34+
output = exec_failing_test_command(
3635
["linode-cli", "linodes", "ls"], ExitCodes.UNRECOGNIZED_COMMAND
3736
)
38-
output = process.stderr.decode()
3937

4038
assert "ssh://" in output

0 commit comments

Comments
 (0)