Skip to content

Commit

Permalink
Merge branch 'dev' into TPT-3254-obj-plugin-missing-input-error
Browse files Browse the repository at this point in the history
  • Loading branch information
ezilber-akamai authored Dec 10, 2024
2 parents 946a532 + d4224ff commit defad8f
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 13 deletions.
2 changes: 1 addition & 1 deletion linodecli/plugins/obj/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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
Expand Down
46 changes: 46 additions & 0 deletions tests/integration/obj/test_obj_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 9 additions & 6 deletions tests/unit/test_api_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
11 changes: 7 additions & 4 deletions tests/unit/test_overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down

0 comments on commit defad8f

Please sign in to comment.