o3o3o / django-fakeredis Goto Github PK
View Code? Open in Web Editor NEWVery simple tool to use fakeredis more easily in django
Home Page: https://pypi.org/project/django-fakeredis/
Very simple tool to use fakeredis more easily in django
Home Page: https://pypi.org/project/django-fakeredis/
/usr/local/lib/python3.9/site-packages/django_fakeredis/__init__.py:1: in <module>
from .fakeredis import FakeRedis
/usr/local/lib/python3.9/site-packages/django_fakeredis/fakeredis.py:3: in <module>
from django.core.cache import DefaultCacheProxy
E ImportError: cannot import name 'DefaultCacheProxy' from 'django.core.cache' (/usr/local/lib/python3.9/site-packages/django/core/cache/__init__.py)
this DefaultCacheProxy
import is not used is fakeredis.py
. So can be removed ?
In my code, I am trying to use expire and TTL methods, which are natural to use when using redis cache backend. But they raise TypeError when unittesting with this library.
Steps to reproduce:
pip install django django_fakeredis pytest
, django-admin startproject fakeredisbug
example.py
and example_test.py
as provided below inside the application (path: fakeredisbug/fakeredisbug
)DJANGO_SETTINGS_MODULE=fakeredisbug.settings pytest
. Observe the resultexample.py
from django.core.cache import cache
def set_cache(key, val, expire):
cache.set(key, val, expire)
return cache.ttl(key)
example_test.py
from django_fakeredis.fakeredis import FakeRedis
from fakeredisbug.example import set_cache
@FakeRedis("fakeredisbug.example.cache")
def test_set_cache():
expire = set_cache("a", "b", 300)
assert expire == 300
Result:
============================================================= test session starts =============================================================
platform darwin -- Python 3.9.9, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /Users/ashutosh/code/office/test
collected 1 item
fakeredisbug/fakeredisbug/example_test.py F [100%]
================================================================== FAILURES ===================================================================
_______________________________________________________________ test_set_cache ________________________________________________________________
@FakeRedis("fakeredisbug.example.cache")
def test_set_cache():
> expire = set_cache("a", "b", 300)
fakeredisbug/fakeredisbug/example_test.py:7:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
fakeredisbug/fakeredisbug/example.py:6: in set_cache
return cache.ttl(key)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <django.utils.connection.ConnectionProxy object at 0x1040def70>, item = 'ttl'
def __getattr__(self, item):
> return getattr(self._connections[self._alias], item)
E AttributeError: 'LocMemCache' object has no attribute 'ttl'
venv/lib/python3.9/site-packages/django/utils/connection.py:15: AttributeError
=========================================================== short test summary info ===========================================================
FAILED fakeredisbug/fakeredisbug/example_test.py::test_set_cache - AttributeError: 'LocMemCache' object has no attribute 'ttl'
============================================================== 1 failed in 0.14s ==============================================================
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.