mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-12-03 17:58:41 +00:00
* Fix: sign cache entries so values planted in Redis are never unpickled * Guards against the small window where the suggestion cache could return a version and a None from get_many
31 lines
1.0 KiB
Python
31 lines
1.0 KiB
Python
from pytest_mock import MockerFixture
|
|
|
|
from documents.caching import CLASSIFIER_VERSION_KEY
|
|
from documents.caching import get_suggestion_cache
|
|
from documents.caching import get_suggestion_cache_key
|
|
from documents.classifier import DocumentClassifier
|
|
|
|
|
|
class TestGetSuggestionCache:
|
|
def test_rejected_entry_is_a_cache_miss(self, mocker: MockerFixture) -> None:
|
|
"""
|
|
GIVEN:
|
|
- A document suggestion entry the cache serializer rejected, which
|
|
get_many reports as None
|
|
- A classifier version entry matching the current format
|
|
WHEN:
|
|
- The suggestion cache is read
|
|
THEN:
|
|
- It is treated as a cache miss
|
|
"""
|
|
doc_key = get_suggestion_cache_key(1)
|
|
mocker.patch(
|
|
"documents.caching.cache.get_many",
|
|
return_value={
|
|
CLASSIFIER_VERSION_KEY: DocumentClassifier.FORMAT_VERSION,
|
|
doc_key: None,
|
|
},
|
|
)
|
|
|
|
assert get_suggestion_cache(1) is None
|