From 61e9bc694c92161f60d1ca7aa9007132d325a53e Mon Sep 17 00:00:00 2001 From: Zhiwei Liang <121905282+zliang-akamai@users.noreply.github.com> Date: Mon, 9 Dec 2024 16:32:12 -0500 Subject: [PATCH 1/2] Bump minimal Python version to 3.9 (#698) --- pyproject.toml | 4 ++-- tests/unit/test_api_request.py | 15 +++++++++------ tests/unit/test_overrides.py | 11 +++++++---- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 311402da7..8ce03bfa1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ name = "linode-cli" authors = [{ name = "Akamai Technologies Inc.", email = "developers@linode.com" }] description = "The official command-line interface for interacting with the Linode API." readme = "README.md" -requires-python = ">=3.8" +requires-python = ">=3.9" license = { text = "BSD-3-Clause" } classifiers = [] dependencies = [ @@ -54,7 +54,7 @@ line_length = 80 [tool.black] line-length = 80 -target-version = ["py37", "py38", "py39", "py310", "py311"] +target-version = ["py39", "py310", "py311", "py312", "py313"] [tool.autoflake] expand-star-imports = true diff --git a/tests/unit/test_api_request.py b/tests/unit/test_api_request.py index 6b99c941f..5a395d038 100644 --- a/tests/unit/test_api_request.py +++ b/tests/unit/test_api_request.py @@ -447,8 +447,9 @@ def json_func(): status_code=200, reason="OK", headers={"X-Spec-Version": "1.1.0"} ) - with contextlib.redirect_stderr(stderr_buf), patch( - "linodecli.api_request.requests.get", mock_http_response + with ( + contextlib.redirect_stderr(stderr_buf), + patch("linodecli.api_request.requests.get", mock_http_response), ): api_request._attempt_warn_old_version(mock_cli, mock_response) @@ -491,8 +492,9 @@ def json_func(): status_code=200, reason="OK", headers={"X-Spec-Version": "1.1.0"} ) - with contextlib.redirect_stderr(stderr_buf), patch( - "linodecli.api_request.requests.get", mock_http_response + with ( + contextlib.redirect_stderr(stderr_buf), + patch("linodecli.api_request.requests.get", mock_http_response), ): api_request._attempt_warn_old_version(mock_cli, mock_response) @@ -525,8 +527,9 @@ def json_func(): status_code=200, reason="OK", headers={"X-Spec-Version": "1.0.0"} ) - with contextlib.redirect_stderr(stderr_buf), patch( - "linodecli.api_request.requests.get", mock_http_response + with ( + contextlib.redirect_stderr(stderr_buf), + patch("linodecli.api_request.requests.get", mock_http_response), ): api_request._attempt_warn_old_version(mock_cli, mock_response) diff --git a/tests/unit/test_overrides.py b/tests/unit/test_overrides.py index 01e3584d2..f5533b6b6 100644 --- a/tests/unit/test_overrides.py +++ b/tests/unit/test_overrides.py @@ -35,10 +35,13 @@ def patch_func(*a): OUTPUT_OVERRIDES[override_signature](*a) return True - with patch( - "linodecli.baked.operation.OUTPUT_OVERRIDES", - {override_signature: patch_func}, - ), patch.object(mock_cli.output_handler, "print") as p: + with ( + patch( + "linodecli.baked.operation.OUTPUT_OVERRIDES", + {override_signature: patch_func}, + ), + patch.object(mock_cli.output_handler, "print") as p, + ): list_operation_for_overrides_test.process_response_json( response_json, mock_cli.output_handler ) From d4224ffe7e028f2cba03f01c63e6b0b809b1ba31 Mon Sep 17 00:00:00 2001 From: Joren Koyen Date: Mon, 9 Dec 2024 23:11:25 +0100 Subject: [PATCH 2/2] Fix prefix path parsing in OBJ plugin (#686) Co-authored-by: Zhiwei Liang <121905282+zliang-akamai@users.noreply.github.com> Co-authored-by: Zhiwei Liang --- linodecli/plugins/obj/objects.py | 2 +- tests/integration/obj/test_obj_plugin.py | 46 ++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/linodecli/plugins/obj/objects.py b/linodecli/plugins/obj/objects.py index bdcaa64ab..f3e2513cf 100644 --- a/linodecli/plugins/obj/objects.py +++ b/linodecli/plugins/obj/objects.py @@ -91,7 +91,7 @@ def upload_object( bucket = parsed.bucket if "/" in parsed.bucket: bucket = parsed.bucket.split("/")[0] - prefix = parsed.bucket.lstrip(f"{bucket}/") + prefix = parsed.bucket.removeprefix(f"{bucket}/") upload_options = { "Bucket": bucket, diff --git a/tests/integration/obj/test_obj_plugin.py b/tests/integration/obj/test_obj_plugin.py index 0bcaf88da..04930cfe9 100644 --- a/tests/integration/obj/test_obj_plugin.py +++ b/tests/integration/obj/test_obj_plugin.py @@ -191,6 +191,52 @@ def test_obj_single_file_single_bucket_with_prefix( assert f1.read() == f2.read() +def test_obj_single_file_single_bucket_with_prefix_ltrim( + create_bucket: Callable[[Optional[str]], str], + generate_test_files: GetTestFilesType, + keys: Keys, + monkeypatch: MonkeyPatch, +): + patch_keys(keys, monkeypatch) + file_path = generate_test_files()[0] + bucket_name = create_bucket() + # using 'bk' in prefix to test out ltrim behaviour (bucket contains 'bk') + exec_test_command( + BASE_CMD + ["put", str(file_path), f"{bucket_name}/bkprefix"] + ) + process = exec_test_command(BASE_CMD + ["la"]) + output = process.stdout.decode() + + assert f"{bucket_name}/bkprefix/{file_path.name}" in output + + file_size = file_path.stat().st_size + assert str(file_size) in output + + process = exec_test_command(BASE_CMD + ["ls"]) + output = process.stdout.decode() + assert bucket_name in output + assert file_path.name not in output + + process = exec_test_command(BASE_CMD + ["ls", bucket_name]) + output = process.stdout.decode() + assert bucket_name not in output + assert "bkprefix" in output + + downloaded_file_path = file_path.parent / f"downloaded_{file_path.name}" + process = exec_test_command( + BASE_CMD + + [ + "get", + bucket_name, + "bkprefix/" + file_path.name, + str(downloaded_file_path), + ] + ) + output = process.stdout.decode() + with open(downloaded_file_path) as f2, open(file_path) as f1: + assert f1.read() == f2.read() + + def test_multi_files_multi_bucket( create_bucket: Callable[[Optional[str]], str], generate_test_files: GetTestFilesType,