From 912d3840df023ee08eb924800baf38dedec6ef19 Mon Sep 17 00:00:00 2001 From: Trenton Holmes <797416+stumpylog@users.noreply.github.com> Date: Tue, 12 Aug 2025 09:44:41 -0700 Subject: [PATCH] Adds some end to end generate testing with the localization --- src/documents/tests/test_file_handling.py | 33 +++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/documents/tests/test_file_handling.py b/src/documents/tests/test_file_handling.py index c91876470..9e3274dc4 100644 --- a/src/documents/tests/test_file_handling.py +++ b/src/documents/tests/test_file_handling.py @@ -24,6 +24,7 @@ from documents.models import DocumentType from documents.models import StoragePath from documents.tasks import empty_trash from documents.templating.filepath import localize_date +from documents.tests.factories import DocumentFactory from documents.tests.utils import DirectoriesMixin from documents.tests.utils import FileSystemAssertsMixin @@ -1749,3 +1750,35 @@ class TestDateLocalization: localize_date(self.TEST_DATE, "medium", "invalid_locale_code") assert "Invalid locale identifier" in str(excinfo.value) + + @pytest.mark.django_db + @pytest.mark.parametrize( + "filename_format,expected_filename", + [ + pytest.param( + "{{title}}_{{ document.created | localize_date('MMMM', 'es_ES')}}", + "My Document_octubre.pdf", + id="spanish_month_name", + ), + pytest.param( + "{{title}}_{{ document.created | localize_date('EEEE', 'fr_FR')}}", + "My Document_jeudi.pdf", + id="french_day_of_week", + ), + pytest.param( + "{{title}}_{{ document.created | localize_date('dd/MM/yyyy', 'en_GB')}}", + "My Document_26/10/2023.pdf", + id="uk_date_format", + ), + ], + ) + def test_localize_date_path_building(self, filename_format, expected_filename): + document = DocumentFactory.create( + title="My Document", + mime_type="application/pdf", + storage_type=Document.STORAGE_TYPE_UNENCRYPTED, + created=self.TEST_DATE, # 2023-10-26 (which is a Thursday) + ) + with override_settings(FILENAME_FORMAT=filename_format): + filename = generate_filename(document) + assert filename == Path(expected_filename)