aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/tests/test_storage.py
diff options
context:
space:
mode:
authorElrond <elrond+mediagoblin.org@samba-tng.org>2013-04-21 19:19:40 +0200
committerElrond <elrond+mediagoblin.org@samba-tng.org>2013-04-21 19:26:57 +0200
commitfd1202b7745a536428cdfe1d862a07bf59a3ad43 (patch)
treebd8c5ec12211402a3a1ad81b3d5f44edb7e483d4 /mediagoblin/tests/test_storage.py
parent449863863a747279b038f9b195ac60c547b73fe2 (diff)
downloadmediagoblin-fd1202b7745a536428cdfe1d862a07bf59a3ad43.tar.lz
mediagoblin-fd1202b7745a536428cdfe1d862a07bf59a3ad43.tar.xz
mediagoblin-fd1202b7745a536428cdfe1d862a07bf59a3ad43.zip
Cleanup storage after test, and test .delete_dir().
The storage tests work in the system's tmpdir. The python docs say, we should clean up after using things. Yes the directory should be cleaned up on reboot, but if running tests a lot, the tmpdir could fill up, so we should really cleanup. So use the new .delete_dir() on the storage interface to cleanup test dirs and get them finally removed with os.rmdir. All nicely packed into cleanup_storage().
Diffstat (limited to 'mediagoblin/tests/test_storage.py')
-rw-r--r--mediagoblin/tests/test_storage.py29
1 files changed, 23 insertions, 6 deletions
diff --git a/mediagoblin/tests/test_storage.py b/mediagoblin/tests/test_storage.py
index 749f7b07..f6f1d18f 100644
--- a/mediagoblin/tests/test_storage.py
+++ b/mediagoblin/tests/test_storage.py
@@ -95,6 +95,14 @@ def get_tmp_filestorage(mount_url=None, fake_remote=False):
return tmpdir, this_storage
+def cleanup_storage(this_storage, tmpdir, *paths):
+ for p in paths:
+ while p:
+ assert this_storage.delete_dir(p) == True
+ p.pop(-1)
+ os.rmdir(tmpdir)
+
+
def test_basic_storage__resolve_filepath():
tmpdir, this_storage = get_tmp_filestorage()
@@ -111,7 +119,7 @@ def test_basic_storage__resolve_filepath():
this_storage._resolve_filepath,
['../../', 'etc', 'passwd'])
- os.rmdir(tmpdir)
+ cleanup_storage(this_storage, tmpdir)
def test_basic_storage_file_exists():
@@ -127,6 +135,7 @@ def test_basic_storage_file_exists():
assert not this_storage.file_exists(['dnedir1', 'dnedir2', 'somefile.lol'])
this_storage.delete_file(['dir1', 'dir2', 'filename.txt'])
+ cleanup_storage(this_storage, tmpdir, ['dir1', 'dir2'])
def test_basic_storage_get_unique_filepath():
@@ -149,6 +158,7 @@ def test_basic_storage_get_unique_filepath():
assert new_filename == secure_filename(new_filename)
os.remove(filename)
+ cleanup_storage(this_storage, tmpdir, ['dir1', 'dir2'])
def test_basic_storage_get_file():
@@ -189,6 +199,7 @@ def test_basic_storage_get_file():
this_storage.delete_file(filepath)
this_storage.delete_file(new_filepath)
this_storage.delete_file(['testydir', 'testyfile.txt'])
+ cleanup_storage(this_storage, tmpdir, ['dir1', 'dir2'], ['testydir'])
def test_basic_storage_delete_file():
@@ -204,11 +215,15 @@ def test_basic_storage_delete_file():
assert os.path.exists(
os.path.join(tmpdir, 'dir1/dir2/ourfile.txt'))
+ assert this_storage.delete_dir(['dir1', 'dir2']) == False
this_storage.delete_file(filepath)
+ assert this_storage.delete_dir(['dir1', 'dir2']) == True
assert not os.path.exists(
os.path.join(tmpdir, 'dir1/dir2/ourfile.txt'))
+ cleanup_storage(this_storage, tmpdir, ['dir1'])
+
def test_basic_storage_url_for_file():
# Not supplying a base_url should actually just bork.
@@ -217,7 +232,7 @@ def test_basic_storage_url_for_file():
storage.NoWebServing,
this_storage.file_url,
['dir1', 'dir2', 'filename.txt'])
- os.rmdir(tmpdir)
+ cleanup_storage(this_storage, tmpdir)
# base_url without domain
tmpdir, this_storage = get_tmp_filestorage('/media/')
@@ -225,7 +240,7 @@ def test_basic_storage_url_for_file():
['dir1', 'dir2', 'filename.txt'])
expected = '/media/dir1/dir2/filename.txt'
assert result == expected
- os.rmdir(tmpdir)
+ cleanup_storage(this_storage, tmpdir)
# base_url with domain
tmpdir, this_storage = get_tmp_filestorage(
@@ -234,7 +249,7 @@ def test_basic_storage_url_for_file():
['dir1', 'dir2', 'filename.txt'])
expected = 'http://media.example.org/ourmedia/dir1/dir2/filename.txt'
assert result == expected
- os.rmdir(tmpdir)
+ cleanup_storage(this_storage, tmpdir)
def test_basic_storage_get_local_path():
@@ -248,13 +263,13 @@ def test_basic_storage_get_local_path():
assert result == expected
- os.rmdir(tmpdir)
+ cleanup_storage(this_storage, tmpdir)
def test_basic_storage_is_local():
tmpdir, this_storage = get_tmp_filestorage()
assert this_storage.local_storage is True
- os.rmdir(tmpdir)
+ cleanup_storage(this_storage, tmpdir)
def test_basic_storage_copy_locally():
@@ -275,6 +290,7 @@ def test_basic_storage_copy_locally():
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):
@@ -292,6 +308,7 @@ def _test_copy_local_to_storage_works(tmpdir, this_storage):
'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():