Source

importosimportshutilfromdjango.testimportTestCasefromdjango.core.files.baseimportContentFilefromdjango.confimportsettingsfromstorages.backends.hashpathimportHashPathStorageclassHashPathStorageTest(TestCase):defsetUp(self):self.storage=HashPathStorage()# make sure the profile upload folder existsifnotos.path.exists(settings.MEDIA_ROOT):os.makedirs(settings.MEDIA_ROOT)deftearDown(self):# remove uploaded profile pictureifos.path.exists(settings.MEDIA_ROOT):shutil.rmtree(settings.MEDIA_ROOT)deftest_save_same_file(self):""" saves a file twice, the file should only be stored once, because the content/hash is the same """path_1=self.storage.save('test',ContentFile('new content'))path_2=self.storage.save('test',ContentFile('new content'))self.assertEqual(path_1,path_2)