Пример #1
0
 def setup_method(self, method):
     TestCase.setup_method(self, method)
     self.path = os.path.join(
         os.path.dirname(__file__),
         'uploads',
         'images'
     )
     self.rel_path = os.path.join('uploads', 'images')
     self.storage = FileSystemStorage(os.path.dirname(__file__))
     self.file = 'some_file.txt'
Пример #2
0
 def test_if_file_view_not_set_uses_application_config_value_as_view(self):
     self.app.config['FILE_SYSTEM_STORAGE_FILE_VIEW'] = 'custom.file_view'
     storage = FileSystemStorage()
     called_url_for = (
         flexmock(flask_storage.filesystem)
         .should_receive('url_for')
         .once()
         .with_args('custom.file_view', filename='file_name')
     )
     storage.url('file_name')
     called_url_for.verify()
Пример #3
0
class FileSystemTestCase(TestCase):
    def setup_method(self, method):
        TestCase.setup_method(self, method)
        self.path = os.path.join(
            os.path.dirname(__file__),
            'uploads',
            'images'
        )
        self.rel_path = os.path.join('uploads', 'images')
        self.storage = FileSystemStorage(os.path.dirname(__file__))
        self.file = 'some_file.txt'

    def teardown_method(self, method):
        shutil.rmtree(os.path.join(
            os.path.dirname(__file__),
            'uploads'
        ), ignore_errors=True)
        try:
            self.storage.delete(self.file)
        except StorageException:
            pass
Пример #4
0
 def test_conflict_exception_contains_proper_status_code(self):
     storage = FileSystemStorage(os.path.dirname(__file__))
     storage.save('uploads', 'some text')
     try:
         storage.create_folder('uploads')
         assert False
     except StorageException, e:
         assert e.status_code == 409
         assert e.message
Пример #5
0
 def test_deletes_folder_on_success(self):
     storage = FileSystemStorage(os.path.dirname(__file__))
     storage.create_folder(self.path)
     storage.delete_folder(self.path)
     assert not os.path.exists(self.path)
Пример #6
0
 def test_raises_exception_on_file_conflict(self):
     storage = FileSystemStorage(os.path.dirname(__file__))
     storage.save('uploads', 'some text')
     with raises(StorageException):
         storage.create_folder('uploads')
Пример #7
0
 def test_raises_exception_on_folder_conflict(self):
     storage = FileSystemStorage(os.path.dirname(__file__))
     storage.create_folder(self.path)
     with raises(StorageException):
         storage.create_folder(self.path)
Пример #8
0
 def test_if_folder_not_set_uses_application_config_default(self):
     self.app.config['UPLOADS_FOLDER'] = self.path
     storage = FileSystemStorage()
     assert self.rel_path in storage.folder_name
Пример #9
0
 def test_new_file(self):
     storage = FileSystemStorage(os.path.dirname(__file__))
     assert isinstance(storage.new_file(), FileSystemStorageFile)
Пример #10
0
 def test_returns_file_object_on_success(self):
     storage = FileSystemStorage(os.path.dirname(__file__))
     obj = storage.save(self.file, 'value')
     assert obj.name == self.file
Пример #11
0
 def test_returns_file_object_on_success(self):
     storage = FileSystemStorage(os.path.dirname(__file__))
     storage.save(self.file, 'something')
     file_ = storage.open(self.file, 'rb')
     assert isinstance(file_, FileSystemStorageFile)
Пример #12
0
 def test_returns_list_of_files_on_success(self):
     storage = FileSystemStorage(os.path.dirname(__file__))
     assert os.path.basename(__file__) in storage.list_files()
Пример #13
0
 def test_returns_list_of_folders_on_success(self):
     storage = FileSystemStorage(os.path.dirname(__file__))
     storage.create_folder(self.path)
     assert 'uploads' in storage.list_folders()
Пример #14
0
 def test_raises_exception_if_folder_does_not_exist(self):
     storage = FileSystemStorage(os.path.dirname(__file__))
     with raises(StorageException):
         storage.delete_folder(self.path)
Пример #15
-1
 def test_raises_exception_for_unknown_file(self):
     storage = FileSystemStorage(os.path.dirname(__file__))
     with raises(StorageException):
         storage.delete('some_unknown_file')