summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorIngo Klöcker <djangoproject@ingo-kloecker.de>2017-04-07 15:41:39 +0200
committerTim Graham <timograham@gmail.com>2017-05-31 21:02:58 -0400
commit6bb3b2bff4bca24896023758a720f16fa6b1e2bb (patch)
treeffc4886d045b62d30777797b63eaa7ab00005cfb /tests
parenteee34ef64c026e3274c6d1b4fa2baffbc956b954 (diff)
Refs #27777 -- Improved docs/added test for File context manager change.
Diffstat (limited to 'tests')
-rw-r--r--tests/model_fields/test_filefield.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/model_fields/test_filefield.py b/tests/model_fields/test_filefield.py
index 3fefcd1fb6..9330a2eba2 100644
--- a/tests/model_fields/test_filefield.py
+++ b/tests/model_fields/test_filefield.py
@@ -3,6 +3,7 @@ import sys
import unittest
from django.core.files import temp
+from django.core.files.base import ContentFile
from django.core.files.uploadedfile import TemporaryUploadedFile
from django.db.utils import IntegrityError
from django.test import TestCase, override_settings
@@ -83,3 +84,13 @@ class FileFieldTests(TestCase):
tmp_file_path = tmp_file.temporary_file_path()
Document.objects.create(myfile=tmp_file)
self.assertFalse(os.path.exists(tmp_file_path), 'Temporary file still exists')
+
+ def test_open_returns_self(self):
+ """
+ FieldField.open() returns self so it can be used as a context manager.
+ """
+ d = Document.objects.create(myfile='something.txt')
+ # Replace the FileField's file with an in-memory ContentFile, so that
+ # open() doesn't write to disk.
+ d.myfile.file = ContentFile(b'', name='bla')
+ self.assertEqual(d.myfile, d.myfile.open())