Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise correct error message when create cache proxy with absent cache type #794

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aiocache/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Cache:
MEMCACHED = AIOCACHE_CACHES.get("memcached")

def __new__(cls, cache_class=MEMORY, **kwargs):
if not issubclass(cache_class, BaseCache):
if not (cache_class and issubclass(cache_class, BaseCache)):
raise InvalidCacheType(
"Invalid cache type, you can only use {}".format(list(AIOCACHE_CACHES.keys()))
)
Expand Down
5 changes: 3 additions & 2 deletions tests/ut/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ async def test_new(self, cache_type):
def test_new_defaults_to_memory(self):
assert isinstance(Cache(), Cache.MEMORY)

def test_new_invalid_cache_raises(self):
@pytest.mark.parametrize("cache_type", (None, object))
def test_new_invalid_cache_raises(self, cache_type):
with pytest.raises(InvalidCacheType) as e:
Cache(object)
Cache(cache_type)
assert str(e.value) == "Invalid cache type, you can only use {}".format(
list(AIOCACHE_CACHES.keys())
)
Expand Down