diff options
Diffstat (limited to 'mediagoblin/tests/test_storage.py')
-rw-r--r-- | mediagoblin/tests/test_storage.py | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/mediagoblin/tests/test_storage.py b/mediagoblin/tests/test_storage.py index f6f1d18f..a4c3e4eb 100644 --- a/mediagoblin/tests/test_storage.py +++ b/mediagoblin/tests/test_storage.py @@ -19,6 +19,8 @@ import os import tempfile import pytest +import six + from werkzeug.utils import secure_filename from mediagoblin import storage @@ -45,7 +47,7 @@ def test_clean_listy_filepath(): storage.clean_listy_filepath(['../../', 'linooks.jpg']) -class FakeStorageSystem(): +class FakeStorageSystem(object): def __init__(self, foobie, blech, **kwargs): self.foobie = foobie self.blech = blech @@ -78,8 +80,8 @@ def test_storage_system_from_config(): 'mediagoblin.tests.test_storage:FakeStorageSystem'}) assert this_storage.foobie == 'eiboof' assert this_storage.blech == 'hcelb' - assert unicode(this_storage.__class__) == \ - u'mediagoblin.tests.test_storage.FakeStorageSystem' + assert six.text_type(this_storage.__class__) == \ + u"<class 'mediagoblin.tests.test_storage.FakeStorageSystem'>" ########################## @@ -168,11 +170,11 @@ def test_basic_storage_get_file(): filepath = ['dir1', 'dir2', 'ourfile.txt'] with this_storage.get_file(filepath, 'w') as our_file: - our_file.write('First file') + our_file.write(b'First file') with this_storage.get_file(filepath, 'r') as our_file: - assert our_file.read() == 'First file' + assert our_file.read() == b'First file' assert os.path.exists(os.path.join(tmpdir, 'dir1/dir2/ourfile.txt')) - with file(os.path.join(tmpdir, 'dir1/dir2/ourfile.txt'), 'r') as our_file: + with open(os.path.join(tmpdir, 'dir1/dir2/ourfile.txt'), 'r') as our_file: assert our_file.read() == 'First file' # Write to the same path but try to get a unique file. @@ -180,21 +182,21 @@ def test_basic_storage_get_file(): assert not os.path.exists(os.path.join(tmpdir, *new_filepath)) with this_storage.get_file(new_filepath, 'w') as our_file: - our_file.write('Second file') + our_file.write(b'Second file') with this_storage.get_file(new_filepath, 'r') as our_file: - assert our_file.read() == 'Second file' + assert our_file.read() == b'Second file' assert os.path.exists(os.path.join(tmpdir, *new_filepath)) - with file(os.path.join(tmpdir, *new_filepath), 'r') as our_file: + with open(os.path.join(tmpdir, *new_filepath), 'r') as our_file: assert our_file.read() == 'Second file' # Read from an existing file manually_written_file = os.makedirs( os.path.join(tmpdir, 'testydir')) - with file(os.path.join(tmpdir, 'testydir/testyfile.txt'), 'w') as testyfile: + with open(os.path.join(tmpdir, 'testydir/testyfile.txt'), 'w') as testyfile: testyfile.write('testy file! so testy.') with this_storage.get_file(['testydir', 'testyfile.txt']) as testyfile: - assert testyfile.read() == 'testy file! so testy.' + assert testyfile.read() == b'testy file! so testy.' this_storage.delete_file(filepath) this_storage.delete_file(new_filepath) @@ -210,7 +212,7 @@ def test_basic_storage_delete_file(): filepath = ['dir1', 'dir2', 'ourfile.txt'] with this_storage.get_file(filepath, 'w') as our_file: - our_file.write('Testing this file') + our_file.write(b'Testing this file') assert os.path.exists( os.path.join(tmpdir, 'dir1/dir2/ourfile.txt')) @@ -279,14 +281,14 @@ def test_basic_storage_copy_locally(): filepath = ['dir1', 'dir2', 'ourfile.txt'] with this_storage.get_file(filepath, 'w') as our_file: - our_file.write('Testing this file') + our_file.write(b'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' + assert open(new_file_dest).read() == 'Testing this file' os.remove(new_file_dest) os.rmdir(dest_tmpdir) @@ -295,7 +297,7 @@ def test_basic_storage_copy_locally(): def _test_copy_local_to_storage_works(tmpdir, this_storage): local_filename = tempfile.mktemp() - with file(local_filename, 'w') as tmpfile: + with open(local_filename, 'w') as tmpfile: tmpfile.write('haha') this_storage.copy_local_to_storage( @@ -303,7 +305,7 @@ def _test_copy_local_to_storage_works(tmpdir, this_storage): os.remove(local_filename) - assert file( + assert open( os.path.join(tmpdir, 'dir1/dir2/copiedto.txt'), 'r').read() == 'haha' |