summaryrefslogtreecommitdiff
path: root/tests/forms_tests/field_tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests/forms_tests/field_tests')
-rw-r--r--tests/forms_tests/field_tests/test_filepathfield.py11
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