Skip to content

Commit

Permalink
Fixed #35695 -- Ensured FileFields use a storage pointing to a temp d…
Browse files Browse the repository at this point in the history
…irectory in model_fields tests.
  • Loading branch information
Hisham-Pak authored Aug 21, 2024
1 parent ba46b09 commit 5190878
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions tests/model_fields/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
Image = None


# Set up a temp directory for file storage.
temp_storage_dir = tempfile.mkdtemp()
temp_storage = FileSystemStorage(temp_storage_dir)

test_collation = SimpleLazyObject(
lambda: connection.features.test_collations["virtual"]
)
Expand Down Expand Up @@ -206,7 +210,9 @@ class VerboseNameField(models.Model):
field5 = models.DateTimeField("verbose field5")
field6 = models.DecimalField("verbose field6", max_digits=6, decimal_places=1)
field7 = models.EmailField("verbose field7")
field8 = models.FileField("verbose field8", upload_to="unused")
field8 = models.FileField(
"verbose field8", storage=temp_storage, upload_to="unused"
)
field9 = models.FilePathField("verbose field9")
field10 = models.FloatField("verbose field10")
# Don't want to depend on Pillow in this test
Expand Down Expand Up @@ -256,7 +262,7 @@ class DataModel(models.Model):


class Document(models.Model):
myfile = models.FileField(upload_to="unused", unique=True)
myfile = models.FileField(storage=temp_storage, upload_to="unused", unique=True)


###############################################################################
Expand All @@ -282,10 +288,6 @@ def open(self):
class TestImageField(models.ImageField):
attr_class = TestImageFieldFile

# Set up a temp directory for file storage.
temp_storage_dir = tempfile.mkdtemp()
temp_storage = FileSystemStorage(temp_storage_dir)

class Person(models.Model):
"""
Model that defines an ImageField with no dimension fields.
Expand Down

0 comments on commit 5190878

Please sign in to comment.