From 73de61afaff2c2466e8952546314695396de4e00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ha=CC=8Avard=20Gulldahl?= Date: Sun, 4 Sep 2016 22:05:25 +0200 Subject: [PATCH] Make py3 happy when uploading bytes #55 --- tests/test_JFS.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/tests/test_JFS.py b/tests/test_JFS.py index 5d58e99..71a7728 100644 --- a/tests/test_JFS.py +++ b/tests/test_JFS.py @@ -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 @@ -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 @@ -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) @@ -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)