1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Added file cleanup in FileFieldTests.test_pickle().

This commit is contained in:
Carlton Gibson 2020-01-09 20:43:50 +01:00 committed by Mariusz Felisiak
parent aa6c620249
commit 4c1b401e82

View File

@ -110,19 +110,27 @@ class FileFieldTests(TestCase):
file1 = File(fp, name='test_file.py')
document = Document(myfile='test_file.py')
document.myfile.save('test_file.py', file1)
try:
dump = pickle.dumps(document)
loaded_document = pickle.loads(dump)
self.assertEqual(document.myfile, loaded_document.myfile)
self.assertEqual(document.myfile.url, loaded_document.myfile.url)
self.assertEqual(
document.myfile.storage,
loaded_document.myfile.storage,
)
self.assertEqual(
document.myfile.instance,
loaded_document.myfile.instance,
)
self.assertEqual(document.myfile.field, loaded_document.myfile.field)
dump = pickle.dumps(document)
loaded_document = pickle.loads(dump)
self.assertEqual(document.myfile, loaded_document.myfile)
self.assertEqual(document.myfile.url, loaded_document.myfile.url)
self.assertEqual(document.myfile.storage, loaded_document.myfile.storage)
self.assertEqual(document.myfile.instance, loaded_document.myfile.instance)
self.assertEqual(document.myfile.field, loaded_document.myfile.field)
myfile_dump = pickle.dumps(document.myfile)
loaded_myfile = pickle.loads(myfile_dump)
self.assertEqual(document.myfile, loaded_myfile)
self.assertEqual(document.myfile.url, loaded_myfile.url)
self.assertEqual(document.myfile.storage, loaded_myfile.storage)
self.assertEqual(document.myfile.instance, loaded_myfile.instance)
self.assertEqual(document.myfile.field, loaded_myfile.field)
myfile_dump = pickle.dumps(document.myfile)
loaded_myfile = pickle.loads(myfile_dump)
self.assertEqual(document.myfile, loaded_myfile)
self.assertEqual(document.myfile.url, loaded_myfile.url)
self.assertEqual(document.myfile.storage, loaded_myfile.storage)
self.assertEqual(document.myfile.instance, loaded_myfile.instance)
self.assertEqual(document.myfile.field, loaded_myfile.field)
finally:
document.myfile.delete()