aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Allan Webber <cwebber@dustycloud.org>2011-04-10 16:51:25 -0500
committerChristopher Allan Webber <cwebber@dustycloud.org>2011-04-10 16:51:25 -0500
commit20e3ee115d5db738b071e99172d2ea97c6c0443e (patch)
tree27a914f23b327245ffd3808ec4502bba2bf8361a
parent2fdec8270d786624cfe570f949eb8f0f89054eb6 (diff)
downloadmediagoblin-20e3ee115d5db738b071e99172d2ea97c6c0443e.tar.lz
mediagoblin-20e3ee115d5db738b071e99172d2ea97c6c0443e.tar.xz
mediagoblin-20e3ee115d5db738b071e99172d2ea97c6c0443e.zip
Test BasicFileStorage.get_unique_filepath()
-rw-r--r--mediagoblin/tests/test_storage.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/mediagoblin/tests/test_storage.py b/mediagoblin/tests/test_storage.py
index ff49ec9b..79f1c8ea 100644
--- a/mediagoblin/tests/test_storage.py
+++ b/mediagoblin/tests/test_storage.py
@@ -19,6 +19,7 @@ import os
import tempfile
from nose.tools import assert_raises
+from werkzeug.utils import secure_filename
from mediagoblin import storage
@@ -82,8 +83,24 @@ def test_basic_storage_file_exists():
assert not this_storage.file_exists(['dnedir1', 'dnedir2', 'somefile.lol'])
-def test_basic_storage_get_unique_filename():
- pass
+def test_basic_storage_get_unique_filepath():
+ tmpdir, this_storage = get_tmp_filestorage()
+
+ # write something that exists
+ os.makedirs(os.path.join(tmpdir, 'dir1', 'dir2'))
+ filename = os.path.join(tmpdir, 'dir1', 'dir2', 'filename.txt')
+ with open(filename, 'w') as ourfile:
+ ourfile.write("I'm having a lovely day!")
+
+ # now we want something new, with the same name!
+ new_filepath = this_storage.get_unique_filepath(
+ ['dir1', 'dir2', 'filename.txt'])
+ assert new_filepath[:-1] == [u'dir1', u'dir2']
+
+ new_filename = new_filepath[-1]
+ assert new_filename.endswith('filename.txt')
+ assert len(new_filename) > len('filename.txt')
+ assert new_filename == secure_filename(new_filename)
def test_basic_storage_get_file():