Giter Club home page Giter Club logo

django-fakeredis's People

Contributors

o3o3o avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

django-fakeredis's Issues

Django 3.2 incompatibility

/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 ?

No module TTL and expire

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:

  • Create a new django project: pip install django django_fakeredis pytest, django-admin startproject fakeredisbug
  • Create example.py and example_test.py as provided below inside the application (path: fakeredisbug/fakeredisbug)
  • Add cache settings to django settings (you can use dummy cache for now)
  • run pytest: DJANGO_SETTINGS_MODULE=fakeredisbug.settings pytest. Observe the result

example.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 ==============================================================

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.