Merge pull request #3760 from a17t/dev

[BUG] Set office document creation date with timezone, if it is naive
This commit is contained in:
Trenton H 2023-08-03 10:35:56 -07:00 committed by GitHub
commit e50d30876a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -3,6 +3,7 @@ from pathlib import Path
import httpx
from django.conf import settings
from django.utils import timezone
from tika_client import TikaClient
from documents.parsers import DocumentParser
@ -63,6 +64,9 @@ class TikaDocumentParser(DocumentParser):
self.text = self.text.strip()
self.date = parsed.created
if self.date is not None and timezone.is_naive(self.date):
self.date = timezone.make_aware(self.date)
self.archive_path = self.convert_to_pdf(document_path, file_name)
def convert_to_pdf(self, document_path, file_name):

View File

@ -3,6 +3,11 @@ import os
from pathlib import Path
from unittest import mock
try:
import zoneinfo
except ImportError:
from backports import zoneinfo
from django.test import TestCase
from django.test import override_settings
from httpx import Request
@ -21,6 +26,7 @@ class TestTikaParser(HttpxMockMixin, TestCase):
def tearDown(self) -> None:
self.parser.cleanup()
@override_settings(TIME_ZONE="America/Chicago")
def test_parse(self):
# Pretend parse response
self.httpx_mock.add_response(
@ -46,7 +52,12 @@ class TestTikaParser(HttpxMockMixin, TestCase):
self.assertEqual(
self.parser.date,
datetime.datetime(2020, 11, 21),
datetime.datetime(
2020,
11,
21,
tzinfo=zoneinfo.ZoneInfo("America/Chicago"),
),
)
def test_metadata(self):