From 88a9c5079bde7cb25fb2b95361839e627cfcdbdf Mon Sep 17 00:00:00 2001 From: Trenton H <797416+stumpylog@users.noreply.github.com> Date: Sat, 3 Feb 2024 14:42:19 -0800 Subject: [PATCH] Finally figures out that hex thing --- src/documents/caching.py | 14 -------------- src/documents/tests/test_api_documents.py | 15 ++++++++++----- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/documents/caching.py b/src/documents/caching.py index 4441c611d..0eaf9fe71 100644 --- a/src/documents/caching.py +++ b/src/documents/caching.py @@ -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 diff --git a/src/documents/tests/test_api_documents.py b/src/documents/tests/test_api_documents.py index f3199a30f..d7ae1eeb7 100644 --- a/src/documents/tests/test_api_documents.py +++ b/src/documents/tests/test_api_documents.py @@ -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/")