From 98e0017d65c45e02fd7abf916c4dc3d061671efa Mon Sep 17 00:00:00 2001 From: Pawel Snoch Date: Thu, 30 Oct 2025 12:06:59 +0100 Subject: [PATCH 1/5] Adds tests draft for sharegroups feature --- tests/integration/helpers.py | 1 + tests/integration/sharegroups/fixtures.py | 47 +++++ .../sharegroups/test_images_sharegroups.py | 174 ++++++++++++++++++ 3 files changed, 222 insertions(+) create mode 100644 tests/integration/sharegroups/fixtures.py create mode 100644 tests/integration/sharegroups/test_images_sharegroups.py diff --git a/tests/integration/helpers.py b/tests/integration/helpers.py index 35a8a22fe..86951797d 100644 --- a/tests/integration/helpers.py +++ b/tests/integration/helpers.py @@ -29,6 +29,7 @@ "events", "image", "image-upload", + "images", "firewalls", "kernels", "linodes", diff --git a/tests/integration/sharegroups/fixtures.py b/tests/integration/sharegroups/fixtures.py new file mode 100644 index 000000000..66907664c --- /dev/null +++ b/tests/integration/sharegroups/fixtures.py @@ -0,0 +1,47 @@ +import pytest + +from tests.integration.helpers import ( + BASE_CMDS, + delete_target_id, + exec_test_command, +) + + +@pytest.fixture(scope="function") +def create_image(): + image_id = exec_test_command( + BASE_CMDS["images"] + ["create", "--label", "testLabel", "--description", "Test description", "--disk_id"] + ) + + yield image_id + + delete_target_id(target="images", id=image_id) + + +@pytest.fixture(scope="function") +def create_share_group(): + image_id = exec_test_command( + BASE_CMDS["images"] + ["create", "--label", "testLabel", "--description", "Test description", "--disk_id"] + ) + + share_group_id = exec_test_command( + BASE_CMDS["images"] + + ["sharegroups", "create", "--label", "my_label", "--description", "my_description", "--images", + f'[{{"id": {image_id}, "label": "Linux Debian", "description": "Official Debian Linux image ' + 'for server deployment"}]', "--delimiter", ",", "--text", "--no-headers"] + ) + + yield share_group_id, "uid" + + delete_target_id(target="images", id=image_id) + + +@pytest.fixture(scope="function") +def create_token(): + token_id = exec_test_command( + BASE_CMDS["images"] + ["create", "--label", "testLabel", "--description", "Test description", "--disk_id"] + ) + + yield token_id + + delete_target_id(target="images", id=token_id) diff --git a/tests/integration/sharegroups/test_images_sharegroups.py b/tests/integration/sharegroups/test_images_sharegroups.py new file mode 100644 index 000000000..ed7461261 --- /dev/null +++ b/tests/integration/sharegroups/test_images_sharegroups.py @@ -0,0 +1,174 @@ +from tests.integration.helpers import ( + BASE_CMDS, + exec_test_command, +) + + +def test_list_all_share_groups(): + result = exec_test_command( + BASE_CMDS["images"] + ["sharegroups", "list", "--delimiter", ",", "--text", "--no-headers"] + ) + assert "is_shared" in result + assert "image_sharing" in result + + +def test_list_all_owned_groups_with_shared_images(create_image): + image_id = create_image[0] + result = exec_test_command( + BASE_CMDS["images"] + [image_id, "sharegroups", "list", "--delimiter", ",", "--text", "--no-headers"] + ) + assert "data" in result + + +def test_add_image_to_share_group_list_images(create_share_group): + share_group_id = create_share_group[0] + result = exec_test_command( + BASE_CMDS["images"] + ["sharegroups", share_group_id, "images", "add", "--delimiter", ",", "--text", + "--no-headers"] + ) + assert "sharegroup_id" in result + result = exec_test_command( + BASE_CMDS["images"] + ["sharegroups", share_group_id, "images", "list", "--delimiter", ",", "--text", + "--no-headers"] + ) + assert "sharegroup_id" in result + + +def test_add_and_list_share_group_member(create_share_group): + share_group_id = create_share_group[0] + result = exec_test_command( + BASE_CMDS["images"] + ["sharegroups", share_group_id, "members", "add", "--token", "abc123", "--label", + "my_sharegroup_member", "--delimiter", ",", "--text", "--no-headers"] + ) + assert "token_uuid" in result + result = exec_test_command( + BASE_CMDS["images"] + ["sharegroups", share_group_id, "members", "list", "--delimiter", ",", "--text", + "--no-headers"] + ) + assert "token_uuid" in result + + +def test_create_read_update_delete_share_group(create_share_group): + share_group_id = create_share_group[0] + result = exec_test_command( + BASE_CMDS["images"] + ["sharegroups", "view", share_group_id, "--delimiter", ",", "--text", "--no-headers"] + ) + assert "id" + share_group_id in result + result = exec_test_command( + BASE_CMDS["images"] + ["sharegroups", "update", share_group_id, "--label", "new_label", "--description", + "A new description.", "--delimiter", ",", "--text", "--no-headers"] + ) + assert "label" in result + exec_test_command( + BASE_CMDS["images"] + ["sharegroups", "delete", share_group_id, "--delimiter", ",", "--text", "--no-headers"] + ) + result = exec_test_command( + BASE_CMDS["images"] + ["sharegroups", "view", share_group_id, "--delimiter", ",", "--text", "--no-headers"] + ) + assert "Request failed: 400" in result + + +def test_create_token(create_share_group): + share_group_uuid = create_share_group[1] + result = exec_test_command( + BASE_CMDS["images"] + ["sharegroups", "tokens", "create", "--label", "my_token", "--valid_for_sharegroup_uuid", + share_group_uuid, "--delimiter", ",", "--text", "--no-headers"] + ) + assert "token_uuid" in result + + +def test_get_details_about_all_the_users_tokens(): + result = exec_test_command( + BASE_CMDS["images"] + ["sharegroups", "tokens", "list", "--delimiter", ",", "--text", "--no-headers"] + ) + assert "token_uuid" in result + + +def test_update_and_revoke_access_to_shared_image(create_image, create_share_group): + image_id = create_image[0] + share_group_id = create_share_group[0] + result = exec_test_command( + BASE_CMDS["images"] + ["sharegroups", share_group_id, "images", "update", image_id, "--label", "new_label", + "--description", "A new description.", "--delimiter", ",", "--text", "--no-headers"] + ) + assert "image_sharing" in result + exec_test_command( + BASE_CMDS["images"] + ["sharegroups", share_group_id, "images", "remove", image_id, "--delimiter", ",", + "--text", "--no-headers"] + ) + result = exec_test_command( + BASE_CMDS["images"] + ["sharegroups", share_group_id, "images", "update", image_id, "--label", "new_label", + "--description", "A new description.", "--delimiter", ",", "--text", "--no-headers"] + ) + assert "Request failed: 400" in result + + +def test_get_and_revoke_membership_token_details(create_share_group, create_token): + share_group_id = create_share_group[0] + token_id = create_token[0] + result = exec_test_command( + BASE_CMDS["images"] + ["sharegroups", share_group_id, "members", "view", token_id, "--delimiter", ",", "--text", + "--no-headers"] + ) + assert "token_uuid" in result + token_id = create_token[0] + exec_test_command( + BASE_CMDS["images"] + ["sharegroups", share_group_id, "members", "delete", token_id, "--delimiter", ",", + "--text", "--no-headers"] + ) + result = exec_test_command( + BASE_CMDS["images"] + ["sharegroups", share_group_id, "members", "view", token_id, "--delimiter", ",", "--text", + "--no-headers"] + ) + assert "Request failed: 400" in result + + +def test_create_and_update_membership_token(create_image, create_share_group, create_token): + image_id = create_image[0] + share_group_id = create_share_group[0] + token_id = create_token[0] + result = exec_test_command( + BASE_CMDS["images"] + [image_id, "sharegroups", share_group_id, "members", "update", token_id, "--label", + "new_label", "--delimiter", ",", "--text", "--no-headers"] + ) + assert "label" in result + + +def test_list_all_shared_images(create_token): + token_id = create_token[0] + result = exec_test_command( + BASE_CMDS["images"] + ["sharegroups", "tokens", token_id, "sharegroup", "images", "list", "--delimiter", ",", + "--text", "--no-headers"] + ) + assert "data" in result + assert "image_sharing" in result + + +def test_gets_details_about_your_share_group(create_token): + token_id = create_token[0] + result = exec_test_command( + BASE_CMDS["images"] + ["sharegroups", "tokens", token_id, "sharegroup", "view", "--delimiter", ",", "--text", + "--no-headers"] + ) + assert "sharegroup_uuid" in result + + +def test_get_update_remove_membership_for_token(create_token): + token_id = create_token[0] + result = exec_test_command( + BASE_CMDS["images"] + ["sharegroups", "tokens", "view", token_id, "--delimiter", ",", "--text", "--no-headers"] + ) + assert "sharegroup_uuid" in result + result = exec_test_command( + BASE_CMDS["images"] + ["sharegroups", "tokens", "update", token_id, "--label", "new_label", "--delimiter", ",", + "--text", "--no-headers"] + ) + assert "label" in result + exec_test_command( + BASE_CMDS["images"] + ["sharegroups", "tokens", "delete", token_id, "--delimiter", ",", "--text", + "--no-headers"] + ) + result = exec_test_command( + BASE_CMDS["images"] + ["sharegroups", "tokens", "view", token_id, "--delimiter", ",", "--text", "--no-headers"] + ) + assert "Request failed: 400" in result From 9cb93b25ef485ded942c27e97bce3a8dbec59d7f Mon Sep 17 00:00:00 2001 From: Pawel Snoch Date: Fri, 7 Nov 2025 22:34:45 +0100 Subject: [PATCH 2/5] Updates commands and improves test scripts --- tests/integration/helpers.py | 3 +- tests/integration/sharegroups/fixtures.py | 63 ++--- .../sharegroups/test_images_sharegroups.py | 219 ++++++++++++------ 3 files changed, 183 insertions(+), 102 deletions(-) diff --git a/tests/integration/helpers.py b/tests/integration/helpers.py index 86951797d..c085c04af 100644 --- a/tests/integration/helpers.py +++ b/tests/integration/helpers.py @@ -28,8 +28,9 @@ "domains", "events", "image", - "image-upload", "images", + "image-sharegroups", + "image-upload", "firewalls", "kernels", "linodes", diff --git a/tests/integration/sharegroups/fixtures.py b/tests/integration/sharegroups/fixtures.py index 66907664c..e2838e9bd 100644 --- a/tests/integration/sharegroups/fixtures.py +++ b/tests/integration/sharegroups/fixtures.py @@ -1,47 +1,54 @@ +import jwt import pytest from tests.integration.helpers import ( BASE_CMDS, - delete_target_id, - exec_test_command, + exec_test_command, get_random_text, ) -@pytest.fixture(scope="function") -def create_image(): - image_id = exec_test_command( - BASE_CMDS["images"] + ["create", "--label", "testLabel", "--description", "Test description", "--disk_id"] - ) - - yield image_id - - delete_target_id(target="images", id=image_id) +@pytest.fixture +def get_region(): + regions = exec_test_command( + BASE_CMDS["regions"] + ["list", "--text", "--no-headers", "--delimiter", ",", "--format", "id"] + ).splitlines() + first_id = regions[0] + yield first_id @pytest.fixture(scope="function") -def create_share_group(): - image_id = exec_test_command( - BASE_CMDS["images"] + ["create", "--label", "testLabel", "--description", "Test description", "--disk_id"] +def create_image_id(get_region): + linode_id = exec_test_command( + BASE_CMDS["linodes"] + ["create", "--image", "linode/alpine3.22", "--region", get_region, "--type", + "g6-nanode-1", "--root_pass", "aComplex@Password", "--text", "--no-headers", + "--delimiter", ",", "--format", "id"] ) - - share_group_id = exec_test_command( - BASE_CMDS["images"] - + ["sharegroups", "create", "--label", "my_label", "--description", "my_description", "--images", - f'[{{"id": {image_id}, "label": "Linux Debian", "description": "Official Debian Linux image ' - 'for server deployment"}]', "--delimiter", ",", "--text", "--no-headers"] + disks = exec_test_command( + BASE_CMDS["linodes"] + ["disks-list", linode_id, "--text", "--no-headers", "--delimiter", ",", "--format", "id"] + ).splitlines() + image_id = exec_test_command( + BASE_CMDS["images"] + ["create", "--label", "linode-cli-test-image-sharing-image", "--disk_id", disks[0], + "--text", "--no-headers", "--delimiter", ",", "--format", "id"] ) + # TODO: wait_for_status + yield linode_id, image_id - yield share_group_id, "uid" - delete_target_id(target="images", id=image_id) +@pytest.fixture(scope="function") +def create_share_group(): + label = get_random_text(8) + "_sharegroup_cli_test" + share_group = exec_test_command( + BASE_CMDS["image-sharegroups"] + ["create", "--label", label, "--text", "--no-headers", "--delimiter", ",", + "--format", "id,uuid"] + ).split(",") + yield share_group[0], share_group[1] @pytest.fixture(scope="function") def create_token(): - token_id = exec_test_command( - BASE_CMDS["images"] + ["create", "--label", "testLabel", "--description", "Test description", "--disk_id"] + label = get_random_text(8) + "_sharegroup_cli_test" + created_token = exec_test_command( + BASE_CMDS["profile"] + ["token-create", "--label", label, "--text", "--no-headers", "--delimiter", ",", + "--format", "token"] ) - - yield token_id - - delete_target_id(target="images", id=token_id) + yield jwt.encode({"some": "payload"}, created_token, algorithm="HS256") diff --git a/tests/integration/sharegroups/test_images_sharegroups.py b/tests/integration/sharegroups/test_images_sharegroups.py index ed7461261..307e41682 100644 --- a/tests/integration/sharegroups/test_images_sharegroups.py +++ b/tests/integration/sharegroups/test_images_sharegroups.py @@ -1,104 +1,177 @@ +from linodecli.exit_codes import ExitCodes from tests.integration.helpers import ( + assert_headers_in_lines, BASE_CMDS, - exec_test_command, + delete_target_id, + exec_test_command, get_random_text, exec_failing_test_command, +) +from tests.integration.sharegroups.fixtures import ( + create_image_id, + create_share_group, + get_region, + create_token, ) - -def test_list_all_share_groups(): - result = exec_test_command( - BASE_CMDS["images"] + ["sharegroups", "list", "--delimiter", ",", "--text", "--no-headers"] - ) - assert "is_shared" in result - assert "image_sharing" in result - - -def test_list_all_owned_groups_with_shared_images(create_image): - image_id = create_image[0] - result = exec_test_command( - BASE_CMDS["images"] + [image_id, "sharegroups", "list", "--delimiter", ",", "--text", "--no-headers"] - ) - assert "data" in result - - -def test_add_image_to_share_group_list_images(create_share_group): - share_group_id = create_share_group[0] - result = exec_test_command( - BASE_CMDS["images"] + ["sharegroups", share_group_id, "images", "add", "--delimiter", ",", "--text", - "--no-headers"] - ) - assert "sharegroup_id" in result - result = exec_test_command( - BASE_CMDS["images"] + ["sharegroups", share_group_id, "images", "list", "--delimiter", ",", "--text", - "--no-headers"] - ) - assert "sharegroup_id" in result +# def test_help_image_sharegroups(): +# output = exec_test_command( +# BASE_CMDS["image-sharegroups"] + ["--help", "--text", "--delimiter=,"] +# ) +# actions = [ +# "create", +# "delete", +# "image-add", +# "image-remove", +# "image-update", +# "images-list", +# "images-list-by-token", +# "list, ls", +# "member-add", +# "member-delete", +# "member-update", +# "member-view", +# "members-list", +# "token-create", +# "token-delete", +# "token-update", +# "token-view", +# "tokens-list", +# "update", +# "view", +# "view-by-token" +# ] +# assert_help_actions_list(actions, output) -def test_add_and_list_share_group_member(create_share_group): - share_group_id = create_share_group[0] - result = exec_test_command( - BASE_CMDS["images"] + ["sharegroups", share_group_id, "members", "add", "--token", "abc123", "--label", - "my_sharegroup_member", "--delimiter", ",", "--text", "--no-headers"] - ) - assert "token_uuid" in result +def test_list_all_share_groups(): result = exec_test_command( - BASE_CMDS["images"] + ["sharegroups", share_group_id, "members", "list", "--delimiter", ",", "--text", - "--no-headers"] - ) - assert "token_uuid" in result - + BASE_CMDS["image-sharegroups"] + ["list", "--delimiter", ",", "--text"] + ) + lines = result.splitlines() + headers = ["id", "label", "uuid", "description", "is_suspended", "images_count", "members_count"] + assert_headers_in_lines(headers, lines) + + +def test_list_all_owned_groups_with_shared_images(): + result = exec_test_command( + BASE_CMDS["image-sharegroups"] + ["list", "--delimiter", ",", "--text"] + ).splitlines() + headers = ["id", "label", "uuid", "description", "is_suspended", "images_count", "members_count"] + assert_headers_in_lines(headers, result) + + +def test_add_image_to_share_group_list_images(create_share_group, create_image_id): + result_add_image = exec_test_command( + BASE_CMDS["image-sharegroups"] + ["image-add", "--images.id", create_image_id[1], create_share_group[0], + "--delimiter", ",", "--text"] + ).splitlines() + headers = ["id", "label", "description", "size", "total_size", "capabilities", "is_public", "is_shared", "tags"] + assert_headers_in_lines(headers, result_add_image) + assert "linode-cli-test-image-sharing-image" in result_add_image[1] + + result_list = exec_test_command( + BASE_CMDS["image-sharegroups"] + ["images-list", create_share_group[0], "--delimiter", ",", "--text"] + ).splitlines() + headers = ["id", "label", "description", "size", "total_size", "capabilities", "is_public", "is_shared", "tags"] + assert_headers_in_lines(headers, result_list) + assert "linode-cli-test-image-sharing-image" in result_list[1] + + delete_target_id(target="image-sharegroups", id=create_share_group[0]) + delete_target_id(target="images", id=create_image_id[1]) + delete_target_id(target="linodes", id=create_image_id[0]) + + +def test_add_and_list_share_group_member(create_token, create_share_group): + result_add = exec_test_command( + BASE_CMDS["image-sharegroups"] + ["member-add", "--token", create_token, "--label", "test add member", + create_share_group[0], "--delimiter", ",", "--text"] + ).splitlines() + headers = ["id", "label", "uuid", "description", "is_suspended", "images_count", "members_count"] + assert_headers_in_lines(headers, result_add) + assert "token_uuid" in result_add[1] + assert create_token in result_add[1] + + result_list = exec_test_command( + BASE_CMDS["image-sharegroups"] + ["members-list", create_share_group[0], "members", "list", "--delimiter", ",", + "--text"] + ).splitlines() + headers = ["id", "label", "uuid", "description", "is_suspended", "images_count", "members_count"] + assert_headers_in_lines(headers, result_list) + assert "token_uuid" in result_list[1] + assert "Test create" in result_list[1] + + delete_target_id(target="profile", id=create_token) + delete_target_id(target="image-sharegroups", id=create_share_group[0]) + + +def test_create_read_update_delete_share_group(): + group_label = get_random_text(8) + "_sharegroup_cli_test" + create_result = exec_test_command( + BASE_CMDS["image-sharegroups"] + ["create", "--label", group_label, "--description", "Test create", + "--delimiter", ",", "--text"] + ).splitlines() + headers = ["id", "label", "uuid", "description", "is_suspended", "images_count", "members_count"] + assert_headers_in_lines(headers, create_result) + assert group_label in create_result[1] + assert "Test create" in create_result[1] + share_group_id = create_result[1].split(",")[0] + + get_result = exec_test_command( + BASE_CMDS["image-sharegroups"] + ["view", share_group_id, "--delimiter", ",", "--text"] + ).splitlines() + assert_headers_in_lines(headers, get_result) + assert group_label in get_result[1] + + update_result = exec_test_command( + BASE_CMDS["image-sharegroups"] + ["update", "--description", "Description update", "--label", group_label + + "_updated", share_group_id, "--delimiter", ",", "--text"] + ).splitlines() + assert_headers_in_lines(headers, update_result) + assert group_label + "_updated" in update_result[1] + assert "Description update" in update_result[1] -def test_create_read_update_delete_share_group(create_share_group): - share_group_id = create_share_group[0] - result = exec_test_command( - BASE_CMDS["images"] + ["sharegroups", "view", share_group_id, "--delimiter", ",", "--text", "--no-headers"] - ) - assert "id" + share_group_id in result - result = exec_test_command( - BASE_CMDS["images"] + ["sharegroups", "update", share_group_id, "--label", "new_label", "--description", - "A new description.", "--delimiter", ",", "--text", "--no-headers"] - ) - assert "label" in result exec_test_command( - BASE_CMDS["images"] + ["sharegroups", "delete", share_group_id, "--delimiter", ",", "--text", "--no-headers"] + BASE_CMDS["image-sharegroups"] + ["delete", share_group_id] ) - result = exec_test_command( - BASE_CMDS["images"] + ["sharegroups", "view", share_group_id, "--delimiter", ",", "--text", "--no-headers"] + result_after_delete = exec_failing_test_command( + BASE_CMDS["image-sharegroups"] + ["view", share_group_id, "--delimiter", ",", "--text"], + expected_code=ExitCodes.REQUEST_FAILED ) - assert "Request failed: 400" in result + assert "Request failed: 403" in result_after_delete def test_create_token(create_share_group): share_group_uuid = create_share_group[1] result = exec_test_command( BASE_CMDS["images"] + ["sharegroups", "tokens", "create", "--label", "my_token", "--valid_for_sharegroup_uuid", - share_group_uuid, "--delimiter", ",", "--text", "--no-headers"] + share_group_uuid, "--delimiter", ",", "--text"] ) assert "token_uuid" in result def test_get_details_about_all_the_users_tokens(): result = exec_test_command( - BASE_CMDS["images"] + ["sharegroups", "tokens", "list", "--delimiter", ",", "--text", "--no-headers"] + BASE_CMDS["image-sharegroups"] + ["tokens-list", "--delimiter", ",", "--text"] ) - assert "token_uuid" in result + lines = result.splitlines() + headers = ["token_uuid", "label", "status", "valid_for_sharegroup_uuid", "sharegroup_uuid", "sharegroup_label"] + assert_headers_in_lines(headers, lines) -def test_update_and_revoke_access_to_shared_image(create_image, create_share_group): - image_id = create_image[0] +def test_update_and_revoke_access_to_shared_image(create_image_id, create_share_group): + image_id = create_image_id[0] share_group_id = create_share_group[0] result = exec_test_command( BASE_CMDS["images"] + ["sharegroups", share_group_id, "images", "update", image_id, "--label", "new_label", - "--description", "A new description.", "--delimiter", ",", "--text", "--no-headers"] + "--description", "A new description.", "--delimiter", ",", "--text"] ) assert "image_sharing" in result exec_test_command( BASE_CMDS["images"] + ["sharegroups", share_group_id, "images", "remove", image_id, "--delimiter", ",", - "--text", "--no-headers"] + "--text"] ) result = exec_test_command( BASE_CMDS["images"] + ["sharegroups", share_group_id, "images", "update", image_id, "--label", "new_label", - "--description", "A new description.", "--delimiter", ",", "--text", "--no-headers"] + "--description", "A new description.", "--delimiter", ",", "--text"] ) assert "Request failed: 400" in result @@ -114,7 +187,7 @@ def test_get_and_revoke_membership_token_details(create_share_group, create_toke token_id = create_token[0] exec_test_command( BASE_CMDS["images"] + ["sharegroups", share_group_id, "members", "delete", token_id, "--delimiter", ",", - "--text", "--no-headers"] + "--text"] ) result = exec_test_command( 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 assert "Request failed: 400" in result -def test_create_and_update_membership_token(create_image, create_share_group, create_token): - image_id = create_image[0] +def test_create_and_update_membership_token(create_image_id, create_share_group, create_token): + image_id = create_image_id[0] share_group_id = create_share_group[0] token_id = create_token[0] result = exec_test_command( BASE_CMDS["images"] + [image_id, "sharegroups", share_group_id, "members", "update", token_id, "--label", - "new_label", "--delimiter", ",", "--text", "--no-headers"] + "new_label", "--delimiter", ",", "--text"] ) assert "label" in result @@ -138,7 +211,7 @@ def test_list_all_shared_images(create_token): token_id = create_token[0] result = exec_test_command( BASE_CMDS["images"] + ["sharegroups", "tokens", token_id, "sharegroup", "images", "list", "--delimiter", ",", - "--text", "--no-headers"] + "--text"] ) assert "data" in result assert "image_sharing" in result @@ -156,12 +229,12 @@ def test_gets_details_about_your_share_group(create_token): def test_get_update_remove_membership_for_token(create_token): token_id = create_token[0] result = exec_test_command( - BASE_CMDS["images"] + ["sharegroups", "tokens", "view", token_id, "--delimiter", ",", "--text", "--no-headers"] + BASE_CMDS["images"] + ["sharegroups", "tokens", "view", token_id, "--delimiter", ",", "--text"] ) assert "sharegroup_uuid" in result result = exec_test_command( BASE_CMDS["images"] + ["sharegroups", "tokens", "update", token_id, "--label", "new_label", "--delimiter", ",", - "--text", "--no-headers"] + "--text"] ) assert "label" in result exec_test_command( @@ -169,6 +242,6 @@ def test_get_update_remove_membership_for_token(create_token): "--no-headers"] ) result = exec_test_command( - BASE_CMDS["images"] + ["sharegroups", "tokens", "view", token_id, "--delimiter", ",", "--text", "--no-headers"] + BASE_CMDS["images"] + ["sharegroups", "tokens", "view", token_id, "--delimiter", ",", "--text"] ) assert "Request failed: 400" in result From 760c68eea79e5341d66a02f464420a757380580a Mon Sep 17 00:00:00 2001 From: Pawel Snoch Date: Fri, 14 Nov 2025 15:13:58 +0100 Subject: [PATCH 3/5] Improve and add missing tests for Private Image Sharing feature --- tests/integration/helpers.py | 2 +- tests/integration/sharegroups/fixtures.py | 32 +- .../sharegroups/test_images_sharegroups.py | 289 +++++++++--------- 3 files changed, 167 insertions(+), 156 deletions(-) diff --git a/tests/integration/helpers.py b/tests/integration/helpers.py index c085c04af..0b5540fad 100644 --- a/tests/integration/helpers.py +++ b/tests/integration/helpers.py @@ -210,6 +210,6 @@ def get_random_region_with_caps( def assert_help_actions_list(expected_actions, help_output): - output_actions = re.findall("\│\s(\S+)\s*\│", help_output) + output_actions = re.findall("\│\s(\S+(?:,\s)?\S+)\s*\│", help_output) for expected_action in expected_actions: assert expected_action in output_actions diff --git a/tests/integration/sharegroups/fixtures.py b/tests/integration/sharegroups/fixtures.py index e2838e9bd..f6e91f0cd 100644 --- a/tests/integration/sharegroups/fixtures.py +++ b/tests/integration/sharegroups/fixtures.py @@ -3,7 +3,8 @@ from tests.integration.helpers import ( BASE_CMDS, - exec_test_command, get_random_text, + exec_test_command, + get_random_text, ) @@ -16,6 +17,23 @@ def get_region(): yield first_id +def wait_for_image_status(id, expected_status, timeout=180, interval=5): + import time + + current_status = exec_test_command( + BASE_CMDS["images"] + ["view", id, "--text", "--no-headers", "--delimiter", ",", "--format", "status"] + ).splitlines() + timer = 0 + while current_status[0] != expected_status and timer < timeout: + time.sleep(interval) + timer += interval + current_status = exec_test_command( + BASE_CMDS["images"] + ["view", id, "--text", "--no-headers", "--delimiter", ",", "--format", "status"] + ).splitlines() + if timer >= timeout: + raise TimeoutError(f"Created image did not reach status '{expected_status}' within {timeout} seconds.") + + @pytest.fixture(scope="function") def create_image_id(get_region): linode_id = exec_test_command( @@ -30,7 +48,7 @@ def create_image_id(get_region): BASE_CMDS["images"] + ["create", "--label", "linode-cli-test-image-sharing-image", "--disk_id", disks[0], "--text", "--no-headers", "--delimiter", ",", "--format", "id"] ) - # TODO: wait_for_status + wait_for_image_status(image_id, "available") yield linode_id, image_id @@ -42,13 +60,3 @@ def create_share_group(): "--format", "id,uuid"] ).split(",") yield share_group[0], share_group[1] - - -@pytest.fixture(scope="function") -def create_token(): - label = get_random_text(8) + "_sharegroup_cli_test" - created_token = exec_test_command( - BASE_CMDS["profile"] + ["token-create", "--label", label, "--text", "--no-headers", "--delimiter", ",", - "--format", "token"] - ) - yield jwt.encode({"some": "payload"}, created_token, algorithm="HS256") diff --git a/tests/integration/sharegroups/test_images_sharegroups.py b/tests/integration/sharegroups/test_images_sharegroups.py index 307e41682..8d9d8d69b 100644 --- a/tests/integration/sharegroups/test_images_sharegroups.py +++ b/tests/integration/sharegroups/test_images_sharegroups.py @@ -1,45 +1,48 @@ from linodecli.exit_codes import ExitCodes from tests.integration.helpers import ( - assert_headers_in_lines, BASE_CMDS, + assert_headers_in_lines, + assert_help_actions_list, delete_target_id, - exec_test_command, get_random_text, exec_failing_test_command, + exec_failing_test_command, + exec_test_command, + get_random_text, ) from tests.integration.sharegroups.fixtures import ( create_image_id, create_share_group, get_region, - create_token, ) -# def test_help_image_sharegroups(): -# output = exec_test_command( -# BASE_CMDS["image-sharegroups"] + ["--help", "--text", "--delimiter=,"] -# ) -# actions = [ -# "create", -# "delete", -# "image-add", -# "image-remove", -# "image-update", -# "images-list", -# "images-list-by-token", -# "list, ls", -# "member-add", -# "member-delete", -# "member-update", -# "member-view", -# "members-list", -# "token-create", -# "token-delete", -# "token-update", -# "token-view", -# "tokens-list", -# "update", -# "view", -# "view-by-token" -# ] -# assert_help_actions_list(actions, output) + +def test_help_image_sharegroups(): + output = exec_test_command( + BASE_CMDS["image-sharegroups"] + ["--help", "--text", "--delimiter=,"] + ) + actions = [ + "create", + "delete, rm", + "image-add", + "image-remove", + "image-update", + "images-list", + "images-list-by-token", + "list, ls", + "member-add", + "member-delete", + "member-update", + "member-view", + "members-list", + "token-create", + "token-delete", + "token-update", + "token-view", + "tokens-list", + "update", + "view", + "view-by-token", + ] + assert_help_actions_list(actions, output) def test_list_all_share_groups(): @@ -51,18 +54,10 @@ def test_list_all_share_groups(): assert_headers_in_lines(headers, lines) -def test_list_all_owned_groups_with_shared_images(): - result = exec_test_command( - BASE_CMDS["image-sharegroups"] + ["list", "--delimiter", ",", "--text"] - ).splitlines() - headers = ["id", "label", "uuid", "description", "is_suspended", "images_count", "members_count"] - assert_headers_in_lines(headers, result) - - -def test_add_image_to_share_group_list_images(create_share_group, create_image_id): +def test_add_list_update_remove_image_to_share_group(create_share_group, create_image_id): result_add_image = exec_test_command( BASE_CMDS["image-sharegroups"] + ["image-add", "--images.id", create_image_id[1], create_share_group[0], - "--delimiter", ",", "--text"] + "--delimiter", ",", "--text"] ).splitlines() headers = ["id", "label", "description", "size", "total_size", "capabilities", "is_public", "is_shared", "tags"] assert_headers_in_lines(headers, result_add_image) @@ -74,35 +69,83 @@ def test_add_image_to_share_group_list_images(create_share_group, create_image_i headers = ["id", "label", "description", "size", "total_size", "capabilities", "is_public", "is_shared", "tags"] assert_headers_in_lines(headers, result_list) assert "linode-cli-test-image-sharing-image" in result_list[1] + share_image_id = result_list[1].split(",")[0] + + result_update_image = exec_test_command( + BASE_CMDS["image-sharegroups"] + ["image-update", create_share_group[0], share_image_id, + "--label", "updated_label", "--description", "Updated description.", + "--delimiter", ",", "--text"] + ).splitlines() + assert_headers_in_lines(headers, result_update_image) + assert "updated_label" in result_update_image[1] + assert "Updated description." in result_update_image[1] + + exec_test_command( + BASE_CMDS["image-sharegroups"] + ["image-remove", create_share_group[0], share_image_id, "--delimiter", + ",", "--text"] + ).splitlines() + + result_list = exec_test_command( + BASE_CMDS["image-sharegroups"] + ["images-list", create_share_group[0], "--delimiter", ",", "--text"] + ) + assert not "linode-cli-test-image-sharing-image" in result_list + assert not "updated_label" in result_list delete_target_id(target="image-sharegroups", id=create_share_group[0]) delete_target_id(target="images", id=create_image_id[1]) delete_target_id(target="linodes", id=create_image_id[0]) -def test_add_and_list_share_group_member(create_token, create_share_group): - result_add = exec_test_command( - BASE_CMDS["image-sharegroups"] + ["member-add", "--token", create_token, "--label", "test add member", - create_share_group[0], "--delimiter", ",", "--text"] - ).splitlines() - headers = ["id", "label", "uuid", "description", "is_suspended", "images_count", "members_count"] - assert_headers_in_lines(headers, result_add) - assert "token_uuid" in result_add[1] - assert create_token in result_add[1] +def test_try_add_member_use_invalid_token(create_share_group): + result = exec_failing_test_command( + BASE_CMDS["image-sharegroups"] + ["member-add", "--token", "notExistingToken", "--label", "test add member", + create_share_group[0], "--delimiter", ",", "--text"], + expected_code=ExitCodes.REQUEST_FAILED + ) + assert "Request failed: 500" in result + assert "Invalid token format" in result - result_list = exec_test_command( - BASE_CMDS["image-sharegroups"] + ["members-list", create_share_group[0], "members", "list", "--delimiter", ",", - "--text"] + delete_target_id(target="image-sharegroups", id=create_share_group[0]) + + +def test_list_members_for_invalid_token(create_share_group): + result = exec_test_command( + BASE_CMDS["image-sharegroups"] + ["members-list", "--token", "notExistingToken", create_share_group[0], + "--delimiter", ",", "--text"] ).splitlines() - headers = ["id", "label", "uuid", "description", "is_suspended", "images_count", "members_count"] - assert_headers_in_lines(headers, result_list) - assert "token_uuid" in result_list[1] - assert "Test create" in result_list[1] + headers = ["token_uuid", "label", "status"] + assert_headers_in_lines(headers, result) - delete_target_id(target="profile", id=create_token) delete_target_id(target="image-sharegroups", id=create_share_group[0]) +def test_try_revoke_membership_for_invalid_token(): + result = exec_failing_test_command( + BASE_CMDS["image-sharegroups"] + ["member-delete", "9876543", "notExistingToken", "--delimiter", ",", "--text", + "--no-headers"], expected_code=ExitCodes.REQUEST_FAILED + ) + assert "Request failed: 404" in result + assert "Not found" in result + + +def test_try_update_membership_for_invalid_token(): + result = exec_failing_test_command( + BASE_CMDS["image-sharegroups"] + ["member-update", "9876543", "notExistingToken", "--delimiter", ",", "--text", + "--no-headers", "--label", "update"], expected_code=ExitCodes.REQUEST_FAILED + ) + assert "Request failed: 404" in result + assert "Not found" in result + + +def test_try_view_membership_for_invalid_token(): + result = exec_failing_test_command( + BASE_CMDS["image-sharegroups"] + ["member-view", "9876543", "notExistingToken", "--delimiter", ",", "--text", + "--no-headers"], expected_code=ExitCodes.REQUEST_FAILED + ) + assert "Request failed: 404" in result + assert "Not found" in result + + def test_create_read_update_delete_share_group(): group_label = get_random_text(8) + "_sharegroup_cli_test" create_result = exec_test_command( @@ -136,112 +179,72 @@ def test_create_read_update_delete_share_group(): BASE_CMDS["image-sharegroups"] + ["view", share_group_id, "--delimiter", ",", "--text"], expected_code=ExitCodes.REQUEST_FAILED ) - assert "Request failed: 403" in result_after_delete + assert "Request failed: 404" in result_after_delete + assert "Not found" in result_after_delete -def test_create_token(create_share_group): +def test_try_to_create_token(create_share_group): share_group_uuid = create_share_group[1] - result = exec_test_command( - BASE_CMDS["images"] + ["sharegroups", "tokens", "create", "--label", "my_token", "--valid_for_sharegroup_uuid", - share_group_uuid, "--delimiter", ",", "--text"] + result = exec_failing_test_command( + BASE_CMDS["image-sharegroups"] + ["token-create", "--label", "cli_test", "--valid_for_sharegroup_uuid", + share_group_uuid, "--delimiter", ",", "--text"], + expected_code=ExitCodes.REQUEST_FAILED ) - assert "token_uuid" in result - + assert "Request failed: 400" in result + assert "You may not create a token for your own sharegroup" in result -def test_get_details_about_all_the_users_tokens(): - result = exec_test_command( - BASE_CMDS["image-sharegroups"] + ["tokens-list", "--delimiter", ",", "--text"] - ) - lines = result.splitlines() - headers = ["token_uuid", "label", "status", "valid_for_sharegroup_uuid", "sharegroup_uuid", "sharegroup_label"] - assert_headers_in_lines(headers, lines) + delete_target_id(target="image-sharegroups", id=create_share_group[0]) -def test_update_and_revoke_access_to_shared_image(create_image_id, create_share_group): - image_id = create_image_id[0] - share_group_id = create_share_group[0] - result = exec_test_command( - BASE_CMDS["images"] + ["sharegroups", share_group_id, "images", "update", image_id, "--label", "new_label", - "--description", "A new description.", "--delimiter", ",", "--text"] - ) - assert "image_sharing" in result - exec_test_command( - BASE_CMDS["images"] + ["sharegroups", share_group_id, "images", "remove", image_id, "--delimiter", ",", - "--text"] - ) - result = exec_test_command( - BASE_CMDS["images"] + ["sharegroups", share_group_id, "images", "update", image_id, "--label", "new_label", - "--description", "A new description.", "--delimiter", ",", "--text"] +def test_try_read_invalid_token(): + result = exec_failing_test_command( + BASE_CMDS["image-sharegroups"] + ["token-view", "36b0-4d52_invalid", "--delimiter", ",", "--text"], + expected_code=ExitCodes.REQUEST_FAILED ) - assert "Request failed: 400" in result + assert "Request failed: 404" in result + assert "Not found" in result -def test_get_and_revoke_membership_token_details(create_share_group, create_token): - share_group_id = create_share_group[0] - token_id = create_token[0] - result = exec_test_command( - BASE_CMDS["images"] + ["sharegroups", share_group_id, "members", "view", token_id, "--delimiter", ",", "--text", - "--no-headers"] - ) - assert "token_uuid" in result - token_id = create_token[0] - exec_test_command( - BASE_CMDS["images"] + ["sharegroups", share_group_id, "members", "delete", token_id, "--delimiter", ",", - "--text"] - ) - result = exec_test_command( - BASE_CMDS["images"] + ["sharegroups", share_group_id, "members", "view", token_id, "--delimiter", ",", "--text", - "--no-headers"] +def test_try_to_update_invalid_token(): + result = exec_failing_test_command( + BASE_CMDS["image-sharegroups"] + ["token-update", "--label", "cli_test_update", "36b0-4d52_invalid", + "--delimiter", ",", "--text"], expected_code=ExitCodes.REQUEST_FAILED ) - assert "Request failed: 400" in result + assert "Request failed: 404" in result + assert "Not found" in result -def test_create_and_update_membership_token(create_image_id, create_share_group, create_token): - image_id = create_image_id[0] - share_group_id = create_share_group[0] - token_id = create_token[0] - result = exec_test_command( - BASE_CMDS["images"] + [image_id, "sharegroups", share_group_id, "members", "update", token_id, "--label", - "new_label", "--delimiter", ",", "--text"] +def test_try_to_delete_token(): + result = exec_failing_test_command( + BASE_CMDS["image-sharegroups"] + ["token-delete", "36b0-4d52_invalid", "--delimiter", ",", "--text"], + expected_code=ExitCodes.REQUEST_FAILED ) - assert "label" in result + assert "Request failed: 404" in result + assert "Not found" in result -def test_list_all_shared_images(create_token): - token_id = create_token[0] +def test_get_details_about_all_the_users_tokens(): result = exec_test_command( - BASE_CMDS["images"] + ["sharegroups", "tokens", token_id, "sharegroup", "images", "list", "--delimiter", ",", - "--text"] + BASE_CMDS["image-sharegroups"] + ["tokens-list", "--delimiter", ",", "--text"] ) - assert "data" in result - assert "image_sharing" in result + lines = result.splitlines() + headers = ["token_uuid", "label", "status", "valid_for_sharegroup_uuid", "sharegroup_uuid", "sharegroup_label"] + assert_headers_in_lines(headers, lines) -def test_gets_details_about_your_share_group(create_token): - token_id = create_token[0] - result = exec_test_command( - BASE_CMDS["images"] + ["sharegroups", "tokens", token_id, "sharegroup", "view", "--delimiter", ",", "--text", - "--no-headers"] +def test_try_to_list_all_shared_images_for_invalid_token(): + result = exec_failing_test_command( + BASE_CMDS["image-sharegroups"] + ["images-list-by-token", "notExistingToken", "--delimiter", ",", "--text"], + expected_code=ExitCodes.REQUEST_FAILED ) - assert "sharegroup_uuid" in result + assert "Request failed: 404" in result + assert "Not found" in result -def test_get_update_remove_membership_for_token(create_token): - token_id = create_token[0] - result = exec_test_command( - BASE_CMDS["images"] + ["sharegroups", "tokens", "view", token_id, "--delimiter", ",", "--text"] - ) - assert "sharegroup_uuid" in result - result = exec_test_command( - BASE_CMDS["images"] + ["sharegroups", "tokens", "update", token_id, "--label", "new_label", "--delimiter", ",", - "--text"] +def test_try_gets_details_about_your_share_group_for_invalid_token(): + result = exec_failing_test_command( + BASE_CMDS["image-sharegroups"] + ["view-by-token", "notExistingToken", "--delimiter", ",", "--text", + "--no-headers"], expected_code=ExitCodes.REQUEST_FAILED ) - assert "label" in result - exec_test_command( - BASE_CMDS["images"] + ["sharegroups", "tokens", "delete", token_id, "--delimiter", ",", "--text", - "--no-headers"] - ) - result = exec_test_command( - BASE_CMDS["images"] + ["sharegroups", "tokens", "view", token_id, "--delimiter", ",", "--text"] - ) - assert "Request failed: 400" in result + assert "Request failed: 404" in result + assert "Not found" in result From 5f76549fb0ad5368bc28f1fe9c92429c797eaa57 Mon Sep 17 00:00:00 2001 From: Pawel Snoch Date: Tue, 18 Nov 2025 19:27:19 +0100 Subject: [PATCH 4/5] Add Copilot suggestions and fix regex warning --- tests/integration/helpers.py | 2 +- tests/integration/sharegroups/fixtures.py | 1 - tests/integration/sharegroups/test_images_sharegroups.py | 6 +++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/integration/helpers.py b/tests/integration/helpers.py index 0b5540fad..f0c2c2e3f 100644 --- a/tests/integration/helpers.py +++ b/tests/integration/helpers.py @@ -210,6 +210,6 @@ def get_random_region_with_caps( def assert_help_actions_list(expected_actions, help_output): - output_actions = re.findall("\│\s(\S+(?:,\s)?\S+)\s*\│", help_output) + output_actions = re.findall(r'│\s(\S+(?:,\s)?\S+)\s*│', help_output) for expected_action in expected_actions: assert expected_action in output_actions diff --git a/tests/integration/sharegroups/fixtures.py b/tests/integration/sharegroups/fixtures.py index f6e91f0cd..dd6d408c0 100644 --- a/tests/integration/sharegroups/fixtures.py +++ b/tests/integration/sharegroups/fixtures.py @@ -1,4 +1,3 @@ -import jwt import pytest from tests.integration.helpers import ( diff --git a/tests/integration/sharegroups/test_images_sharegroups.py b/tests/integration/sharegroups/test_images_sharegroups.py index 8d9d8d69b..c2fdd4cd6 100644 --- a/tests/integration/sharegroups/test_images_sharegroups.py +++ b/tests/integration/sharegroups/test_images_sharegroups.py @@ -8,7 +8,7 @@ exec_test_command, get_random_text, ) -from tests.integration.sharegroups.fixtures import ( +from tests.integration.sharegroups.fixtures import ( # noqa: F401 create_image_id, create_share_group, get_region, @@ -88,8 +88,8 @@ def test_add_list_update_remove_image_to_share_group(create_share_group, create_ result_list = exec_test_command( BASE_CMDS["image-sharegroups"] + ["images-list", create_share_group[0], "--delimiter", ",", "--text"] ) - assert not "linode-cli-test-image-sharing-image" in result_list - assert not "updated_label" in result_list + assert "linode-cli-test-image-sharing-image" not in result_list + assert "updated_label" not in result_list delete_target_id(target="image-sharegroups", id=create_share_group[0]) delete_target_id(target="images", id=create_image_id[1]) From 5fb159d5661c293d35419f404367df1439cab456 Mon Sep 17 00:00:00 2001 From: Pawel Snoch Date: Wed, 19 Nov 2025 13:36:51 +0100 Subject: [PATCH 5/5] Apply make format suggestions --- tests/integration/helpers.py | 2 +- tests/integration/sharegroups/fixtures.py | 102 ++++++- .../sharegroups/test_images_sharegroups.py | 270 +++++++++++++++--- 3 files changed, 314 insertions(+), 60 deletions(-) diff --git a/tests/integration/helpers.py b/tests/integration/helpers.py index f0c2c2e3f..f74d81957 100644 --- a/tests/integration/helpers.py +++ b/tests/integration/helpers.py @@ -210,6 +210,6 @@ def get_random_region_with_caps( def assert_help_actions_list(expected_actions, help_output): - output_actions = re.findall(r'│\s(\S+(?:,\s)?\S+)\s*│', help_output) + output_actions = re.findall(r"│\s(\S+(?:,\s)?\S+)\s*│", help_output) for expected_action in expected_actions: assert expected_action in output_actions diff --git a/tests/integration/sharegroups/fixtures.py b/tests/integration/sharegroups/fixtures.py index dd6d408c0..488b1a023 100644 --- a/tests/integration/sharegroups/fixtures.py +++ b/tests/integration/sharegroups/fixtures.py @@ -10,7 +10,16 @@ @pytest.fixture def get_region(): regions = exec_test_command( - BASE_CMDS["regions"] + ["list", "--text", "--no-headers", "--delimiter", ",", "--format", "id"] + BASE_CMDS["regions"] + + [ + "list", + "--text", + "--no-headers", + "--delimiter", + ",", + "--format", + "id", + ] ).splitlines() first_id = regions[0] yield first_id @@ -20,32 +29,91 @@ def wait_for_image_status(id, expected_status, timeout=180, interval=5): import time current_status = exec_test_command( - BASE_CMDS["images"] + ["view", id, "--text", "--no-headers", "--delimiter", ",", "--format", "status"] + BASE_CMDS["images"] + + [ + "view", + id, + "--text", + "--no-headers", + "--delimiter", + ",", + "--format", + "status", + ] ).splitlines() timer = 0 while current_status[0] != expected_status and timer < timeout: time.sleep(interval) timer += interval current_status = exec_test_command( - BASE_CMDS["images"] + ["view", id, "--text", "--no-headers", "--delimiter", ",", "--format", "status"] + BASE_CMDS["images"] + + [ + "view", + id, + "--text", + "--no-headers", + "--delimiter", + ",", + "--format", + "status", + ] ).splitlines() if timer >= timeout: - raise TimeoutError(f"Created image did not reach status '{expected_status}' within {timeout} seconds.") + raise TimeoutError( + f"Created image did not reach status '{expected_status}' within {timeout} seconds." + ) @pytest.fixture(scope="function") def create_image_id(get_region): linode_id = exec_test_command( - BASE_CMDS["linodes"] + ["create", "--image", "linode/alpine3.22", "--region", get_region, "--type", - "g6-nanode-1", "--root_pass", "aComplex@Password", "--text", "--no-headers", - "--delimiter", ",", "--format", "id"] + BASE_CMDS["linodes"] + + [ + "create", + "--image", + "linode/alpine3.22", + "--region", + get_region, + "--type", + "g6-nanode-1", + "--root_pass", + "aComplex@Password", + "--text", + "--no-headers", + "--delimiter", + ",", + "--format", + "id", + ] ) disks = exec_test_command( - BASE_CMDS["linodes"] + ["disks-list", linode_id, "--text", "--no-headers", "--delimiter", ",", "--format", "id"] + BASE_CMDS["linodes"] + + [ + "disks-list", + linode_id, + "--text", + "--no-headers", + "--delimiter", + ",", + "--format", + "id", + ] ).splitlines() image_id = exec_test_command( - BASE_CMDS["images"] + ["create", "--label", "linode-cli-test-image-sharing-image", "--disk_id", disks[0], - "--text", "--no-headers", "--delimiter", ",", "--format", "id"] + BASE_CMDS["images"] + + [ + "create", + "--label", + "linode-cli-test-image-sharing-image", + "--disk_id", + disks[0], + "--text", + "--no-headers", + "--delimiter", + ",", + "--format", + "id", + ] ) wait_for_image_status(image_id, "available") yield linode_id, image_id @@ -55,7 +123,17 @@ def create_image_id(get_region): def create_share_group(): label = get_random_text(8) + "_sharegroup_cli_test" share_group = exec_test_command( - BASE_CMDS["image-sharegroups"] + ["create", "--label", label, "--text", "--no-headers", "--delimiter", ",", - "--format", "id,uuid"] + BASE_CMDS["image-sharegroups"] + + [ + "create", + "--label", + label, + "--text", + "--no-headers", + "--delimiter", + ",", + "--format", + "id,uuid", + ] ).split(",") yield share_group[0], share_group[1] diff --git a/tests/integration/sharegroups/test_images_sharegroups.py b/tests/integration/sharegroups/test_images_sharegroups.py index c2fdd4cd6..1ab8bf340 100644 --- a/tests/integration/sharegroups/test_images_sharegroups.py +++ b/tests/integration/sharegroups/test_images_sharegroups.py @@ -50,43 +50,100 @@ def test_list_all_share_groups(): BASE_CMDS["image-sharegroups"] + ["list", "--delimiter", ",", "--text"] ) lines = result.splitlines() - headers = ["id", "label", "uuid", "description", "is_suspended", "images_count", "members_count"] + headers = [ + "id", + "label", + "uuid", + "description", + "is_suspended", + "images_count", + "members_count", + ] assert_headers_in_lines(headers, lines) -def test_add_list_update_remove_image_to_share_group(create_share_group, create_image_id): +def test_add_list_update_remove_image_to_share_group( + create_share_group, create_image_id +): result_add_image = exec_test_command( - BASE_CMDS["image-sharegroups"] + ["image-add", "--images.id", create_image_id[1], create_share_group[0], - "--delimiter", ",", "--text"] + BASE_CMDS["image-sharegroups"] + + [ + "image-add", + "--images.id", + create_image_id[1], + create_share_group[0], + "--delimiter", + ",", + "--text", + ] ).splitlines() - headers = ["id", "label", "description", "size", "total_size", "capabilities", "is_public", "is_shared", "tags"] + headers = [ + "id", + "label", + "description", + "size", + "total_size", + "capabilities", + "is_public", + "is_shared", + "tags", + ] assert_headers_in_lines(headers, result_add_image) assert "linode-cli-test-image-sharing-image" in result_add_image[1] result_list = exec_test_command( - BASE_CMDS["image-sharegroups"] + ["images-list", create_share_group[0], "--delimiter", ",", "--text"] + BASE_CMDS["image-sharegroups"] + + ["images-list", create_share_group[0], "--delimiter", ",", "--text"] ).splitlines() - headers = ["id", "label", "description", "size", "total_size", "capabilities", "is_public", "is_shared", "tags"] + headers = [ + "id", + "label", + "description", + "size", + "total_size", + "capabilities", + "is_public", + "is_shared", + "tags", + ] assert_headers_in_lines(headers, result_list) assert "linode-cli-test-image-sharing-image" in result_list[1] share_image_id = result_list[1].split(",")[0] result_update_image = exec_test_command( - BASE_CMDS["image-sharegroups"] + ["image-update", create_share_group[0], share_image_id, - "--label", "updated_label", "--description", "Updated description.", - "--delimiter", ",", "--text"] + BASE_CMDS["image-sharegroups"] + + [ + "image-update", + create_share_group[0], + share_image_id, + "--label", + "updated_label", + "--description", + "Updated description.", + "--delimiter", + ",", + "--text", + ] ).splitlines() assert_headers_in_lines(headers, result_update_image) assert "updated_label" in result_update_image[1] assert "Updated description." in result_update_image[1] exec_test_command( - BASE_CMDS["image-sharegroups"] + ["image-remove", create_share_group[0], share_image_id, "--delimiter", - ",", "--text"] + BASE_CMDS["image-sharegroups"] + + [ + "image-remove", + create_share_group[0], + share_image_id, + "--delimiter", + ",", + "--text", + ] ).splitlines() result_list = exec_test_command( - BASE_CMDS["image-sharegroups"] + ["images-list", create_share_group[0], "--delimiter", ",", "--text"] + BASE_CMDS["image-sharegroups"] + + ["images-list", create_share_group[0], "--delimiter", ",", "--text"] ) assert "linode-cli-test-image-sharing-image" not in result_list assert "updated_label" not in result_list @@ -98,9 +155,19 @@ def test_add_list_update_remove_image_to_share_group(create_share_group, create_ def test_try_add_member_use_invalid_token(create_share_group): result = exec_failing_test_command( - BASE_CMDS["image-sharegroups"] + ["member-add", "--token", "notExistingToken", "--label", "test add member", - create_share_group[0], "--delimiter", ",", "--text"], - expected_code=ExitCodes.REQUEST_FAILED + BASE_CMDS["image-sharegroups"] + + [ + "member-add", + "--token", + "notExistingToken", + "--label", + "test add member", + create_share_group[0], + "--delimiter", + ",", + "--text", + ], + expected_code=ExitCodes.REQUEST_FAILED, ) assert "Request failed: 500" in result assert "Invalid token format" in result @@ -110,8 +177,16 @@ def test_try_add_member_use_invalid_token(create_share_group): def test_list_members_for_invalid_token(create_share_group): result = exec_test_command( - BASE_CMDS["image-sharegroups"] + ["members-list", "--token", "notExistingToken", create_share_group[0], - "--delimiter", ",", "--text"] + BASE_CMDS["image-sharegroups"] + + [ + "members-list", + "--token", + "notExistingToken", + create_share_group[0], + "--delimiter", + ",", + "--text", + ] ).splitlines() headers = ["token_uuid", "label", "status"] assert_headers_in_lines(headers, result) @@ -121,8 +196,17 @@ def test_list_members_for_invalid_token(create_share_group): def test_try_revoke_membership_for_invalid_token(): result = exec_failing_test_command( - BASE_CMDS["image-sharegroups"] + ["member-delete", "9876543", "notExistingToken", "--delimiter", ",", "--text", - "--no-headers"], expected_code=ExitCodes.REQUEST_FAILED + BASE_CMDS["image-sharegroups"] + + [ + "member-delete", + "9876543", + "notExistingToken", + "--delimiter", + ",", + "--text", + "--no-headers", + ], + expected_code=ExitCodes.REQUEST_FAILED, ) assert "Request failed: 404" in result assert "Not found" in result @@ -130,8 +214,19 @@ def test_try_revoke_membership_for_invalid_token(): def test_try_update_membership_for_invalid_token(): result = exec_failing_test_command( - BASE_CMDS["image-sharegroups"] + ["member-update", "9876543", "notExistingToken", "--delimiter", ",", "--text", - "--no-headers", "--label", "update"], expected_code=ExitCodes.REQUEST_FAILED + BASE_CMDS["image-sharegroups"] + + [ + "member-update", + "9876543", + "notExistingToken", + "--delimiter", + ",", + "--text", + "--no-headers", + "--label", + "update", + ], + expected_code=ExitCodes.REQUEST_FAILED, ) assert "Request failed: 404" in result assert "Not found" in result @@ -139,8 +234,17 @@ def test_try_update_membership_for_invalid_token(): def test_try_view_membership_for_invalid_token(): result = exec_failing_test_command( - BASE_CMDS["image-sharegroups"] + ["member-view", "9876543", "notExistingToken", "--delimiter", ",", "--text", - "--no-headers"], expected_code=ExitCodes.REQUEST_FAILED + BASE_CMDS["image-sharegroups"] + + [ + "member-view", + "9876543", + "notExistingToken", + "--delimiter", + ",", + "--text", + "--no-headers", + ], + expected_code=ExitCodes.REQUEST_FAILED, ) assert "Request failed: 404" in result assert "Not found" in result @@ -149,24 +253,52 @@ def test_try_view_membership_for_invalid_token(): def test_create_read_update_delete_share_group(): group_label = get_random_text(8) + "_sharegroup_cli_test" create_result = exec_test_command( - BASE_CMDS["image-sharegroups"] + ["create", "--label", group_label, "--description", "Test create", - "--delimiter", ",", "--text"] + BASE_CMDS["image-sharegroups"] + + [ + "create", + "--label", + group_label, + "--description", + "Test create", + "--delimiter", + ",", + "--text", + ] ).splitlines() - headers = ["id", "label", "uuid", "description", "is_suspended", "images_count", "members_count"] + headers = [ + "id", + "label", + "uuid", + "description", + "is_suspended", + "images_count", + "members_count", + ] assert_headers_in_lines(headers, create_result) assert group_label in create_result[1] assert "Test create" in create_result[1] share_group_id = create_result[1].split(",")[0] get_result = exec_test_command( - BASE_CMDS["image-sharegroups"] + ["view", share_group_id, "--delimiter", ",", "--text"] + BASE_CMDS["image-sharegroups"] + + ["view", share_group_id, "--delimiter", ",", "--text"] ).splitlines() assert_headers_in_lines(headers, get_result) assert group_label in get_result[1] update_result = exec_test_command( - BASE_CMDS["image-sharegroups"] + ["update", "--description", "Description update", "--label", group_label + - "_updated", share_group_id, "--delimiter", ",", "--text"] + BASE_CMDS["image-sharegroups"] + + [ + "update", + "--description", + "Description update", + "--label", + group_label + "_updated", + share_group_id, + "--delimiter", + ",", + "--text", + ] ).splitlines() assert_headers_in_lines(headers, update_result) assert group_label + "_updated" in update_result[1] @@ -176,8 +308,9 @@ def test_create_read_update_delete_share_group(): BASE_CMDS["image-sharegroups"] + ["delete", share_group_id] ) result_after_delete = exec_failing_test_command( - BASE_CMDS["image-sharegroups"] + ["view", share_group_id, "--delimiter", ",", "--text"], - expected_code=ExitCodes.REQUEST_FAILED + BASE_CMDS["image-sharegroups"] + + ["view", share_group_id, "--delimiter", ",", "--text"], + expected_code=ExitCodes.REQUEST_FAILED, ) assert "Request failed: 404" in result_after_delete assert "Not found" in result_after_delete @@ -186,9 +319,18 @@ def test_create_read_update_delete_share_group(): def test_try_to_create_token(create_share_group): share_group_uuid = create_share_group[1] result = exec_failing_test_command( - BASE_CMDS["image-sharegroups"] + ["token-create", "--label", "cli_test", "--valid_for_sharegroup_uuid", - share_group_uuid, "--delimiter", ",", "--text"], - expected_code=ExitCodes.REQUEST_FAILED + BASE_CMDS["image-sharegroups"] + + [ + "token-create", + "--label", + "cli_test", + "--valid_for_sharegroup_uuid", + share_group_uuid, + "--delimiter", + ",", + "--text", + ], + expected_code=ExitCodes.REQUEST_FAILED, ) assert "Request failed: 400" in result assert "You may not create a token for your own sharegroup" in result @@ -198,8 +340,9 @@ def test_try_to_create_token(create_share_group): def test_try_read_invalid_token(): result = exec_failing_test_command( - BASE_CMDS["image-sharegroups"] + ["token-view", "36b0-4d52_invalid", "--delimiter", ",", "--text"], - expected_code=ExitCodes.REQUEST_FAILED + BASE_CMDS["image-sharegroups"] + + ["token-view", "36b0-4d52_invalid", "--delimiter", ",", "--text"], + expected_code=ExitCodes.REQUEST_FAILED, ) assert "Request failed: 404" in result assert "Not found" in result @@ -207,8 +350,17 @@ def test_try_read_invalid_token(): def test_try_to_update_invalid_token(): result = exec_failing_test_command( - BASE_CMDS["image-sharegroups"] + ["token-update", "--label", "cli_test_update", "36b0-4d52_invalid", - "--delimiter", ",", "--text"], expected_code=ExitCodes.REQUEST_FAILED + BASE_CMDS["image-sharegroups"] + + [ + "token-update", + "--label", + "cli_test_update", + "36b0-4d52_invalid", + "--delimiter", + ",", + "--text", + ], + expected_code=ExitCodes.REQUEST_FAILED, ) assert "Request failed: 404" in result assert "Not found" in result @@ -216,8 +368,9 @@ def test_try_to_update_invalid_token(): def test_try_to_delete_token(): result = exec_failing_test_command( - BASE_CMDS["image-sharegroups"] + ["token-delete", "36b0-4d52_invalid", "--delimiter", ",", "--text"], - expected_code=ExitCodes.REQUEST_FAILED + BASE_CMDS["image-sharegroups"] + + ["token-delete", "36b0-4d52_invalid", "--delimiter", ",", "--text"], + expected_code=ExitCodes.REQUEST_FAILED, ) assert "Request failed: 404" in result assert "Not found" in result @@ -225,17 +378,32 @@ def test_try_to_delete_token(): def test_get_details_about_all_the_users_tokens(): result = exec_test_command( - BASE_CMDS["image-sharegroups"] + ["tokens-list", "--delimiter", ",", "--text"] + BASE_CMDS["image-sharegroups"] + + ["tokens-list", "--delimiter", ",", "--text"] ) lines = result.splitlines() - headers = ["token_uuid", "label", "status", "valid_for_sharegroup_uuid", "sharegroup_uuid", "sharegroup_label"] + headers = [ + "token_uuid", + "label", + "status", + "valid_for_sharegroup_uuid", + "sharegroup_uuid", + "sharegroup_label", + ] assert_headers_in_lines(headers, lines) def test_try_to_list_all_shared_images_for_invalid_token(): result = exec_failing_test_command( - BASE_CMDS["image-sharegroups"] + ["images-list-by-token", "notExistingToken", "--delimiter", ",", "--text"], - expected_code=ExitCodes.REQUEST_FAILED + BASE_CMDS["image-sharegroups"] + + [ + "images-list-by-token", + "notExistingToken", + "--delimiter", + ",", + "--text", + ], + expected_code=ExitCodes.REQUEST_FAILED, ) assert "Request failed: 404" in result assert "Not found" in result @@ -243,8 +411,16 @@ def test_try_to_list_all_shared_images_for_invalid_token(): def test_try_gets_details_about_your_share_group_for_invalid_token(): result = exec_failing_test_command( - BASE_CMDS["image-sharegroups"] + ["view-by-token", "notExistingToken", "--delimiter", ",", "--text", - "--no-headers"], expected_code=ExitCodes.REQUEST_FAILED + BASE_CMDS["image-sharegroups"] + + [ + "view-by-token", + "notExistingToken", + "--delimiter", + ",", + "--text", + "--no-headers", + ], + expected_code=ExitCodes.REQUEST_FAILED, ) assert "Request failed: 404" in result assert "Not found" in result