Skip to content

Commit

Permalink
Make py3 happy when uploading bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
havardgulldahl committed Sep 4, 2016
1 parent adee17e commit 73de61a
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions tests/test_JFS.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def test_getObject(self):
assert isinstance(jfs.getObject('/Jotta/Archive/test'), JFS.JFSFolder)
#TODO: test with a python-requests object

def test_urlencoded_filename(self):
def test_urlencoded_filename(self, tmpdir):
# make sure filenames that contain percent-encoded characters are
# correctly parsed and the percent encoding is preserved
tests = ['%2FVolumes%2FMedia%2Ftest.txt', # existing percent encoding, see #25
Expand All @@ -204,12 +204,9 @@ def test_urlencoded_filename(self):

for f in tests:
p = posixpath.join('/Jotta/Archive', f)
if six.PY2:
_f = tempfile.NamedTemporaryFile(mode='w+', prefix=f)
elif six.PY3:
_f = tempfile.NamedTemporaryFile(mode='w+', encoding='utf-8', prefix=f)
_f.write('123test')
jfs_f = jfs.up(p, _f)
_f = tmpdir.join(f).ensure()
_f.write(f)
jfs_f = jfs.up(p, six.BytesIO(_f.read_binary()))
clean_room_path = '%s%s%s%s' % (JFS.JFS_ROOT, jfs.username, '/Jotta/Archive/', f)
assert jfs.session.get(clean_room_path).status_code == 200 # check that strange file name is preserved
assert jfs_f.path == clean_room_path
Expand Down Expand Up @@ -357,7 +354,7 @@ def test_xml(self):
newf.delete()

_f = tempfile.NamedTemporaryFile()
_f.write(u'123test')
_f.write(b'123test')

newfile = dev.up(_f)
assert isinstance(newfile, JFS.JFSFile)
Expand Down Expand Up @@ -711,7 +708,7 @@ def test_delete_and_restore():


_f = tempfile.NamedTemporaryFile()
_f.write('123test')
_f.write(b'123test')

newfile = dev.up(_f)
assert isinstance(newfile, JFS.JFSFile)
Expand Down

0 comments on commit 73de61a

Please sign in to comment.