File: test_low_level.py

package info (click to toggle)
django-cacheops 7.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 404 kB
  • sloc: python: 3,189; sh: 7; makefile: 4
file content (22 lines) | stat: -rw-r--r-- 499 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import pytest

from cacheops.redis import redis_client

from .models import User
from .utils import BaseTestCase


@pytest.fixture()
def base(db):
    case = BaseTestCase()
    case.setUp()
    yield
    case.tearDown()


def test_ttl(base):
    user = User.objects.create(username='Suor')
    qs = User.objects.cache(timeout=100).filter(pk=user.pk)
    list(qs)
    assert 90 <= redis_client.ttl(qs._cache_key()) <= 100
    assert redis_client.ttl(f'{qs._prefix}conj:auth_user:id={user.id}') > 100