Used temporary directory in FileFieldTests.test_pickle().
Using the current directory caused a PermissionError.
This commit is contained in:
parent
c1b24718e0
commit
2e6dc72d83
|
@ -106,31 +106,44 @@ class FileFieldTests(TestCase):
|
||||||
self.assertTrue(os.path.exists(os.path.join(tmp_dir, 'unused', 'foo.txt')))
|
self.assertTrue(os.path.exists(os.path.join(tmp_dir, 'unused', 'foo.txt')))
|
||||||
|
|
||||||
def test_pickle(self):
|
def test_pickle(self):
|
||||||
with open(__file__, 'rb') as fp:
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
file1 = File(fp, name='test_file.py')
|
with override_settings(MEDIA_ROOT=Path(tmp_dir)):
|
||||||
document = Document(myfile='test_file.py')
|
with open(__file__, 'rb') as fp:
|
||||||
document.myfile.save('test_file.py', file1)
|
file1 = File(fp, name='test_file.py')
|
||||||
try:
|
document = Document(myfile='test_file.py')
|
||||||
dump = pickle.dumps(document)
|
document.myfile.save('test_file.py', file1)
|
||||||
loaded_document = pickle.loads(dump)
|
try:
|
||||||
self.assertEqual(document.myfile, loaded_document.myfile)
|
dump = pickle.dumps(document)
|
||||||
self.assertEqual(document.myfile.url, loaded_document.myfile.url)
|
loaded_document = pickle.loads(dump)
|
||||||
self.assertEqual(
|
self.assertEqual(document.myfile, loaded_document.myfile)
|
||||||
document.myfile.storage,
|
self.assertEqual(
|
||||||
loaded_document.myfile.storage,
|
document.myfile.url,
|
||||||
)
|
loaded_document.myfile.url,
|
||||||
self.assertEqual(
|
)
|
||||||
document.myfile.instance,
|
self.assertEqual(
|
||||||
loaded_document.myfile.instance,
|
document.myfile.storage,
|
||||||
)
|
loaded_document.myfile.storage,
|
||||||
self.assertEqual(document.myfile.field, loaded_document.myfile.field)
|
)
|
||||||
|
self.assertEqual(
|
||||||
myfile_dump = pickle.dumps(document.myfile)
|
document.myfile.instance,
|
||||||
loaded_myfile = pickle.loads(myfile_dump)
|
loaded_document.myfile.instance,
|
||||||
self.assertEqual(document.myfile, loaded_myfile)
|
)
|
||||||
self.assertEqual(document.myfile.url, loaded_myfile.url)
|
self.assertEqual(
|
||||||
self.assertEqual(document.myfile.storage, loaded_myfile.storage)
|
document.myfile.field,
|
||||||
self.assertEqual(document.myfile.instance, loaded_myfile.instance)
|
loaded_document.myfile.field,
|
||||||
self.assertEqual(document.myfile.field, loaded_myfile.field)
|
)
|
||||||
finally:
|
myfile_dump = pickle.dumps(document.myfile)
|
||||||
document.myfile.delete()
|
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()
|
||||||
|
|
Loading…
Reference in New Issue