def test_returns_file_url(self): storage = MockStorage('/uploads') storage.save('key', '') assert storage.url('key') == '/uploads/key'
def test_save_supports_overwrite(self): storage = MockStorage() storage.save('key', 'value') storage.save('key', 'value 2', overwrite=True) assert len(MockStorage._files) == 1
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'
def test_saves_key_value_pair_in_dict(self): storage = MockStorage() storage.save('key', '') assert storage.exists('key')
def test_save_returns_file_object_on_success(self): storage = MockStorage() obj = storage.save('key', 'value') assert obj.name == 'key'
def test_size_returns_the_associated_file_size(self): storage = MockStorage('uploads') storage.save('key', '123123') file_ = storage.open('key') assert file_.size == 6
def test_read_returns_file_contents(self): storage = MockStorage('uploads') storage.save('key', '123123') file_ = storage.open('key') assert file_.read() == '123123'
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'
def test_open_returns_file_object(self): storage = MockStorage() storage.save('key', '') file_ = storage.open('key') assert isinstance(file_, MockStorageFile)
def test_returns_file_url(self): storage = MockStorage('/uploads') file_ = storage.save('key', '123123') assert file_.url == '/uploads/key'