| 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 | ====================================================================== |
| 650 | ERROR: test_pickle (model_fields.tests.FileFieldTests) |
| 651 | ---------------------------------------------------------------------- |
| 652 | Traceback (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) |
| 657 | AttributeError: 'FieldFile' object has no attribute 'storage' |
| 658 | """ |
| 659 | self.assertEqual(d.myfile.url, loaded.url) |
| 660 | |