Files
galaxy/test/unit/app/test_tasks.py
T
mvdbeek ef26fc4685 Use MockApp instead of celery_injected_app_container
Sorry, I guess the idea was to not have to build a full MockApp ?
Realisitically all tasks access the database at this point.
I suppose we could make the decorators more specific if necessary ?
2024-01-17 12:45:20 +01:00

39 lines
1.2 KiB
Python

from typing import List
from galaxy.app_unittest_utils.galaxy_mock import MockApp
from galaxy.celery.tasks import clean_object_store_caches
from galaxy.objectstore import BaseObjectStore
from galaxy.objectstore.caching import CacheTarget
class MockObjectStore:
def __init__(self, cache_targets: List[CacheTarget]):
self._cache_targets = cache_targets
def cache_targets(self) -> List[CacheTarget]:
return self._cache_targets
def test_clean_object_store_caches(tmp_path):
container = MockApp()
cache_targets: List[CacheTarget] = []
container[BaseObjectStore] = MockObjectStore(cache_targets) # type: ignore[assignment]
# similar code used in object store unit tests
cache_dir = tmp_path
path = cache_dir / "a_file_0"
path.write_text("this is an example file")
# works fine on an empty list of cache targets...
clean_object_store_caches()
assert path.exists()
# place the file in mock object store's cache targets and
# run the task again and the above file should be gone.
cache_targets.append(CacheTarget(cache_dir, 1, 0.000000001))
# works fine on an empty list of cache targets...
clean_object_store_caches()
assert not path.exists()