Пример #1
0
 def test_open_raises_excetion_for_unknown_file(self):
     storage = MockStorage()
     with raises(FileNotFoundError):
         storage.open('key')
Пример #2
0
 def test_new_file(self):
     storage = MockStorage()
     assert isinstance(storage.new_file(), MockStorageFile)
Пример #3
0
 def test_reads_file_object_and_saves_in_dict(self):
     storage = MockStorage()
     io = StringIO()
     io.write('file contents')
     storage.save('key', io)
     assert storage.open('key').read() == 'file contents'
Пример #4
0
 def test_supports_directories_in_file_names(self):
     storage = MockStorage()
     storage.save('some_dir/filename.txt', 'something')
     assert storage.open('some_dir/filename.txt').read() == 'something'
Пример #5
0
 def test_returns_file_url(self):
     storage = MockStorage('/uploads')
     file_ = storage.save('key', '123123')
     assert file_.url == '/uploads/key'
Пример #6
0
 def test_save_returns_file_object_on_success(self):
     storage = MockStorage()
     obj = storage.save('key', 'value')
     assert obj.name == 'key'
Пример #7
0
 def test_returns_file_url(self):
     storage = MockStorage('/uploads')
     storage.save('key', '')
     assert storage.url('key') == '/uploads/key'
Пример #8
0
 def test_supports_file_objects_without_name(self):
     storage = MockStorage('uploads')
     file_ = MockStorageFile(storage)
     assert bool(file_) is False
Пример #9
0
 def test_save_supports_overwrite(self):
     storage = MockStorage()
     storage.save('key', 'value')
     storage.save('key', 'value 2', overwrite=True)
     assert len(MockStorage._files) == 1
Пример #10
0
 def test_reads_file_object_and_saves_in_dict(self):
     storage = MockStorage()
     io = StringIO()
     io.write('file contents')
     storage.save('key', io)
     assert storage.open('key').read() == 'file contents'
Пример #11
0
 def test_save_returns_file_object_on_success(self):
     storage = MockStorage()
     obj = storage.save('key', 'value')
     assert obj.name == 'key'
Пример #12
0
 def test_saves_key_value_pair_in_dict(self):
     storage = MockStorage()
     storage.save('key', '')
     assert storage.exists('key')
Пример #13
0
 def test_assigns_folder_on_initialization(self):
     storage = MockStorage('uploads')
     assert storage.folder_name == 'uploads'
Пример #14
0
 def test_size_returns_the_associated_file_size(self):
     storage = MockStorage('uploads')
     storage.save('key', '123123')
     file_ = storage.open('key')
     assert file_.size == 6
Пример #15
0
 def test_supports_directories_in_file_names(self):
     storage = MockStorage()
     storage.save('some_dir/filename.txt', 'something')
     assert storage.open('some_dir/filename.txt').read() == 'something'
Пример #16
0
 def test_rename_throws_error(self):
     storage = MockStorage('uploads')
     file_ = MockStorageFile(storage)
     file_.name = 'some_key'
     with raises(StorageException):
         file_.name = 'some_key2'
Пример #17
0
 def test_open_returns_file_object(self):
     storage = MockStorage()
     storage.save('key', '')
     file_ = storage.open('key')
     assert isinstance(file_, MockStorageFile)
Пример #18
0
 def test_returns_file_url(self):
     storage = MockStorage('/uploads')
     file_ = storage.save('key', '123123')
     assert file_.url == '/uploads/key'
Пример #19
0
 def test_open_raises_excetion_for_unknown_file(self):
     storage = MockStorage()
     with raises(FileNotFoundError):
         storage.open('key')
Пример #20
0
 def test_saves_key_value_pair_in_dict(self):
     storage = MockStorage()
     storage.save('key', '')
     assert storage.exists('key')
Пример #21
0
 def test_delete_raises_exception_for_unknown_file(self):
     storage = MockStorage()
     with raises(FileNotFoundError):
         storage.delete('key')
Пример #22
0
 def test_save_supports_overwrite(self):
     storage = MockStorage()
     storage.save('key', 'value')
     storage.save('key', 'value 2', overwrite=True)
     assert len(MockStorage._files) == 1
Пример #23
0
 def test_new_file(self):
     storage = MockStorage()
     assert isinstance(storage.new_file(), MockStorageFile)
Пример #24
0
 def test_returns_file_url(self):
     storage = MockStorage('/uploads')
     storage.save('key', '')
     assert storage.url('key') == '/uploads/key'
Пример #25
0
 def test_new_file_supports_prefixes(self):
     storage = MockStorage()
     assert storage.new_file(prefix='pics').prefix == 'pics'
Пример #26
0
 def test_open_returns_file_object(self):
     storage = MockStorage()
     storage.save('key', '')
     file_ = storage.open('key')
     assert isinstance(file_, MockStorageFile)
Пример #27
0
 def setup_method(self, method):
     TestCase.setup_method(self, method)
     MockStorage._files = {}
     self.storage = MockStorage('/uploads')
Пример #28
0
 def test_delete_raises_exception_for_unknown_file(self):
     storage = MockStorage()
     with raises(FileNotFoundError):
         storage.delete('key')
Пример #29
0
 def test_size_returns_the_associated_file_size(self):
     storage = MockStorage('uploads')
     storage.save('key', '123123')
     file_ = storage.open('key')
     assert file_.size == 6
Пример #30
0
 def test_new_file_supports_prefixes(self):
     storage = MockStorage()
     assert storage.new_file(prefix='pics').prefix == 'pics'
Пример #31
0
 def test_read_returns_file_contents(self):
     storage = MockStorage('uploads')
     storage.save('key', '123123')
     file_ = storage.open('key')
     assert file_.read() == '123123'
Пример #32
0
 def test_read_returns_file_contents(self):
     storage = MockStorage('uploads')
     storage.save('key', '123123')
     file_ = storage.open('key')
     assert file_.read() == '123123'
Пример #33
0
 def test_supports_name_attribute(self):
     storage = MockStorage('uploads')
     file_ = MockStorageFile(storage)
     file_.name = 'some_key'
     assert file_.name == 'some_key'