From 3f912ee4189602b4df121c0dc0428673fda5c253 Mon Sep 17 00:00:00 2001 From: TildaDares Date: Sun, 29 Mar 2026 22:02:10 +0100 Subject: Fixed #16429 -- Extracted set_choices() method from FilePathField.__init__(). --- tests/forms_tests/field_tests/test_filepathfield.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests/forms_tests') diff --git a/tests/forms_tests/field_tests/test_filepathfield.py b/tests/forms_tests/field_tests/test_filepathfield.py index 092001b453..116600484a 100644 --- a/tests/forms_tests/field_tests/test_filepathfield.py +++ b/tests/forms_tests/field_tests/test_filepathfield.py @@ -1,4 +1,5 @@ import os.path +import tempfile from django.core.exceptions import ValidationError from django.forms import FilePathField @@ -98,6 +99,16 @@ class FilePathFieldTest(SimpleTestCase): ) self.assertChoices(f, []) + def test_set_choices_picks_up_new_files(self): + with tempfile.TemporaryDirectory() as tmp_dir: + f = FilePathField(path=tmp_dir) + self.assertEqual(f.choices, []) + tmp_file = os.path.join(tmp_dir, "new_file.txt") + open(tmp_file, "w").close() + f.set_choices() + self.assertIn((tmp_file, "new_file.txt"), f.choices) + self.assertIn((tmp_file, "new_file.txt"), f.widget.choices) + def test_recursive_folders_without_files(self): f = FilePathField( path=self.path, recursive=True, allow_folders=True, allow_files=False -- cgit v1.3