Finally figures out that hex thing

This commit is contained in:
Trenton H 2024-02-03 14:42:19 -08:00
parent 31b19a48b7
commit 88a9c5079b
2 changed files with 10 additions and 19 deletions

View File

@ -62,20 +62,6 @@ def get_suggestion_cache(document_id: int) -> Optional[SuggestionCacheData]:
# The classifier format is the same
# The classifier hash is the same
# Then the suggestions can be used
print(CLASSIFIER_VERSION_KEY in cache_hits)
if CLASSIFIER_VERSION_KEY in cache_hits:
print(
cache_hits[CLASSIFIER_VERSION_KEY] == DocumentClassifier.FORMAT_VERSION,
)
print(
cache_hits[CLASSIFIER_VERSION_KEY]
== doc_suggestions.classifier_version,
)
print(CLASSIFIER_HASH_KEY in cache_hits)
if CLASSIFIER_HASH_KEY in cache_hits:
print(cache_hits[CLASSIFIER_HASH_KEY])
print(doc_suggestions.classifier_hash)
print(cache_hits[CLASSIFIER_HASH_KEY] == doc_suggestions.classifier_hash)
if (
CLASSIFIER_VERSION_KEY in cache_hits
and cache_hits[CLASSIFIER_VERSION_KEY] == DocumentClassifier.FORMAT_VERSION

View File

@ -4,6 +4,7 @@ import shutil
import tempfile
import uuid
import zoneinfo
from binascii import hexlify
from datetime import timedelta
from pathlib import Path
from unittest import mock
@ -1168,6 +1169,9 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
self.assertEqual(meta["original_size"], os.stat(source_file).st_size)
self.assertEqual(meta["archive_size"], os.stat(archive_file).st_size)
response = self.client.get(f"/api/documents/{doc.pk}/metadata/")
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_get_metadata_invalid_doc(self):
response = self.client.get("/api/documents/34576/metadata/")
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
@ -1301,23 +1305,24 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
settings.MODEL_FILE.touch()
classifier_checksum = b"thisisachecksum"
classifier_checksum_bytes = b"thisisachecksum"
classifier_checksum_hex = hexlify(classifier_checksum_bytes).decode()
# Two loads, so two side effects
mocked_load.side_effect = [
mock.Mock(
last_auto_type_hash=classifier_checksum,
last_auto_type_hash=classifier_checksum_bytes,
FORMAT_VERSION=DocumentClassifier.FORMAT_VERSION,
),
mock.Mock(
last_auto_type_hash=classifier_checksum,
last_auto_type_hash=classifier_checksum_bytes,
FORMAT_VERSION=DocumentClassifier.FORMAT_VERSION,
),
]
last_modified = timezone.now()
cache.set(CLASSIFIER_MODIFIED_KEY, last_modified, CACHE_50_MINUTES)
cache.set(CLASSIFIER_HASH_KEY, classifier_checksum.decode(), CACHE_50_MINUTES)
cache.set(CLASSIFIER_HASH_KEY, classifier_checksum_hex, CACHE_50_MINUTES)
cache.set(
CLASSIFIER_VERSION_KEY,
DocumentClassifier.FORMAT_VERSION,
@ -1356,7 +1361,7 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
self.assertIn("ETag", response.headers)
self.assertEqual(
response.headers["ETag"],
f'"{classifier_checksum.decode()}:{settings.NUMBER_OF_SUGGESTED_DATES}"',
f'"{classifier_checksum_hex}:{settings.NUMBER_OF_SUGGESTED_DATES}"',
)
response = self.client.get(f"/api/documents/{doc.pk}/suggestions/")