misc: set cache_duration to 5 seconds as combo's card cells (#85755)
This commit is contained in:
parent
56abb63c39
commit
e82ce47d9d
|
@ -261,6 +261,7 @@ class LazyCardDefObjectsManager:
|
|||
user=None if without_user else self._user,
|
||||
without_user=without_user,
|
||||
log_errors=False,
|
||||
cache_duration=5,
|
||||
)
|
||||
response.raise_for_status()
|
||||
except RequestException:
|
||||
|
|
|
@ -8,3 +8,11 @@ def nocache(settings):
|
|||
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def django_cache():
|
||||
from django.core.cache import cache
|
||||
|
||||
cache.clear()
|
||||
return cache
|
||||
|
|
|
@ -679,3 +679,37 @@ def test_order_by(mock_send, context, nocache):
|
|||
t = Template('{{ foobar|order_by:"foo" }}')
|
||||
t.render(context)
|
||||
assert mock_send.call_args_list == []
|
||||
|
||||
|
||||
@mock.patch('requests.Session.send', side_effect=mocked_requests_send)
|
||||
def test_cache(mock_send, settings, context, django_cache, freezer):
|
||||
t = Template('{% for card in cards|objects:"foo" %}{{ card.id }} {% endfor %}')
|
||||
assert t.render(context) == '1 2 '
|
||||
assert mock_send.call_count == 1
|
||||
|
||||
t = Template('{% for card in cards|objects:"foo" %}{{ card.id }} {% endfor %}')
|
||||
assert t.render(context) == '1 2 '
|
||||
assert mock_send.call_count == 1
|
||||
|
||||
django_cache.clear()
|
||||
|
||||
t = Template('{% for card in cards|objects:"foo" %}{{ card.id }} {% endfor %}')
|
||||
assert t.render(context) == '1 2 '
|
||||
assert mock_send.call_count == 2
|
||||
|
||||
t = Template('{% for card in cards|objects:"foo" %}{{ card.id }} {% endfor %}')
|
||||
assert t.render(context) == '1 2 '
|
||||
assert mock_send.call_count == 2
|
||||
|
||||
freezer.tick(4)
|
||||
|
||||
t = Template('{% for card in cards|objects:"foo" %}{{ card.id }} {% endfor %}')
|
||||
assert t.render(context) == '1 2 '
|
||||
assert mock_send.call_count == 2
|
||||
|
||||
# cache duration is 5 seconds
|
||||
freezer.tick(1.1)
|
||||
|
||||
t = Template('{% for card in cards|objects:"foo" %}{{ card.id }} {% endfor %}')
|
||||
assert t.render(context) == '1 2 '
|
||||
assert mock_send.call_count == 3
|
||||
|
|
Loading…
Reference in New Issue