Пример #1
0
 def test_store_upload_local_direct_no_file_store_path(self):
     fsp = local_settings.FILE_STORE_PATH
     local_settings.FILE_STORE_PATH = None
     tu = TemporaryUpload.objects.get(upload_id=self.upload_id)
     with self.assertRaisesMessage(
             ValueError, 'The FILE_STORE_PATH is not set to a directory.'):
         _store_upload_local('/test_storage', 'test_file.txt', tu)
     local_settings.FILE_STORE_PATH = fsp
Пример #2
0
 def test_store_upload_local_direct_missing_store_path(self):
     fsp = local_settings.FILE_STORE_PATH
     test_dir = '/tmp/%s' % _get_file_id()
     local_settings.FILE_STORE_PATH = test_dir
     with self.assertRaisesMessage(
             FileNotFoundError,
             'The local output directory [%s] defined by '
             'FILE_STORE_PATH is missing.' % test_dir):
         _store_upload_local('/test_storage', 'test_file.txt', None)
     local_settings.FILE_STORE_PATH = fsp
Пример #3
0
 def test_store_upload_local_direct_file_exists(self):
     filestore_base = getattr(local_settings, 'FILE_STORE_PATH', None)
     target_file_dir = os.path.join(filestore_base, 'test_storage')
     os.mkdir(target_file_dir)
     with open(os.path.join(target_file_dir, 'testfile.txt'), 'a') as f:
         f.write('\n')
     tu = TemporaryUpload.objects.get(upload_id=self.upload_id)
     with self.assertRaisesMessage(
             FileExistsError,
             'The specified temporary file cannot be stored to the '
             'specified location - file exists.'):
         _store_upload_local('/test_storage', 'testfile.txt', tu)
Пример #4
0
 def test_store_upload_local_copy_to_store_fails(self):
     tu = TemporaryUpload.objects.get(upload_id=self.upload_id)
     with patch('shutil.copy2') as copy2_patch:
         with patch('os.path.exists') as exists_patch:
             with patch('os.path.isdir') as isdir_patch:
                 exists_patch.side_effect = [True, False, True]
                 isdir_patch.return_value = True
                 copy2_patch.side_effect = IOError(
                     'Error moving temporary file to permanent storage '
                     'location')
                 with self.assertRaisesMessage(
                         IOError,
                         'Error moving temporary file to permanent '
                         'storage location'):
                     _store_upload_local('/test_storage', 'testfile.txt',
                                         tu)