Skip to content

Update system caches tests #697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 4, 2025
Merged
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
20 changes: 4 additions & 16 deletions tests/test_main_system_caches.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@

CONNECT_SERVER = "http://localhost:3939"
CONNECT_KEYS_JSON = "vetiver-testing/rsconnect_api_keys.json"
CONNECT_CACHE_DIR = "/data/python-environments/_packages_cache"

ADD_CACHE_COMMAND = "docker compose exec -u rstudio-connect -T rsconnect mkdir -p /data/python-environments/pip/1.2.3"
RM_CACHE_COMMAND = "docker compose exec -u rstudio-connect -T rsconnect rm -Rf /data/python-environments/pip/1.2.3"
ADD_CACHE_COMMAND = f"docker compose exec -u rstudio-connect -T rsconnect mkdir -p {CONNECT_CACHE_DIR}/pip/1.2.3"
Copy link
Contributor

Choose a reason for hiding this comment

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

Tests that shell out to docker compose? We don't have to change that here, but that doesn't feel right, does it?

Copy link
Collaborator Author

@amol- amol- Aug 1, 2025

Choose a reason for hiding this comment

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

Definitely, there are a few Connect implementation details that are involved in rsconnect-python tests.
While Integration tests make sense, I believe they should treat connect as a blackbox.

For example, as far as "delete + list again" API calls confirm that the cache was actually deleted, we should not care if that happened for real or not on disk. Worst case, that would be a Connect bug and not a rsconnect one, and would be caught by connect tests. Rsconnect should start from the assumption that Connect does the right thing.

RM_CACHE_COMMAND = f"docker compose exec -u rstudio-connect -T rsconnect rm -Rf {CONNECT_CACHE_DIR}/pip/1.2.3"
# The following returns int(0) if dir exists, else int(256).
CACHE_EXISTS_COMMAND = "docker compose exec -u rstudio-connect -T rsconnect [ -d /data/python-environments/pip/1.2.3 ]"
CACHE_EXISTS_COMMAND = f"docker compose exec -u rstudio-connect -T rsconnect [ -d {CONNECT_CACHE_DIR}/pip/1.2.3 ]"
SERVICE_RUNNING_COMMAND = "docker compose ps --services --filter 'status=running' | grep rsconnect"


Expand Down Expand Up @@ -131,19 +132,6 @@ def test_system_caches_delete_admin(self):

# TODO: Unsure how to test log messages received from Connect.

# Admins cannot delete caches that do not exist
Copy link
Collaborator Author

@amol- amol- Aug 1, 2025

Choose a reason for hiding this comment

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

This test should not be here imho,
it's testing a connect behaviour not rsconnect-python.

We are already testing that deleting a cache does work, and we are already testing that reporting an error message from delete works:

  • test_system_caches_delete_admin
  • test_system_caches_delete_publisher

So this test didn't test anything additional and made the testsuite too dependant on a connect behaviours that didn't break compatibility with rsconnect itself.

def test_system_caches_delete_admin_nonexistent(self):
api_key = get_key("admin")
runner = CliRunner()

args = ["system", "caches", "delete", "--language", "Python", "--version", "0.1.2", "--image-name", "Local"]
apply_common_args(args, server=CONNECT_SERVER, key=api_key)

result = runner.invoke(cli, args)
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")
Expand Down
Loading