Finally figures out that hex thing
This commit is contained in:
parent
31b19a48b7
commit
88a9c5079b
@ -62,20 +62,6 @@ def get_suggestion_cache(document_id: int) -> Optional[SuggestionCacheData]:
|
|||||||
# The classifier format is the same
|
# The classifier format is the same
|
||||||
# The classifier hash is the same
|
# The classifier hash is the same
|
||||||
# Then the suggestions can be used
|
# 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 (
|
if (
|
||||||
CLASSIFIER_VERSION_KEY in cache_hits
|
CLASSIFIER_VERSION_KEY in cache_hits
|
||||||
and cache_hits[CLASSIFIER_VERSION_KEY] == DocumentClassifier.FORMAT_VERSION
|
and cache_hits[CLASSIFIER_VERSION_KEY] == DocumentClassifier.FORMAT_VERSION
|
||||||
|
@ -4,6 +4,7 @@ import shutil
|
|||||||
import tempfile
|
import tempfile
|
||||||
import uuid
|
import uuid
|
||||||
import zoneinfo
|
import zoneinfo
|
||||||
|
from binascii import hexlify
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from unittest import mock
|
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["original_size"], os.stat(source_file).st_size)
|
||||||
self.assertEqual(meta["archive_size"], os.stat(archive_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):
|
def test_get_metadata_invalid_doc(self):
|
||||||
response = self.client.get("/api/documents/34576/metadata/")
|
response = self.client.get("/api/documents/34576/metadata/")
|
||||||
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
|
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
|
||||||
@ -1301,23 +1305,24 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
|
|||||||
|
|
||||||
settings.MODEL_FILE.touch()
|
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
|
# Two loads, so two side effects
|
||||||
mocked_load.side_effect = [
|
mocked_load.side_effect = [
|
||||||
mock.Mock(
|
mock.Mock(
|
||||||
last_auto_type_hash=classifier_checksum,
|
last_auto_type_hash=classifier_checksum_bytes,
|
||||||
FORMAT_VERSION=DocumentClassifier.FORMAT_VERSION,
|
FORMAT_VERSION=DocumentClassifier.FORMAT_VERSION,
|
||||||
),
|
),
|
||||||
mock.Mock(
|
mock.Mock(
|
||||||
last_auto_type_hash=classifier_checksum,
|
last_auto_type_hash=classifier_checksum_bytes,
|
||||||
FORMAT_VERSION=DocumentClassifier.FORMAT_VERSION,
|
FORMAT_VERSION=DocumentClassifier.FORMAT_VERSION,
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
last_modified = timezone.now()
|
last_modified = timezone.now()
|
||||||
cache.set(CLASSIFIER_MODIFIED_KEY, last_modified, CACHE_50_MINUTES)
|
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(
|
cache.set(
|
||||||
CLASSIFIER_VERSION_KEY,
|
CLASSIFIER_VERSION_KEY,
|
||||||
DocumentClassifier.FORMAT_VERSION,
|
DocumentClassifier.FORMAT_VERSION,
|
||||||
@ -1356,7 +1361,7 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
|
|||||||
self.assertIn("ETag", response.headers)
|
self.assertIn("ETag", response.headers)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
response.headers["ETag"],
|
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/")
|
response = self.client.get(f"/api/documents/{doc.pk}/suggestions/")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user