Ticket #21238: fieldfile_pickle_test.diff

File fieldfile_pickle_test.diff, 1.5 KB (added by Tim Graham, 10 years ago)
  • tests/model_fields/tests.py

    diff --git a/tests/model_fields/tests.py b/tests/model_fields/tests.py
    index 793538c..9713a7b 100644
    a b class FileFieldTests(unittest.TestCase):  
    631631        except OSError:
    632632            self.fail("Deleting an unset FileField should not raise OSError.")
    633633
     634    def test_pickle(self):
     635        import os
     636        import pickle
     637        from django.utils._os import upath
     638        from django.core.files import File
     639
     640        file_path1 = os.path.join(os.path.dirname(upath(__file__)), "4x8.png")
     641        self.file1 = File(open(file_path1, 'rb'))
     642
     643        d = Document(myfile='something.txt')
     644        d.myfile.save("something.txt", self.file1)
     645        dump = pickle.dumps(d.myfile)
     646        loaded = pickle.loads(dump)
     647
     648""" Fails:
     649======================================================================
     650ERROR: test_pickle (model_fields.tests.FileFieldTests)
     651----------------------------------------------------------------------
     652Traceback (most recent call last):
     653  File "/home/tim/code/django/tests/model_fields/tests.py", line 647, in test_pickle
     654    self.assertEqual(d.myfile.url, loaded.url)
     655  File "/home/tim/code/django/django/db/models/fields/files.py", line 66, in _get_url
     656    return self.storage.url(self.name)
     657AttributeError: 'FieldFile' object has no attribute 'storage'
     658"""
     659        self.assertEqual(d.myfile.url, loaded.url)
     660
    634661
    635662class BinaryFieldTests(test.TestCase):
    636663    binary_data = b'\x00\x46\xFE'
Back to Top