Skip to content

Commit 9cb93b2

Browse files
committed
Updates commands and improves test scripts
1 parent 98e0017 commit 9cb93b2

File tree

3 files changed

+183
-102
lines changed

3 files changed

+183
-102
lines changed

tests/integration/helpers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
"domains",
2929
"events",
3030
"image",
31-
"image-upload",
3231
"images",
32+
"image-sharegroups",
33+
"image-upload",
3334
"firewalls",
3435
"kernels",
3536
"linodes",
Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,54 @@
1+
import jwt
12
import pytest
23

34
from tests.integration.helpers import (
45
BASE_CMDS,
5-
delete_target_id,
6-
exec_test_command,
6+
exec_test_command, get_random_text,
77
)
88

99

10-
@pytest.fixture(scope="function")
11-
def create_image():
12-
image_id = exec_test_command(
13-
BASE_CMDS["images"] + ["create", "--label", "testLabel", "--description", "Test description", "--disk_id"]
14-
)
15-
16-
yield image_id
17-
18-
delete_target_id(target="images", id=image_id)
10+
@pytest.fixture
11+
def get_region():
12+
regions = exec_test_command(
13+
BASE_CMDS["regions"] + ["list", "--text", "--no-headers", "--delimiter", ",", "--format", "id"]
14+
).splitlines()
15+
first_id = regions[0]
16+
yield first_id
1917

2018

2119
@pytest.fixture(scope="function")
22-
def create_share_group():
23-
image_id = exec_test_command(
24-
BASE_CMDS["images"] + ["create", "--label", "testLabel", "--description", "Test description", "--disk_id"]
20+
def create_image_id(get_region):
21+
linode_id = exec_test_command(
22+
BASE_CMDS["linodes"] + ["create", "--image", "linode/alpine3.22", "--region", get_region, "--type",
23+
"g6-nanode-1", "--root_pass", "aComplex@Password", "--text", "--no-headers",
24+
"--delimiter", ",", "--format", "id"]
2525
)
26-
27-
share_group_id = exec_test_command(
28-
BASE_CMDS["images"]
29-
+ ["sharegroups", "create", "--label", "my_label", "--description", "my_description", "--images",
30-
f'[{{"id": {image_id}, "label": "Linux Debian", "description": "Official Debian Linux image '
31-
'for server deployment"}]', "--delimiter", ",", "--text", "--no-headers"]
26+
disks = exec_test_command(
27+
BASE_CMDS["linodes"] + ["disks-list", linode_id, "--text", "--no-headers", "--delimiter", ",", "--format", "id"]
28+
).splitlines()
29+
image_id = exec_test_command(
30+
BASE_CMDS["images"] + ["create", "--label", "linode-cli-test-image-sharing-image", "--disk_id", disks[0],
31+
"--text", "--no-headers", "--delimiter", ",", "--format", "id"]
3232
)
33+
# TODO: wait_for_status
34+
yield linode_id, image_id
3335

34-
yield share_group_id, "uid"
3536

36-
delete_target_id(target="images", id=image_id)
37+
@pytest.fixture(scope="function")
38+
def create_share_group():
39+
label = get_random_text(8) + "_sharegroup_cli_test"
40+
share_group = exec_test_command(
41+
BASE_CMDS["image-sharegroups"] + ["create", "--label", label, "--text", "--no-headers", "--delimiter", ",",
42+
"--format", "id,uuid"]
43+
).split(",")
44+
yield share_group[0], share_group[1]
3745

3846

3947
@pytest.fixture(scope="function")
4048
def create_token():
41-
token_id = exec_test_command(
42-
BASE_CMDS["images"] + ["create", "--label", "testLabel", "--description", "Test description", "--disk_id"]
49+
label = get_random_text(8) + "_sharegroup_cli_test"
50+
created_token = exec_test_command(
51+
BASE_CMDS["profile"] + ["token-create", "--label", label, "--text", "--no-headers", "--delimiter", ",",
52+
"--format", "token"]
4353
)
44-
45-
yield token_id
46-
47-
delete_target_id(target="images", id=token_id)
54+
yield jwt.encode({"some": "payload"}, created_token, algorithm="HS256")
Lines changed: 146 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,177 @@
1+
from linodecli.exit_codes import ExitCodes
12
from tests.integration.helpers import (
3+
assert_headers_in_lines,
24
BASE_CMDS,
3-
exec_test_command,
5+
delete_target_id,
6+
exec_test_command, get_random_text, exec_failing_test_command,
7+
)
8+
from tests.integration.sharegroups.fixtures import (
9+
create_image_id,
10+
create_share_group,
11+
get_region,
12+
create_token,
413
)
514

6-
7-
def test_list_all_share_groups():
8-
result = exec_test_command(
9-
BASE_CMDS["images"] + ["sharegroups", "list", "--delimiter", ",", "--text", "--no-headers"]
10-
)
11-
assert "is_shared" in result
12-
assert "image_sharing" in result
13-
14-
15-
def test_list_all_owned_groups_with_shared_images(create_image):
16-
image_id = create_image[0]
17-
result = exec_test_command(
18-
BASE_CMDS["images"] + [image_id, "sharegroups", "list", "--delimiter", ",", "--text", "--no-headers"]
19-
)
20-
assert "data" in result
21-
22-
23-
def test_add_image_to_share_group_list_images(create_share_group):
24-
share_group_id = create_share_group[0]
25-
result = exec_test_command(
26-
BASE_CMDS["images"] + ["sharegroups", share_group_id, "images", "add", "--delimiter", ",", "--text",
27-
"--no-headers"]
28-
)
29-
assert "sharegroup_id" in result
30-
result = exec_test_command(
31-
BASE_CMDS["images"] + ["sharegroups", share_group_id, "images", "list", "--delimiter", ",", "--text",
32-
"--no-headers"]
33-
)
34-
assert "sharegroup_id" in result
15+
# def test_help_image_sharegroups():
16+
# output = exec_test_command(
17+
# BASE_CMDS["image-sharegroups"] + ["--help", "--text", "--delimiter=,"]
18+
# )
19+
# actions = [
20+
# "create",
21+
# "delete",
22+
# "image-add",
23+
# "image-remove",
24+
# "image-update",
25+
# "images-list",
26+
# "images-list-by-token",
27+
# "list, ls",
28+
# "member-add",
29+
# "member-delete",
30+
# "member-update",
31+
# "member-view",
32+
# "members-list",
33+
# "token-create",
34+
# "token-delete",
35+
# "token-update",
36+
# "token-view",
37+
# "tokens-list",
38+
# "update",
39+
# "view",
40+
# "view-by-token"
41+
# ]
42+
# assert_help_actions_list(actions, output)
3543

3644

37-
def test_add_and_list_share_group_member(create_share_group):
38-
share_group_id = create_share_group[0]
39-
result = exec_test_command(
40-
BASE_CMDS["images"] + ["sharegroups", share_group_id, "members", "add", "--token", "abc123", "--label",
41-
"my_sharegroup_member", "--delimiter", ",", "--text", "--no-headers"]
42-
)
43-
assert "token_uuid" in result
45+
def test_list_all_share_groups():
4446
result = exec_test_command(
45-
BASE_CMDS["images"] + ["sharegroups", share_group_id, "members", "list", "--delimiter", ",", "--text",
46-
"--no-headers"]
47-
)
48-
assert "token_uuid" in result
49-
47+
BASE_CMDS["image-sharegroups"] + ["list", "--delimiter", ",", "--text"]
48+
)
49+
lines = result.splitlines()
50+
headers = ["id", "label", "uuid", "description", "is_suspended", "images_count", "members_count"]
51+
assert_headers_in_lines(headers, lines)
52+
53+
54+
def test_list_all_owned_groups_with_shared_images():
55+
result = exec_test_command(
56+
BASE_CMDS["image-sharegroups"] + ["list", "--delimiter", ",", "--text"]
57+
).splitlines()
58+
headers = ["id", "label", "uuid", "description", "is_suspended", "images_count", "members_count"]
59+
assert_headers_in_lines(headers, result)
60+
61+
62+
def test_add_image_to_share_group_list_images(create_share_group, create_image_id):
63+
result_add_image = exec_test_command(
64+
BASE_CMDS["image-sharegroups"] + ["image-add", "--images.id", create_image_id[1], create_share_group[0],
65+
"--delimiter", ",", "--text"]
66+
).splitlines()
67+
headers = ["id", "label", "description", "size", "total_size", "capabilities", "is_public", "is_shared", "tags"]
68+
assert_headers_in_lines(headers, result_add_image)
69+
assert "linode-cli-test-image-sharing-image" in result_add_image[1]
70+
71+
result_list = exec_test_command(
72+
BASE_CMDS["image-sharegroups"] + ["images-list", create_share_group[0], "--delimiter", ",", "--text"]
73+
).splitlines()
74+
headers = ["id", "label", "description", "size", "total_size", "capabilities", "is_public", "is_shared", "tags"]
75+
assert_headers_in_lines(headers, result_list)
76+
assert "linode-cli-test-image-sharing-image" in result_list[1]
77+
78+
delete_target_id(target="image-sharegroups", id=create_share_group[0])
79+
delete_target_id(target="images", id=create_image_id[1])
80+
delete_target_id(target="linodes", id=create_image_id[0])
81+
82+
83+
def test_add_and_list_share_group_member(create_token, create_share_group):
84+
result_add = exec_test_command(
85+
BASE_CMDS["image-sharegroups"] + ["member-add", "--token", create_token, "--label", "test add member",
86+
create_share_group[0], "--delimiter", ",", "--text"]
87+
).splitlines()
88+
headers = ["id", "label", "uuid", "description", "is_suspended", "images_count", "members_count"]
89+
assert_headers_in_lines(headers, result_add)
90+
assert "token_uuid" in result_add[1]
91+
assert create_token in result_add[1]
92+
93+
result_list = exec_test_command(
94+
BASE_CMDS["image-sharegroups"] + ["members-list", create_share_group[0], "members", "list", "--delimiter", ",",
95+
"--text"]
96+
).splitlines()
97+
headers = ["id", "label", "uuid", "description", "is_suspended", "images_count", "members_count"]
98+
assert_headers_in_lines(headers, result_list)
99+
assert "token_uuid" in result_list[1]
100+
assert "Test create" in result_list[1]
101+
102+
delete_target_id(target="profile", id=create_token)
103+
delete_target_id(target="image-sharegroups", id=create_share_group[0])
104+
105+
106+
def test_create_read_update_delete_share_group():
107+
group_label = get_random_text(8) + "_sharegroup_cli_test"
108+
create_result = exec_test_command(
109+
BASE_CMDS["image-sharegroups"] + ["create", "--label", group_label, "--description", "Test create",
110+
"--delimiter", ",", "--text"]
111+
).splitlines()
112+
headers = ["id", "label", "uuid", "description", "is_suspended", "images_count", "members_count"]
113+
assert_headers_in_lines(headers, create_result)
114+
assert group_label in create_result[1]
115+
assert "Test create" in create_result[1]
116+
share_group_id = create_result[1].split(",")[0]
117+
118+
get_result = exec_test_command(
119+
BASE_CMDS["image-sharegroups"] + ["view", share_group_id, "--delimiter", ",", "--text"]
120+
).splitlines()
121+
assert_headers_in_lines(headers, get_result)
122+
assert group_label in get_result[1]
123+
124+
update_result = exec_test_command(
125+
BASE_CMDS["image-sharegroups"] + ["update", "--description", "Description update", "--label", group_label +
126+
"_updated", share_group_id, "--delimiter", ",", "--text"]
127+
).splitlines()
128+
assert_headers_in_lines(headers, update_result)
129+
assert group_label + "_updated" in update_result[1]
130+
assert "Description update" in update_result[1]
50131

51-
def test_create_read_update_delete_share_group(create_share_group):
52-
share_group_id = create_share_group[0]
53-
result = exec_test_command(
54-
BASE_CMDS["images"] + ["sharegroups", "view", share_group_id, "--delimiter", ",", "--text", "--no-headers"]
55-
)
56-
assert "id" + share_group_id in result
57-
result = exec_test_command(
58-
BASE_CMDS["images"] + ["sharegroups", "update", share_group_id, "--label", "new_label", "--description",
59-
"A new description.", "--delimiter", ",", "--text", "--no-headers"]
60-
)
61-
assert "label" in result
62132
exec_test_command(
63-
BASE_CMDS["images"] + ["sharegroups", "delete", share_group_id, "--delimiter", ",", "--text", "--no-headers"]
133+
BASE_CMDS["image-sharegroups"] + ["delete", share_group_id]
64134
)
65-
result = exec_test_command(
66-
BASE_CMDS["images"] + ["sharegroups", "view", share_group_id, "--delimiter", ",", "--text", "--no-headers"]
135+
result_after_delete = exec_failing_test_command(
136+
BASE_CMDS["image-sharegroups"] + ["view", share_group_id, "--delimiter", ",", "--text"],
137+
expected_code=ExitCodes.REQUEST_FAILED
67138
)
68-
assert "Request failed: 400" in result
139+
assert "Request failed: 403" in result_after_delete
69140

70141

71142
def test_create_token(create_share_group):
72143
share_group_uuid = create_share_group[1]
73144
result = exec_test_command(
74145
BASE_CMDS["images"] + ["sharegroups", "tokens", "create", "--label", "my_token", "--valid_for_sharegroup_uuid",
75-
share_group_uuid, "--delimiter", ",", "--text", "--no-headers"]
146+
share_group_uuid, "--delimiter", ",", "--text"]
76147
)
77148
assert "token_uuid" in result
78149

79150

80151
def test_get_details_about_all_the_users_tokens():
81152
result = exec_test_command(
82-
BASE_CMDS["images"] + ["sharegroups", "tokens", "list", "--delimiter", ",", "--text", "--no-headers"]
153+
BASE_CMDS["image-sharegroups"] + ["tokens-list", "--delimiter", ",", "--text"]
83154
)
84-
assert "token_uuid" in result
155+
lines = result.splitlines()
156+
headers = ["token_uuid", "label", "status", "valid_for_sharegroup_uuid", "sharegroup_uuid", "sharegroup_label"]
157+
assert_headers_in_lines(headers, lines)
85158

86159

87-
def test_update_and_revoke_access_to_shared_image(create_image, create_share_group):
88-
image_id = create_image[0]
160+
def test_update_and_revoke_access_to_shared_image(create_image_id, create_share_group):
161+
image_id = create_image_id[0]
89162
share_group_id = create_share_group[0]
90163
result = exec_test_command(
91164
BASE_CMDS["images"] + ["sharegroups", share_group_id, "images", "update", image_id, "--label", "new_label",
92-
"--description", "A new description.", "--delimiter", ",", "--text", "--no-headers"]
165+
"--description", "A new description.", "--delimiter", ",", "--text"]
93166
)
94167
assert "image_sharing" in result
95168
exec_test_command(
96169
BASE_CMDS["images"] + ["sharegroups", share_group_id, "images", "remove", image_id, "--delimiter", ",",
97-
"--text", "--no-headers"]
170+
"--text"]
98171
)
99172
result = exec_test_command(
100173
BASE_CMDS["images"] + ["sharegroups", share_group_id, "images", "update", image_id, "--label", "new_label",
101-
"--description", "A new description.", "--delimiter", ",", "--text", "--no-headers"]
174+
"--description", "A new description.", "--delimiter", ",", "--text"]
102175
)
103176
assert "Request failed: 400" in result
104177

@@ -114,7 +187,7 @@ def test_get_and_revoke_membership_token_details(create_share_group, create_toke
114187
token_id = create_token[0]
115188
exec_test_command(
116189
BASE_CMDS["images"] + ["sharegroups", share_group_id, "members", "delete", token_id, "--delimiter", ",",
117-
"--text", "--no-headers"]
190+
"--text"]
118191
)
119192
result = exec_test_command(
120193
BASE_CMDS["images"] + ["sharegroups", share_group_id, "members", "view", token_id, "--delimiter", ",", "--text",
@@ -123,13 +196,13 @@ def test_get_and_revoke_membership_token_details(create_share_group, create_toke
123196
assert "Request failed: 400" in result
124197

125198

126-
def test_create_and_update_membership_token(create_image, create_share_group, create_token):
127-
image_id = create_image[0]
199+
def test_create_and_update_membership_token(create_image_id, create_share_group, create_token):
200+
image_id = create_image_id[0]
128201
share_group_id = create_share_group[0]
129202
token_id = create_token[0]
130203
result = exec_test_command(
131204
BASE_CMDS["images"] + [image_id, "sharegroups", share_group_id, "members", "update", token_id, "--label",
132-
"new_label", "--delimiter", ",", "--text", "--no-headers"]
205+
"new_label", "--delimiter", ",", "--text"]
133206
)
134207
assert "label" in result
135208

@@ -138,7 +211,7 @@ def test_list_all_shared_images(create_token):
138211
token_id = create_token[0]
139212
result = exec_test_command(
140213
BASE_CMDS["images"] + ["sharegroups", "tokens", token_id, "sharegroup", "images", "list", "--delimiter", ",",
141-
"--text", "--no-headers"]
214+
"--text"]
142215
)
143216
assert "data" in result
144217
assert "image_sharing" in result
@@ -156,19 +229,19 @@ def test_gets_details_about_your_share_group(create_token):
156229
def test_get_update_remove_membership_for_token(create_token):
157230
token_id = create_token[0]
158231
result = exec_test_command(
159-
BASE_CMDS["images"] + ["sharegroups", "tokens", "view", token_id, "--delimiter", ",", "--text", "--no-headers"]
232+
BASE_CMDS["images"] + ["sharegroups", "tokens", "view", token_id, "--delimiter", ",", "--text"]
160233
)
161234
assert "sharegroup_uuid" in result
162235
result = exec_test_command(
163236
BASE_CMDS["images"] + ["sharegroups", "tokens", "update", token_id, "--label", "new_label", "--delimiter", ",",
164-
"--text", "--no-headers"]
237+
"--text"]
165238
)
166239
assert "label" in result
167240
exec_test_command(
168241
BASE_CMDS["images"] + ["sharegroups", "tokens", "delete", token_id, "--delimiter", ",", "--text",
169242
"--no-headers"]
170243
)
171244
result = exec_test_command(
172-
BASE_CMDS["images"] + ["sharegroups", "tokens", "view", token_id, "--delimiter", ",", "--text", "--no-headers"]
245+
BASE_CMDS["images"] + ["sharegroups", "tokens", "view", token_id, "--delimiter", ",", "--text"]
173246
)
174247
assert "Request failed: 400" in result

0 commit comments

Comments
 (0)