+ # Not supplying a base_url should actually just bork.
+ tmpdir, this_storage = get_tmp_filestorage()
+ pytest.raises(
+ storage.NoWebServing,
+ this_storage.file_url,
+ ['dir1', 'dir2', 'filename.txt'])
+ cleanup_storage(this_storage, tmpdir)
+
+ # base_url without domain
+ tmpdir, this_storage = get_tmp_filestorage('/media/')
+ result = this_storage.file_url(
+ ['dir1', 'dir2', 'filename.txt'])
+ expected = '/media/dir1/dir2/filename.txt'
+ assert result == expected
+ cleanup_storage(this_storage, tmpdir)
+
+ # base_url with domain
+ tmpdir, this_storage = get_tmp_filestorage(
+ 'http://media.example.org/ourmedia/')
+ result = this_storage.file_url(
+ ['dir1', 'dir2', 'filename.txt'])
+ expected = 'http://media.example.org/ourmedia/dir1/dir2/filename.txt'
+ assert result == expected
+ cleanup_storage(this_storage, tmpdir)
+
+
+def test_basic_storage_get_local_path():
+ tmpdir, this_storage = get_tmp_filestorage()
+
+ result = this_storage.get_local_path(
+ ['dir1', 'dir2', 'filename.txt'])
+
+ expected = os.path.join(
+ tmpdir, 'dir1/dir2/filename.txt')
+
+ assert result == expected
+
+ cleanup_storage(this_storage, tmpdir)
+
+
+def test_basic_storage_is_local():
+ tmpdir, this_storage = get_tmp_filestorage()
+ assert this_storage.local_storage is True
+ cleanup_storage(this_storage, tmpdir)
+
+
+def test_basic_storage_copy_locally():
+ tmpdir, this_storage = get_tmp_filestorage()
+
+ dest_tmpdir = tempfile.mkdtemp()
+
+ filepath = ['dir1', 'dir2', 'ourfile.txt']
+ with this_storage.get_file(filepath, 'w') as our_file:
+ our_file.write('Testing this file')
+
+ new_file_dest = os.path.join(dest_tmpdir, 'file2.txt')
+
+ this_storage.copy_locally(filepath, new_file_dest)
+ this_storage.delete_file(filepath)
+
+ assert file(new_file_dest).read() == 'Testing this file'
+
+ os.remove(new_file_dest)
+ os.rmdir(dest_tmpdir)
+ cleanup_storage(this_storage, tmpdir, ['dir1', 'dir2'])
+
+
+def _test_copy_local_to_storage_works(tmpdir, this_storage):
+ local_filename = tempfile.mktemp()
+ with file(local_filename, 'w') as tmpfile:
+ tmpfile.write('haha')
+
+ this_storage.copy_local_to_storage(
+ local_filename, ['dir1', 'dir2', 'copiedto.txt'])
+
+ os.remove(local_filename)
+
+ assert file(
+ os.path.join(tmpdir, 'dir1/dir2/copiedto.txt'),
+ 'r').read() == 'haha'
+
+ this_storage.delete_file(['dir1', 'dir2', 'copiedto.txt'])
+ cleanup_storage(this_storage, tmpdir, ['dir1', 'dir2'])
+
+
+def test_basic_storage_copy_local_to_storage():
+ tmpdir, this_storage = get_tmp_filestorage()
+ _test_copy_local_to_storage_works(tmpdir, this_storage)
+
+
+def test_general_storage_copy_local_to_storage():
+ tmpdir, this_storage = get_tmp_filestorage(fake_remote=True)
+ _test_copy_local_to_storage_works(tmpdir, this_storage)