More easier to use fakeredis in django.
Project description
More easier to use fakeredis in django.
Install
pip install django-fakeredis
Why use it?
I have experienced many times to find bugs which is caused by mutiple fakeredis instances in tests. We just want to use fakerredis like redis with one redis-server and different connections.
Pros:
- One fakeredis server with mutiple connections for tests like the way of using redis.
- Combine override settings to DummyCACHE and fake get_redis_connection
- To disable the fake action with passing env: "NOFAKE_REDIS=1"
NOFAKE_REDIS=1 python manage.py test
Before you use django_fakeredis, your everty test code maybe like that:
server = fakeredis.FakeServer()
@override_settings(CACHES={"default": {"BACKEND": "django.core.cache.backends.dummy.DummyCache" }})
@patch('foo.get_redis_connection', fakeredis.FakeRedis(server=server)
def test_sth():
....
Now your can just:
@FakeRedis("yourpath.get_redis_connection")
def test_sth():
...
Usage
from django_fakeredis import FakeRedis
@FakeRedis("yourpath.get_redis_connection")
def test_foo():
...
from django_fakeredis import FakeRedis
with FakeRedis("yourpath.get_redis_connection"):
foo()
from django_fakeredis import FakeRedis
with FakeRedis("yourpath.cache"):
foo()
NOTE
If you want to mock django.core.cache.cache with fakeredis, you should notice that there are internal cast in django cache.
i.e:
from django.core.cache import cache
cache.set("key", 2)
assert cache.get("key") == 2
but if you use fakeredis, you have to cast by hand:
con.set("key", 2)
concache.get("key").decode('utf8') == "2"
So I suggest to use django_redis with fakeredis in django.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django-fakeredis-0.0.4.tar.gz.
File metadata
- Download URL: django-fakeredis-0.0.4.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.29.1 CPython/3.6.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16f0fa2975df907b95ad8a84097b01c62f7cd10af7a8f3870b0b7e81b6393e30
|
|
| MD5 |
02e6a3c5959ce6cde596ddc261815660
|
|
| BLAKE2b-256 |
9831f1d775545ac38cd8434210e6c47772c6ff98f237a5d6288864db1df09c81
|
File details
Details for the file django_fakeredis-0.0.4-py3-none-any.whl.
File metadata
- Download URL: django_fakeredis-0.0.4-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.29.1 CPython/3.6.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5daedded4e82a4ef6bbb04fb2f1dbde53995612aba53a52e8a87c03d6a732518
|
|
| MD5 |
c4fc87682a602159ba0100dda0c740d4
|
|
| BLAKE2b-256 |
370dd8456aba336dba91f312add4372526f6e656b6e377bd5101074f0a9764e2
|