1+ from linodecli .exit_codes import ExitCodes
12from 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
71142def 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
80151def 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):
156229def 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