|
11 | 11 |
|
12 | 12 |
|
13 | 13 | @pytest.mark.skipif( |
14 | | - # Added to the v2023.05.0 milestone |
15 | | - # https://github.com/rstudio/connect/pull/23148 |
16 | | - CONNECT_VERSION < version.parse("2023.05.0"), |
| 14 | + CONNECT_VERSION < version.parse("2024.05.0"), |
17 | 15 | reason="Cache runtimes not implemented", |
18 | 16 | ) |
19 | 17 | class TestSystem: |
20 | 18 | @classmethod |
21 | 19 | def setup_class(cls): |
22 | 20 | cls.client = Client() |
23 | | - assert cls.client.content.count() == 0 |
24 | | - cls.content_item = cls.client.content.create(name="Content_A") |
25 | | - |
26 | | - # Copied from from integration/tests/posit/connect/test_packages.py |
27 | | - def _deploy_python_bundle(self): |
| 21 | + cls.content = cls.client.content.create(name=cls.__name__) |
28 | 22 | path = Path("../../../resources/connect/bundles/example-flask-minimal/bundle.tar.gz") |
29 | 23 | path = (Path(__file__).parent / path).resolve() |
30 | | - bundle = self.content_item.bundles.create(str(path)) |
| 24 | + bundle = cls.content.bundles.create(str(path)) |
31 | 25 | task = bundle.deploy() |
32 | 26 | task.wait_for() |
33 | 27 |
|
34 | | - def _remove_all_caches(self): |
35 | | - caches: list[SystemRuntimeCache] = self.client.system.caches.runtime.find() |
36 | | - for cache in caches: |
37 | | - assert isinstance(cache, SystemRuntimeCache) |
38 | | - none_val = cache.destroy(dry_run=True) |
39 | | - assert none_val is None |
40 | | - task: Task = cache.destroy() |
41 | | - assert isinstance(task, Task) |
42 | | - task.wait_for() |
43 | | - assert len(self.client.system.caches.runtime.find()) == 0 |
44 | | - |
45 | 28 | @classmethod |
46 | 29 | def teardown_class(cls): |
47 | | - cls.content_item.delete() |
48 | | - assert cls.client.content.count() == 0 |
| 30 | + cls.content.delete() |
49 | 31 |
|
50 | 32 | def test_runtime_caches(self): |
51 | | - # Get current caches |
52 | | - caches: list[SystemRuntimeCache] = self.client.system.caches.runtime.find() |
53 | | - assert isinstance(caches, list) |
| 33 | + runtimes = self.client.system.caches.runtime.find() |
| 34 | + assert len(runtimes) > 0 |
54 | 35 |
|
55 | | - # Remove all caches |
56 | | - self._remove_all_caches() |
| 36 | + def test_runtime_cache_destroy(self): |
| 37 | + # Find existing runtime caches |
| 38 | + runtimes: list[SystemRuntimeCache] = self.client.system.caches.runtime.find() |
| 39 | + assert len(runtimes) > 0 |
57 | 40 |
|
58 | | - # Deploy a new cache |
59 | | - self._deploy_python_bundle() |
| 41 | + # Get the first cache for testing |
| 42 | + cache = runtimes[0] |
| 43 | + assert isinstance(cache, SystemRuntimeCache) |
60 | 44 |
|
61 | | - # Check if the cache is deployed |
62 | | - caches = self.client.system.caches.runtime.find() |
| 45 | + # Test dry run destroy (should return None and not actually destroy) |
| 46 | + result = cache.destroy(dry_run=True) |
| 47 | + assert result is None |
63 | 48 |
|
64 | | - # Barret 2024/12: |
65 | | - # Caches only showing up in Connect versions >= 2024.05.0 |
66 | | - # I do not know why. |
67 | | - # Since we are not logic testing Connect, we can confirm our code works given more recent versions of Connect. |
68 | | - if CONNECT_VERSION >= version.parse("2024.05.0"): |
69 | | - assert len(caches) > 0 |
| 49 | + # Verify cache still exists after dry run |
| 50 | + runtimes_after_dry_run = self.client.system.caches.runtime.find() |
| 51 | + assert len(runtimes_after_dry_run) == len(runtimes) |
| 52 | + |
| 53 | + # Test actual destroy |
| 54 | + task: Task = cache.destroy() |
| 55 | + assert isinstance(task, Task) |
| 56 | + task.wait_for() |
70 | 57 |
|
71 | | - # Remove all caches |
72 | | - self._remove_all_caches() |
| 58 | + # Verify cache was removed |
| 59 | + runtimes_after_destroy = self.client.system.caches.runtime.find() |
| 60 | + assert len(runtimes_after_destroy) == len(runtimes) - 1 |
0 commit comments