Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Added

- Added validation for required flags for the `rsconnect system caches delete` command.

## [1.25.0] - 2024-12-18

### Added
Expand Down
2 changes: 1 addition & 1 deletion rsconnect/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@ def runtime_caches(self) -> list[ListEntryOutputDTO]:
raise RSConnectException("To delete a runtime cache, client must be a RSConnectClient.")
return self.client.system_caches_runtime_list()

def delete_runtime_cache(self, language: Optional[str], version: Optional[str], image_name: str, dry_run: bool):
def delete_runtime_cache(self, language: str, version: str, image_name: str, dry_run: bool):
if not isinstance(self.client, RSConnectClient):
raise RSConnectException("To delete a runtime cache, client must be a RSConnectClient.")
target: DeleteInputDTO = {
Expand Down
6 changes: 4 additions & 2 deletions rsconnect/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2825,11 +2825,13 @@ def system_caches_list(
"--language",
"-l",
help="The language of the target cache.",
required=True,
)
@click.option(
"--version",
"-V",
help="The version of the target cache.",
required=True,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The system_caches_delete() function claims that language and version have Optional[..]. The delete_runtime_cache() function does the same. Should we update them to not have Optional[..] typing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh good catch. I removed the Optional typing

)
@click.option(
"--image-name",
Expand All @@ -2852,8 +2854,8 @@ def system_caches_delete(
insecure: bool,
cacert: Optional[str],
verbose: int,
language: Optional[str],
version: Optional[str],
language: str,
version: str,
image_name: str,
dry_run: bool,
):
Expand Down
26 changes: 26 additions & 0 deletions tests/test_main_system_caches.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,29 @@ def test_system_caches_delete_admin_nonexistent(self):
self.assertEqual(result.exit_code, 1)

self.assertRegex(result.output, "Cache does not exist")

# --version and --language flags are required
def test_system_caches_delete_required_flags(self):
api_key = get_key("admin")
runner = CliRunner()

# neither flag provided should fail
args = ["system", "caches", "delete"]
apply_common_args(args, server=CONNECT_SERVER, key=api_key)
result = runner.invoke(cli, args)
self.assertEqual(result.exit_code, 2)
self.assertRegex(result.output, "Error: Missing option '--language' / '-l'")

# only --language flag provided should fail
args = ["system", "caches", "delete", "--language", "Python"]
apply_common_args(args, server=CONNECT_SERVER, key=api_key)
result = runner.invoke(cli, args)
self.assertEqual(result.exit_code, 2)
self.assertRegex(result.output, "Error: Missing option '--version' / '-V'")

# only --version flag provided should fail
args = ["system", "caches", "delete", "--version", "1.2.3"]
apply_common_args(args, server=CONNECT_SERVER, key=api_key)
result = runner.invoke(cli, args)
self.assertEqual(result.exit_code, 2)
self.assertRegex(result.output, "Error: Missing option '--language' / '-l'")
Loading