diff options
| author | TildaDares <mathildaudufo@gmail.com> | 2026-03-29 22:02:10 +0100 |
|---|---|---|
| committer | Jacob Walls <jacobtylerwalls@gmail.com> | 2026-04-29 14:52:25 -0400 |
| commit | 3f912ee4189602b4df121c0dc0428673fda5c253 (patch) | |
| tree | f696c3609f6de8520932a662c88f4918b5fba7fb /tests/forms_tests/field_tests | |
| parent | 60a9c70496e5d7b971928ce3da5b47c8836a4def (diff) | |
Fixed #16429 -- Extracted set_choices() method from FilePathField.__init__().
Diffstat (limited to 'tests/forms_tests/field_tests')
| -rw-r--r-- | tests/forms_tests/field_tests/test_filepathfield.py | 11 |
1 files changed, 11 insertions, 0 deletions
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 |
