Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sainak committed Aug 19, 2024
1 parent 9d1c835 commit cfea5ac
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion care/utils/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(self, decorated):
super().__init__(
CACHES={
"default": {
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
"BACKEND": "config.caches.LocMemCacheWithLock",
"LOCATION": f"care-test-{uuid.uuid4()}",
}
},
Expand Down
21 changes: 21 additions & 0 deletions config/caches.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from contextlib import nullcontext

from django.core.cache.backends import dummy, locmem


class DummyCacheWithLock(dummy.DummyCache):
"""
A dummy cache with lock method to mimic the behavior of python-redis-lock
"""

def lock(self, key, expire=None, id=None, auto_renewal=False):
return nullcontext()


class LocMemCacheWithLock(locmem.LocMemCache):
"""
A locmem cache with lock method to mimic the behavior of python-redis-lock
"""

def lock(self, key, expire=None, id=None, auto_renewal=False):
return nullcontext()
2 changes: 1 addition & 1 deletion config/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
# test in peace
CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.dummy.DummyCache",
"BACKEND": "config.caches.DummyCacheWithLock",
}
}
# for testing retelimit use override_settings decorator
Expand Down

0 comments on commit cfea5ac

Please sign in to comment.