Skip to content

Commit

Permalink
Fix nodeps tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iurisilvio committed Aug 3, 2023
1 parent 910cd3f commit 5ab1e0e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
28 changes: 17 additions & 11 deletions django_cache_mock/backends/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

logger = logging.getLogger(__name__)


try:
from django.core.cache.backends.redis import RedisCache, RedisCacheClient

Expand Down Expand Up @@ -82,18 +81,25 @@ class BaseDjangoRedisRedisCache(LazyLibImportError):
parent_exception = _import_error


class RedisLiteMixin:
def __init__(self, server, params):
import redislite
try:
import redislite

class RedisLiteMixin:
def __init__(self, server, params):
self.library = redislite
self.client_class = redislite.StrictRedis
self.dbfilename = server or "redislite.db"
super().__init__(server, params)

@property
def redis_client_cls_kwargs(self):
return {"dbfilename": self.dbfilename}

self.library = redislite
self.client_class = redislite.StrictRedis
self.dbfilename = server or "redislite.db"
super().__init__(server, params)
except ImportError as _import_error:
logger.debug("redislite is not installed.")

@property
def redis_client_cls_kwargs(self):
return {"dbfilename": self.dbfilename}
class RedisLiteMixin(LazyLibImportError):

Check warning on line 101 in django_cache_mock/backends/redis.py

View check run for this annotation

Codecov / codecov/patch

django_cache_mock/backends/redis.py#L101

Added line #L101 was not covered by tests
parent_exception = _import_error


try:
Expand Down
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ def _validate_backend_installed(cache_alias):
if issubclass(backend, LazyLibImportError):
return False

try:
caches[cache_alias]
except ImportError:

Check warning on line 36 in tests/conftest.py

View check run for this annotation

Codecov / codecov/patch

tests/conftest.py#L36

Added line #L36 was not covered by tests
return False

return True


Expand Down
4 changes: 2 additions & 2 deletions tests/test_backends.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from django.conf import settings
from django.core.cache import InvalidCacheBackendError, caches
from django.core.cache import caches

from django_cache_mock.exceptions import LazyLibImportError
from tests.thread_with_exceptions import Thread
Expand Down Expand Up @@ -73,7 +73,7 @@ def test_memcached_import_error(memcached_cache_alias_not_installed):
cache_alias = memcached_cache_alias_not_installed
try:
caches[cache_alias]
except InvalidCacheBackendError:
except ImportError:

Check warning on line 76 in tests/test_backends.py

View check run for this annotation

Codecov / codecov/patch

tests/test_backends.py#L76

Added line #L76 was not covered by tests
pass
else: # pragma: no cover
pytest.fail("Cache unexpectedly worked.")

0 comments on commit 5ab1e0e

Please sign in to comment.