-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for system cache runtime (#352)
Fixes #337 Example usage: ```python from posit.connect import Client client = Client() runtime_caches = client.system.caches.runtime.find() first_runtime_cache = runtime_caches[0] # Remove the cache task = first_runtime_cache.destroy(dry_run=True) # Wait for the task to finish task.wait_for() ``` --------- Co-authored-by: Taylor Steinberg <[email protected]>
- Loading branch information
Showing
8 changed files
with
423 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
from packaging import version | ||
|
||
from posit.connect import Client | ||
from posit.connect.system import SystemRuntimeCache | ||
from posit.connect.tasks import Task | ||
|
||
from . import CONNECT_VERSION | ||
|
||
|
||
@pytest.mark.skipif( | ||
# Added to the v2023.05.0 milestone | ||
# https://github.com/rstudio/connect/pull/23148 | ||
CONNECT_VERSION < version.parse("2023.05.0"), | ||
reason="Cache runtimes not implemented", | ||
) | ||
class TestSystem: | ||
@classmethod | ||
def setup_class(cls): | ||
cls.client = Client() | ||
assert cls.client.content.count() == 0 | ||
cls.content_item = cls.client.content.create(name="Content_A") | ||
|
||
# Copied from from integration/tests/posit/connect/test_packages.py | ||
def _deploy_python_bundle(self): | ||
path = Path("../../../resources/connect/bundles/example-flask-minimal/bundle.tar.gz") | ||
path = (Path(__file__).parent / path).resolve() | ||
bundle = self.content_item.bundles.create(str(path)) | ||
task = bundle.deploy() | ||
task.wait_for() | ||
|
||
def _remove_all_caches(self): | ||
caches: list[SystemRuntimeCache] = self.client.system.caches.runtime.find() | ||
for cache in caches: | ||
assert isinstance(cache, SystemRuntimeCache) | ||
none_val = cache.destroy(dry_run=True) | ||
assert none_val is None | ||
task: Task = cache.destroy() | ||
assert isinstance(task, Task) | ||
task.wait_for() | ||
assert len(self.client.system.caches.runtime.find()) == 0 | ||
|
||
@classmethod | ||
def teardown_class(cls): | ||
cls.content_item.delete() | ||
assert cls.client.content.count() == 0 | ||
|
||
def test_runtime_caches(self): | ||
# Get current caches | ||
caches: list[SystemRuntimeCache] = self.client.system.caches.runtime.find() | ||
assert isinstance(caches, list) | ||
|
||
# Remove all caches | ||
self._remove_all_caches() | ||
|
||
# Deploy a new cache | ||
self._deploy_python_bundle() | ||
|
||
# Check if the cache is deployed | ||
caches = self.client.system.caches.runtime.find() | ||
|
||
# Barret 2024/12: | ||
# Caches only showing up in Connect versions >= 2024.05.0 | ||
# I do not know why. | ||
# Since we are not logic testing Connect, we can confirm our code works given more recent versions of Connect. | ||
if CONNECT_VERSION >= version.parse("2024.05.0"): | ||
assert len(caches) > 0 | ||
|
||
# Remove all caches | ||
self._remove_all_caches() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.